structure_test.py 1.2 KB

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