@@ -44,44 +44,46 @@ def test_event_codes(self):
44
44
all_codes .add (code )
45
45
46
46
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
+ """
62
53
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
+ ]
63
69
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.
68
70
def test_all_serializable (self ):
69
71
all_non_abstract_events = set (
70
72
get_all_subclasses (BaseEvent ),
71
73
)
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 ))
73
75
diff = all_non_abstract_events .difference (set (all_event_values_list ))
74
76
assert (
75
77
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"
77
79
78
80
# 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 :
80
82
assert not isinstance (event , type )
81
83
82
84
# if we have everything we need to test, try to serialize everything
83
85
count = 0
84
- for event in sample_values :
86
+ for event in self . SAMPLE_VALUES :
85
87
msg = msg_from_base_event (event )
86
88
print (f"--- msg: { msg .info .name } " )
87
89
# Serialize to dictionary
0 commit comments