|
@@ -1,13 +1,14 @@
|
|
|
+from __future__ import annotations
|
|
|
+
|
|
|
import ast
|
|
|
|
|
|
from tools.flake8_plugin import SentryCheck
|
|
|
|
|
|
|
|
|
-def _run(src):
|
|
|
+def _run(src: str, filename: str = "getsentry/t.py") -> list[str]:
|
|
|
tree = ast.parse(src)
|
|
|
return sorted(
|
|
|
- "t.py:{}:{}: {}".format(*error)
|
|
|
- for error in SentryCheck(tree=tree, filename="getsentry/foo.py").run()
|
|
|
+ "t.py:{}:{}: {}".format(*error) for error in SentryCheck(tree=tree, filename=filename).run()
|
|
|
)
|
|
|
|
|
|
|
|
@@ -89,3 +90,17 @@ from sentry.models import User
|
|
|
assert errors == [
|
|
|
"t.py:1:0: S005 Do not import models from sentry.models but the actual module",
|
|
|
]
|
|
|
+
|
|
|
+
|
|
|
+def test_S006():
|
|
|
+ src = """\
|
|
|
+from django.utils.encoding import force_bytes
|
|
|
+from django.utils.encoding import force_str
|
|
|
+"""
|
|
|
+ # only error in tests until we can fix the rest
|
|
|
+ assert _run(src, filename="src/sentry/whatever.py") == []
|
|
|
+ errors = _run(src, filename="tests/test_foo.py")
|
|
|
+ assert errors == [
|
|
|
+ "t.py:1:0: S006 Do not use force_bytes / force_str -- test the types directly",
|
|
|
+ "t.py:2:0: S006 Do not use force_bytes / force_str -- test the types directly",
|
|
|
+ ]
|