1
0
mirror of https://github.com/240596448/onec_codetemplate_parser.git synced 2025-11-23 21:34:39 +02:00

проблема наборов

This commit is contained in:
Vladimir Nadulich
2025-11-01 02:18:51 +03:00
parent b0b6983ab9
commit 1c0003a015
3 changed files with 22 additions and 13 deletions

View File

@@ -31,9 +31,17 @@ def test_data(test_file_path):
return file_data return file_data
@pytest.fixture(scope="class") @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' для теста. Создаёт временную папку 'src' для теста.
Папка автоматически удаляется после теста. Папка автоматически удаляется после теста.
""" """
return tmp_path_factory.mktemp("src") return tmp_path / "src"

View File

@@ -6,8 +6,11 @@ class Test_API:
def test_parse(self, test_file_path, temp_src): def test_parse(self, test_file_path, temp_src):
"""Тест библиотеки: парсинг""" """Тест библиотеки: парсинг"""
parse_to_src(str(test_file_path), str(temp_src)) parse_to_src(str(test_file_path), str(temp_src))
assert folder_is_empty(temp_src), f"Папка src пустая {temp_src}" if test_file_path.stat().st_size > 6:
assert folder_contains_files(temp_src), f"В папке нет ни одного файла {temp_src}" 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): def test_render(self, temp_src, tmp_path):
"""Тест библиотеки: сборка""" """Тест библиотеки: сборка"""

View File

@@ -1,5 +1,5 @@
from onec_codetemplate_parser import core 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: class TestReadSkobkofile:
@@ -23,21 +23,19 @@ class TestReadSkobkofile:
class TestWriteToFiles: 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 = core.parser(test_data)
root.to_files(temp_src) root.to_files(temp_src)
def test_01_to_files(self, temp_src): # assert folder_contains_files(temp_src), f"В папке нет ни одного файла {temp_src}"
# Проверка: есть ли файлы # assert not folder_is_empty(temp_src), f"Папка src пустая {temp_src}"
files = [p for p in temp_src.iterdir() if p.is_file()]
assert len(files) == 0
# Проверка: есть ли папки # Проверка: есть ли папки
dirs = [p for p in temp_src.iterdir() if p.is_dir()] dirs = [p for p in temp_src.iterdir() if p.is_dir()]
assert len(dirs) == 1 assert len(dirs) == 1, f"Ожидалась 1 папка в src, получили {len(dirs)}"
assert temp_src / "001.0_Надулич" in 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_Комментарии" d = temp_src / "001.0_Надулич" / "002.0_Комментарии"
subfiles = [p.name for p in d.iterdir()] subfiles = [p.name for p in d.iterdir()]
check_files_sequential(subfiles) check_files_sequential(subfiles)