test_mypy.py 895 B

12345678910111213141516171819202122232425262728293031
  1. import pathlib
  2. import sys
  3. import unittest
  4. import mypy.api
  5. test_modules = ["rsa", "tests"]
  6. class MypyRunnerTest(unittest.TestCase):
  7. def test_run_mypy(self):
  8. proj_root = pathlib.Path(__file__).parent.parent
  9. args = [
  10. "--incremental",
  11. "--ignore-missing-imports",
  12. f"--python-version={sys.version_info.major}.{sys.version_info.minor}",
  13. ] + [str(proj_root / dirname) for dirname in test_modules]
  14. result = mypy.api.run(args)
  15. stdout, stderr, status = result
  16. messages = []
  17. if stderr:
  18. messages.append(stderr)
  19. if stdout:
  20. messages.append(stdout)
  21. if status:
  22. messages.append("Mypy failed with status %d" % status)
  23. if messages and not all("Success" in message for message in messages):
  24. self.fail("\n".join(["Mypy errors:"] + messages))