custom_check: Detect incorrect use of assertTrue.

This commit adds a check to avoid the use of assertTrue
for cases like: assertTrue(len(data) == 2).
We should use assert_length, assertGreater, or
assertGreaterEqual, whatever suits, in cases like these.
This commit is contained in:
akshatdalton
2021-07-13 17:49:03 +00:00
committed by Tim Abbott
parent 3ea1ff7665
commit 2e4a333133

View File

@@ -277,6 +277,16 @@ python_rules = RuleList(
"good_lines": ["assert_length(data, 2)"],
"bad_lines": ["assertEqual(len(data), 2)"],
},
{
"pattern": "assertTrue[(]len[(][^ ]*[)]",
"description": "Use assert_length or assertGreater helper instead of assertTrue(len(..) ..).",
"good_lines": ["assert_length(data, 2)", "assertGreater(len(data), 2)"],
"bad_lines": [
"assertTrue(len(data) == 2)",
"assertTrue(len(data) >= 2)",
"assertTrue(len(data) > 2)",
],
},
{
"pattern": r"#\s*type:\s*ignore(?!\[[^][]+\] +# +\S)",
"exclude": {"tools/tests", "zerver/lib/test_runner.py", "zerver/tests"},