@@ -94,6 +94,27 @@ class SanityTests(unittest.TestCase):
94
94
seen .add (each )
95
95
self .assertFalse (duplicated , "Elements are not unique." )
96
96
97
+ def assertFollowsDescriptionStyle (self , description ):
98
+ """
99
+ Instead of saying "test that X frobs" or "X should frob" use "X frobs".
100
+
101
+ See e.g. https://jml.io/pages/test-docstrings.html
102
+
103
+ This test isn't comprehensive (it doesn't catch all the extra
104
+ verbiage there), but it's just to catch whatever it manages to
105
+ cover.
106
+ """
107
+
108
+ message = (
109
+ "In descriptions, don't say 'Test that X frobs' or 'X should "
110
+ "frob' or 'X should be valid'. Just say 'X frobs' or 'X is "
111
+ "valid'. It's shorter, and the test suite is entirely about "
112
+ "what *should* be already. "
113
+ "See https://jml.io/pages/test-docstrings.html for help."
114
+ )
115
+ self .assertNotRegex (description , r"\bshould\b" , message )
116
+ self .assertNotRegex (description , r"(?i)\btest(s)? that\b" , message )
117
+
97
118
def test_all_test_files_are_valid_json (self ):
98
119
"""
99
120
All test files contain valid JSON.
@@ -160,36 +181,15 @@ class SanityTests(unittest.TestCase):
160
181
)
161
182
print (f"Found { count } test cases." )
162
183
163
- def test_descriptions_do_not_use_modal_verbs (self ):
164
- """
165
- Instead of saying "test that X frobs" or "X should frob" use "X frobs".
166
-
167
- See e.g. https://jml.io/pages/test-docstrings.html
168
-
169
- This test isn't comprehensive (it doesn't catch all the extra
170
- verbiage there), but it's just to catch whatever it manages to
171
- cover.
172
- """
184
+ def test_case_descriptions_do_not_use_modal_verbs (self ):
185
+ for case in cases (self .test_files ):
186
+ with self .subTest (description = case ["description" ]):
187
+ self .assertFollowsDescriptionStyle (case ["description" ])
173
188
174
- message = (
175
- "In descriptions, don't say 'Test that X frobs' or 'X should "
176
- "frob' or 'X should be valid'. Just say 'X frobs' or 'X is "
177
- "valid'. It's shorter, and the test suite is entirely about "
178
- "what *should* be already. "
179
- "See https://jml.io/pages/test-docstrings.html for help."
180
- )
189
+ def test_test_descriptions_do_not_use_modal_verbs (self ):
181
190
for test in tests (self .test_files ):
182
191
with self .subTest (description = test ["description" ]):
183
- self .assertNotRegex (
184
- test ["description" ],
185
- r"\bshould\b" ,
186
- message ,
187
- )
188
- self .assertNotRegex (
189
- test ["description" ],
190
- r"(?i)\btest(s)? that\b" ,
191
- message ,
192
- )
192
+ self .assertFollowsDescriptionStyle (test ["description" ])
193
193
194
194
@unittest .skipIf (jsonschema is None , "Validation library not present!" )
195
195
def test_all_schemas_are_valid (self ):
0 commit comments