From 1c0003a015392b22a074f42997df967d8344faf3 Mon Sep 17 00:00:00 2001 From: Vladimir Nadulich Date: Sat, 1 Nov 2025 02:18:51 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=B1=D0=BB=D0=B5=D0=BC?= =?UTF-8?q?=D0=B0=20=D0=BD=D0=B0=D0=B1=D0=BE=D1=80=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/conftest.py | 12 ++++++++++-- tests/test_api.py | 7 +++++-- tests/test_core.py | 16 +++++++--------- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index cacbd94..b503fa4 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -31,9 +31,17 @@ def test_data(test_file_path): return file_data @pytest.fixture(scope="class") -def temp_src(tmp_path_factory): +def temp_src_class(tmp_path_factory): + """ + Создаёт временную папку 'src' для класса тестов. + Папка автоматически удаляется после теста. + """ + return tmp_path_factory.mktemp("src") + +@pytest.fixture() +def temp_src(tmp_path): """ Создаёт временную папку 'src' для теста. Папка автоматически удаляется после теста. """ - return tmp_path_factory.mktemp("src") + return tmp_path / "src" diff --git a/tests/test_api.py b/tests/test_api.py index 0551496..21c0594 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -6,8 +6,11 @@ class Test_API: def test_parse(self, test_file_path, temp_src): """Тест библиотеки: парсинг""" parse_to_src(str(test_file_path), str(temp_src)) - assert folder_is_empty(temp_src), f"Папка src пустая {temp_src}" - assert folder_contains_files(temp_src), f"В папке нет ни одного файла {temp_src}" + if test_file_path.stat().st_size > 6: + assert folder_is_empty(temp_src), f"Папка src пустая {temp_src}" + assert folder_contains_files(temp_src), f"В папке нет ни одного файла {temp_src}" + else: + assert not folder_is_empty(temp_src), f"Для пустого файла что-то распарсилось {temp_src}" def test_render(self, temp_src, tmp_path): """Тест библиотеки: сборка""" diff --git a/tests/test_core.py b/tests/test_core.py index 844c57d..16fd922 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -1,5 +1,5 @@ from onec_codetemplate_parser import core -from tests.common import check_files_sequential +from tests.common import check_files_sequential, folder_is_empty, folder_contains_files class TestReadSkobkofile: @@ -23,21 +23,19 @@ class TestReadSkobkofile: class TestWriteToFiles: - def test_00_to_file(self, test_data, temp_src): + def test_white_to_src(self, test_data, temp_src): root = core.parser(test_data) root.to_files(temp_src) - def test_01_to_files(self, temp_src): - # Проверка: есть ли файлы - files = [p for p in temp_src.iterdir() if p.is_file()] - assert len(files) == 0 + # assert folder_contains_files(temp_src), f"В папке нет ни одного файла {temp_src}" + # assert not folder_is_empty(temp_src), f"Папка src пустая {temp_src}" # Проверка: есть ли папки dirs = [p for p in temp_src.iterdir() if p.is_dir()] - assert len(dirs) == 1 - assert temp_src / "001.0_Надулич" in dirs + assert len(dirs) == 1, f"Ожидалась 1 папка в src, получили {len(dirs)}" + assert temp_src / "001.0_Надулич" in dirs, f"Папка 001.0_Надулич не найдена в {temp_src}" - def test_02_sequential_name(self, temp_src): + def test_sequential_name(self, temp_src): d = temp_src / "001.0_Надулич" / "002.0_Комментарии" subfiles = [p.name for p in d.iterdir()] check_files_sequential(subfiles)