Commit 215f74e706

215f74e70653a33420a681812d0b1405d2551407

parent: 756d010b09

Verified · cmc

cmc <hello@cleberg.net> · 2026-08-23 02:20 UTC

Lift the test fixture out of the class

RUF012: a list as a class attribute is a mutable default. I had linted only
main.py locally; the action lints the repo.

Layout: unified · split

tests/test_main.py +11 −10
@@ -24,21 +24,22 @@ class TestBuildMessage(unittest.TestCase):
24 self.assertIn("one\ntwo", msg.get_payload()) 24 self.assertIn("one\ntwo", msg.get_payload())
25 25
26 26
27PAYLOAD = [
28 {
29 "title": "Sonnet",
30 "author": "Anon",
31 "linecount": "2",
32 "lines": ["first line", "second line"],
33 }
34]
35
36
27class TestFetchPoem(unittest.TestCase): 37class TestFetchPoem(unittest.TestCase):
28 """PoetryDB is stubbed: the test covers the shape this code expects from it, 38 """PoetryDB is stubbed: the test covers the shape this code expects from it,
29 not the service being up.""" 39 not the service being up."""
30 40
31 PAYLOAD = [
32 {
33 "title": "Sonnet",
34 "author": "Anon",
35 "linecount": "2",
36 "lines": ["first line", "second line"],
37 }
38 ]
39
40 def test_fields_are_extracted_and_lines_joined(self): 41 def test_fields_are_extracted_and_lines_joined(self):
41 with patch("main.requests.get", return_value=FakeResponse(self.PAYLOAD)): 42 with patch("main.requests.get", return_value=FakeResponse(PAYLOAD)):
42 title, author, line_count, lines = fetch_poem() 43 title, author, line_count, lines = fetch_poem()
43 44
44 self.assertEqual(title, "Sonnet") 45 self.assertEqual(title, "Sonnet")