mirror of
https://github.com/zulip/zulip.git
synced 2025-11-11 17:36:27 +00:00
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:
@@ -277,6 +277,16 @@ python_rules = RuleList(
|
|||||||
"good_lines": ["assert_length(data, 2)"],
|
"good_lines": ["assert_length(data, 2)"],
|
||||||
"bad_lines": ["assertEqual(len(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)",
|
"pattern": r"#\s*type:\s*ignore(?!\[[^][]+\] +# +\S)",
|
||||||
"exclude": {"tools/tests", "zerver/lib/test_runner.py", "zerver/tests"},
|
"exclude": {"tools/tests", "zerver/lib/test_runner.py", "zerver/tests"},
|
||||||
|
|||||||
Reference in New Issue
Block a user