Skip to content

Commit ec10b29

Browse files
committed
pr feedback
1 parent 59ac8d8 commit ec10b29

File tree

1 file changed

+25
-23
lines changed

1 file changed

+25
-23
lines changed

tests/unit/test_events.py

+25-23
Original file line numberDiff line numberDiff line change
@@ -44,44 +44,46 @@ def test_event_codes(self):
4444
all_codes.add(code)
4545

4646

47-
sample_values = [
48-
# N.B. Events instantiated here include the module prefix in order to
49-
# avoid having the entire list twice in the code.
50-
# M - Deps generation ======================
51-
types.RetryExternalCall(attempt=0, max=0),
52-
types.RecordRetryException(exc=""),
53-
# Z - misc ======================
54-
types.SystemCouldNotWrite(path="", reason="", exc=""),
55-
types.SystemExecutingCmd(cmd=[""]),
56-
types.SystemStdOut(bmsg=str(b"")),
57-
types.SystemStdErr(bmsg=str(b"")),
58-
types.SystemReportReturnCode(returncode=0),
59-
types.Formatting(),
60-
types.Note(msg="This is a note."),
61-
]
47+
class TestEventJSONSerialization:
48+
"""Attempts to test that every event is serializable to json.
49+
50+
event types that take `Any` are not possible to test in this way since some will serialize
51+
just fine and others won't.
52+
"""
6253

54+
SAMPLE_VALUES = [
55+
# N.B. Events instantiated here include the module prefix in order to
56+
# avoid having the entire list twice in the code.
57+
# M - Deps generation ======================
58+
types.RetryExternalCall(attempt=0, max=0),
59+
types.RecordRetryException(exc=""),
60+
# Z - misc ======================
61+
types.SystemCouldNotWrite(path="", reason="", exc=""),
62+
types.SystemExecutingCmd(cmd=[""]),
63+
types.SystemStdOut(bmsg=str(b"")),
64+
types.SystemStdErr(bmsg=str(b"")),
65+
types.SystemReportReturnCode(returncode=0),
66+
types.Formatting(),
67+
types.Note(msg="This is a note."),
68+
]
6369

64-
class TestEventJSONSerialization:
65-
# attempts to test that every event is serializable to json.
66-
# event types that take `Any` are not possible to test in this way since some will serialize
67-
# just fine and others won't.
6870
def test_all_serializable(self):
6971
all_non_abstract_events = set(
7072
get_all_subclasses(BaseEvent),
7173
)
72-
all_event_values_list = list(map(lambda x: x.__class__, sample_values))
74+
all_event_values_list = list(map(lambda x: x.__class__, self.SAMPLE_VALUES))
7375
diff = all_non_abstract_events.difference(set(all_event_values_list))
7476
assert (
7577
not diff
76-
), f"{diff}test is missing concrete values in `sample_values`. Please add the values for the aforementioned event classes"
78+
), f"{diff}test is missing concrete values in `SAMPLE_VALUES`. Please add the values for the aforementioned event classes"
7779

7880
# make sure everything in the list is a value not a type
79-
for event in sample_values:
81+
for event in self.SAMPLE_VALUES:
8082
assert not isinstance(event, type)
8183

8284
# if we have everything we need to test, try to serialize everything
8385
count = 0
84-
for event in sample_values:
86+
for event in self.SAMPLE_VALUES:
8587
msg = msg_from_base_event(event)
8688
print(f"--- msg: {msg.info.name}")
8789
# Serialize to dictionary

0 commit comments

Comments
 (0)