From 91dc563a14744f1e308f6cd6550e13989b8d8ff1 Mon Sep 17 00:00:00 2001 From: Vladimir Nadulich Date: Sun, 2 Nov 2025 23:35:44 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=BD=D0=B0=20=D0=BA=D0=B0=D0=B6=D0=B4=D1=8B=D0=B9=20?= =?UTF-8?q?=D1=84=D0=B0=D0=B9=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/conftest.py | 11 ++++++++--- tests/test_api.py | 7 ++++--- tests/test_cli.py | 7 ++++--- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index b503fa4..c31f69c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -34,14 +34,19 @@ def test_data(test_file_path): 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 / "src" + +@pytest.fixture() +def temp_output_st(tmp_path): + """ + Создаёт временный файл для вывода каждого теста. + """ + return tmp_path / "output.st" diff --git a/tests/test_api.py b/tests/test_api.py index 21c0594..d66d594 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -8,13 +8,14 @@ class Test_API: parse_to_src(str(test_file_path), str(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): + def test_render(self, test_file_path, temp_src, tmp_path): """Тест библиотеки: сборка""" + parse_to_src(str(test_file_path), str(temp_src)) 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 + assert temp_file.exists(), f"Файл сборки не создан {temp_file}" + assert test_file_path.read_text(encoding='utf-8-sig') == temp_file.read_text(encoding='utf-8-sig'), 'Собранный файл не совпадает с исходным' \ No newline at end of file diff --git a/tests/test_cli.py b/tests/test_cli.py index 11d796c..7e2e045 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -34,8 +34,9 @@ class Test_CLI: result = runner.invoke(app, ["parse", str(test_file_path), str(temp_src)]) assert result.exit_code == 0, result.stdout + result.stderr - def test_render_command(self, test_file_path, temp_src): + def test_render_command(self, test_file_path, temp_src, temp_output_st): """Тест выполнения команды сборки""" - result = runner.invoke(app, ["render", str(test_file_path), str(temp_src)], catch_exceptions=False) + runner.invoke(app, ["parse", str(test_file_path), str(temp_src)]) + result = runner.invoke(app, ["render", str(temp_output_st), str(temp_src)], catch_exceptions=False) assert result.exit_code == 0, result.stdout + result.stderr - \ No newline at end of file + assert test_file_path.read_text(encoding='utf-8-sig') == temp_output_st.read_text(encoding='utf-8-sig'), 'Собранный файл не совпадает с исходным'