structure_test.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. """Структурный тест."""
  2. import sys
  3. from typing import List
  4. from collections import namedtuple
  5. from pathlib import Path
  6. BASE_DIR: Path = Path(__file__).resolve().parent
  7. sys.path.append(BASE_DIR)
  8. PathForTests = namedtuple('TestPaths', ('rel_path', 'abs_path'))
  9. ya_note_tests: Path = BASE_DIR / 'ya_note/notes/tests/'
  10. ya_news_tests: Path = BASE_DIR / 'ya_news/news/pytest_tests/'
  11. MESSAGE_TEMPLATE = (
  12. '\nНе обнаружены тесты для проекта `{project}`. Убедитесь, что тесты, '
  13. 'которые вы написали, размещены в директории `{path}`.'
  14. )
  15. projects_map = {
  16. 'ya_note': PathForTests(
  17. 'django_testing/ya_note/notes/tests', ya_note_tests
  18. ),
  19. 'ya_news': PathForTests(
  20. 'django_testing/ya_news/news/pytest_tests', ya_news_tests
  21. )
  22. }
  23. errors: List[str] = []
  24. for project_name, path in projects_map.items():
  25. if not path.abs_path.is_dir():
  26. errors.append(MESSAGE_TEMPLATE.format(
  27. project=project_name, path=path.rel_path
  28. ))
  29. continue
  30. path_content = [obj for obj in path.abs_path.glob('*.py') if obj.is_file()]
  31. if not path_content:
  32. errors.append(MESSAGE_TEMPLATE.format(
  33. project=project_name, path=path.rel_path
  34. ))
  35. assert not errors, ''.join(errors)