diff --git a/evap/evaluation/management/commands/precommit.py b/evap/evaluation/management/commands/precommit.py index e147efa7185477aef1734bb10d3a5b2997e631a7..455b254c8eb13d2c44ba4821ed6bc462fbaf7d75 100644 --- a/evap/evaluation/management/commands/precommit.py +++ b/evap/evaluation/management/commands/precommit.py @@ -16,6 +16,8 @@ class Command(BaseCommand): print("Please call me from the evap root directory (where manage.py resides)") sys.exit(1) + call_command("typecheck") + # subprocess call so our sys.argv check in settings.py works subprocess.run(["./manage.py", "test"], check=False) # nosec diff --git a/evap/evaluation/management/commands/typecheck.py b/evap/evaluation/management/commands/typecheck.py new file mode 100644 index 0000000000000000000000000000000000000000..080ad6b456b396d31149cb1288b045a813120a9b --- /dev/null +++ b/evap/evaluation/management/commands/typecheck.py @@ -0,0 +1,12 @@ +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 diff --git a/evap/evaluation/tests/test_commands.py b/evap/evaluation/tests/test_commands.py index 128341a34e5b8c3c946c9c27a14b393a96b8e2ff..904880fdae754d446044f88450b636b3ff6f7172 100644 --- a/evap/evaluation/tests/test_commands.py +++ b/evap/evaluation/tests/test_commands.py @@ -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): @patch("subprocess.run") @patch("evap.evaluation.management.commands.precommit.call_command") @@ -391,6 +399,7 @@ class TestPrecommitCommand(TestCase): 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("format")