diff --git a/tests/common.py b/tests/common.py index e63e405..d860d60 100644 --- a/tests/common.py +++ b/tests/common.py @@ -1,4 +1,5 @@ import re +from pathlib import Path def check_files_sequential(files: list[str]): @@ -14,3 +15,11 @@ def check_files_sequential(files: list[str]): assert number == true_number, f"Пропущен номер: ожидаем {true_number}, получили {number}" expected_number += 1 + +def folder_is_empty(path): + return len(list(Path(path).iterdir())) != 0 + +def folder_contains_files(path): + files = [f.name for f in Path(path).rglob('*') if f.is_file()] + return len(files) > 0 + diff --git a/tests/test_api.py b/tests/test_api.py new file mode 100644 index 0000000..0551496 --- /dev/null +++ b/tests/test_api.py @@ -0,0 +1,17 @@ +from onec_codetemplate_parser import parse_to_src, render_from_src +from tests.common import folder_is_empty, folder_contains_files + +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}" + + def test_render(self, temp_src, tmp_path): + """Тест библиотеки: сборка""" + + temp_file = tmp_path / "output.st" + render_from_src(str(temp_src), str(temp_file)) + assert temp_file.exists(), f"Файл сборки не создан {temp_file}" \ No newline at end of file