2025-11-04 16:08:26 +03:00
|
|
|
import pytest
|
2025-10-31 22:21:26 +03:00
|
|
|
from typer.testing import CliRunner
|
|
|
|
|
from onec_codetemplate_parser.cli import app
|
|
|
|
|
|
|
|
|
|
runner = CliRunner()
|
|
|
|
|
|
2025-11-04 20:34:03 +03:00
|
|
|
class TestCLI:
|
2025-10-31 22:21:26 +03:00
|
|
|
|
|
|
|
|
def test_help_command(self):
|
|
|
|
|
"""Тест вывода справки"""
|
|
|
|
|
result = runner.invoke(app, ["--help"])
|
|
|
|
|
|
|
|
|
|
assert result.exit_code == 0
|
2025-10-31 22:53:12 +03:00
|
|
|
assert "parse " in result.stdout, result.stdout
|
|
|
|
|
assert "render " in result.stdout, result.stdout
|
2025-10-31 22:21:26 +03:00
|
|
|
|
|
|
|
|
def test_parse_help_command(self):
|
|
|
|
|
"""Тест вывода справки команды парсинга"""
|
|
|
|
|
result = runner.invoke(app, ["parse", "--help"])
|
|
|
|
|
|
|
|
|
|
assert result.exit_code == 0
|
2025-10-31 22:53:12 +03:00
|
|
|
assert "path " in result.stdout, result.stdout
|
|
|
|
|
assert "src " in result.stdout, result.stdout
|
2025-10-31 22:21:26 +03:00
|
|
|
|
|
|
|
|
def test_render_help_command(self):
|
|
|
|
|
"""Тест вывода справки команды сборки"""
|
|
|
|
|
result = runner.invoke(app, ["render", "--help"])
|
|
|
|
|
|
|
|
|
|
assert result.exit_code == 0
|
2025-10-31 22:53:12 +03:00
|
|
|
assert "path " in result.stdout, result.stdout
|
|
|
|
|
assert "src " in result.stdout, result.stdout
|
2025-10-31 22:21:26 +03:00
|
|
|
|
2025-11-04 20:34:03 +03:00
|
|
|
def test_parse_command(self, file_path, temp_src):
|
2025-10-31 22:21:26 +03:00
|
|
|
"""Тест выполнения команды парсинга"""
|
2025-11-04 20:34:03 +03:00
|
|
|
result = runner.invoke(app, ["parse", str(file_path), str(temp_src)])
|
2025-10-31 22:53:12 +03:00
|
|
|
assert result.exit_code == 0, result.stdout + result.stderr
|
2025-10-31 22:21:26 +03:00
|
|
|
|
2025-11-04 20:34:03 +03:00
|
|
|
def test_render_command(self, file_path_spec, temp_src, temp_output_st):
|
2025-10-31 22:21:26 +03:00
|
|
|
"""Тест выполнения команды сборки"""
|
2025-11-04 20:34:03 +03:00
|
|
|
if file_path_spec.level == 0:
|
|
|
|
|
pytest.skip(reason=f"Пропускаем тест {file_path_spec.name}: папка SRC будет пустой, CLI не пройдет валидацию")
|
2025-11-04 16:08:26 +03:00
|
|
|
return
|
2025-11-04 20:34:03 +03:00
|
|
|
file_path = file_path_spec.path
|
|
|
|
|
runner.invoke(app, ["parse", str(file_path), str(temp_src)])
|
2025-11-02 23:35:44 +03:00
|
|
|
result = runner.invoke(app, ["render", str(temp_output_st), str(temp_src)], catch_exceptions=False)
|
2025-10-31 22:53:12 +03:00
|
|
|
assert result.exit_code == 0, result.stdout + result.stderr
|
2025-11-04 20:34:03 +03:00
|
|
|
assert file_path.read_text(encoding='utf-8-sig') == temp_output_st.read_text(encoding='utf-8-sig'), 'Собранный файл не совпадает с исходным'
|
2025-11-04 17:28:45 +03:00
|
|
|
|
2025-11-04 20:34:03 +03:00
|
|
|
def test_pretty_print_command(self, file_path_spec):
|
2025-11-04 17:28:45 +03:00
|
|
|
"""Тест выполнения команды парсинга"""
|
2025-11-04 20:34:03 +03:00
|
|
|
result = runner.invoke(app, ["pretty", str(file_path_spec.path)])
|
2025-11-04 17:28:45 +03:00
|
|
|
assert result.exit_code == 0, result.stdout + result.stderr
|
2025-11-04 20:34:03 +03:00
|
|
|
if file_path_spec.objects is None:
|
2025-11-04 17:28:45 +03:00
|
|
|
assert len(result.stdout.splitlines()) > 1, result.stdout + result.stderr
|
2025-11-04 20:34:03 +03:00
|
|
|
else:
|
|
|
|
|
assert len(result.stdout.rstrip(). splitlines()) == file_path_spec.objects + 1, result.stdout + result.stderr
|