Skip to content
Snippets Groups Projects
Unverified Commit bfad786d authored by Niklas Mohrin's avatar Niklas Mohrin
Browse files

Add `manage.py typecheck` and run it in `manage.py precommit`

parent c1925f60
Branches
No related tags found
No related merge requests found
...@@ -16,6 +16,8 @@ class Command(BaseCommand): ...@@ -16,6 +16,8 @@ class Command(BaseCommand):
print("Please call me from the evap root directory (where manage.py resides)") print("Please call me from the evap root directory (where manage.py resides)")
sys.exit(1) sys.exit(1)
call_command("typecheck")
# subprocess call so our sys.argv check in settings.py works # subprocess call so our sys.argv check in settings.py works
subprocess.run(["./manage.py", "test"], check=False) # nosec subprocess.run(["./manage.py", "test"], check=False) # nosec
......
import subprocess # nosec
from django.core.management.base import BaseCommand
class Command(BaseCommand):
args = ""
help = "Runs the type checker (mypy)"
requires_migrations_checks = False
def handle(self, *args, **options):
subprocess.run(["mypy", "-p", "evap"], check=True) # nosec
...@@ -383,6 +383,14 @@ class TestFormatCommand(TestCase): ...@@ -383,6 +383,14 @@ class TestFormatCommand(TestCase):
) )
class TestTypecheckCommand(TestCase):
@patch("subprocess.run")
def test_mypy_called(self, mock_subprocess_run):
management.call_command("typecheck")
self.assertEqual(len(mock_subprocess_run.mock_calls), 1)
mock_subprocess_run.assert_has_calls([call(["mypy", "-p", "evap"], check=True)])
class TestPrecommitCommand(TestCase): class TestPrecommitCommand(TestCase):
@patch("subprocess.run") @patch("subprocess.run")
@patch("evap.evaluation.management.commands.precommit.call_command") @patch("evap.evaluation.management.commands.precommit.call_command")
...@@ -391,6 +399,7 @@ class TestPrecommitCommand(TestCase): ...@@ -391,6 +399,7 @@ class TestPrecommitCommand(TestCase):
mock_subprocess_run.assert_called_with(["./manage.py", "test"], check=False) mock_subprocess_run.assert_called_with(["./manage.py", "test"], check=False)
self.assertEqual(mock_call_command.call_count, 2) self.assertEqual(mock_call_command.call_count, 3)
mock_call_command.assert_any_call("typecheck")
mock_call_command.assert_any_call("lint") mock_call_command.assert_any_call("lint")
mock_call_command.assert_any_call("format") mock_call_command.assert_any_call("format")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment