2025-10-31 23:35:15 +03:00
|
|
|
from onec_codetemplate_parser import parse_to_src, render_from_src
|
2025-11-04 16:08:26 +03:00
|
|
|
from tests.common import folder_is_empty
|
2025-10-31 23:35:15 +03:00
|
|
|
|
2025-11-04 20:39:58 +03:00
|
|
|
class TestAPI:
|
2025-10-31 23:35:15 +03:00
|
|
|
|
2025-11-04 20:34:03 +03:00
|
|
|
def test_parse(self, file_path_spec, temp_src):
|
2025-10-31 23:35:15 +03:00
|
|
|
"""Тест библиотеки: парсинг"""
|
2025-11-04 20:34:03 +03:00
|
|
|
parse_to_src(str(file_path_spec.path), str(temp_src))
|
|
|
|
|
if file_path_spec.level != 0:
|
|
|
|
|
assert not folder_is_empty(temp_src), f"Папка src пустая {temp_src}"
|
2025-11-01 02:18:51 +03:00
|
|
|
else:
|
2025-11-04 20:34:03 +03:00
|
|
|
assert folder_is_empty(temp_src), f"Для пустого файла что-то распарсилось {temp_src}"
|
2025-11-04 20:39:58 +03:00
|
|
|
|
2025-11-04 20:34:03 +03:00
|
|
|
def test_render(self, file_path, temp_src, tmp_path):
|
2025-10-31 23:35:15 +03:00
|
|
|
"""Тест библиотеки: сборка"""
|
|
|
|
|
|
2025-11-04 20:34:03 +03:00
|
|
|
parse_to_src(str(file_path), str(temp_src))
|
2025-10-31 23:35:15 +03:00
|
|
|
temp_file = tmp_path / "output.st"
|
|
|
|
|
render_from_src(str(temp_src), str(temp_file))
|
2025-11-02 23:35:44 +03:00
|
|
|
assert temp_file.exists(), f"Файл сборки не создан {temp_file}"
|
2025-11-04 20:39:58 +03:00
|
|
|
assert file_path.read_text(encoding='utf-8-sig') == temp_file.read_text(encoding='utf-8-sig'), 'Собранный файл не совпадает с исходным'
|