| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- """Структурный тест."""
- import sys
- from typing import List
- from collections import namedtuple
- from pathlib import Path
- BASE_DIR: Path = Path(__file__).resolve().parent
- sys.path.append(BASE_DIR)
- PathForTests = namedtuple('TestPaths', ('rel_path', 'abs_path'))
- ya_note_tests: Path = BASE_DIR / 'ya_note/notes/tests/'
- ya_news_tests: Path = BASE_DIR / 'ya_news/news/pytest_tests/'
- MESSAGE_TEMPLATE = (
- '\nНе обнаружены тесты для проекта `{project}`. Убедитесь, что тесты, '
- 'которые вы написали, размещены в директории `{path}`.'
- )
- projects_map = {
- 'ya_note': PathForTests(
- 'django_testing/ya_note/notes/tests', ya_note_tests
- ),
- 'ya_news': PathForTests(
- 'django_testing/ya_news/news/pytest_tests', ya_news_tests
- )
- }
- errors: List[str] = []
- for project_name, path in projects_map.items():
- if not path.abs_path.is_dir():
- errors.append(MESSAGE_TEMPLATE.format(
- project=project_name, path=path.rel_path
- ))
- continue
- path_content = [obj for obj in path.abs_path.glob('*.py') if obj.is_file()]
- if not path_content:
- errors.append(MESSAGE_TEMPLATE.format(
- project=project_name, path=path.rel_path
- ))
- assert not errors, ''.join(errors)
|