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

48 lines
1.5 KiB
Python
Raw Normal View History

2025-10-31 15:23:24 +03:00
"""fixtures for tests"""
2025-10-21 22:33:34 +03:00
from pathlib import Path
2025-10-31 15:23:24 +03:00
import pytest
2025-11-01 01:56:12 +03:00
import os
2025-10-21 22:33:34 +03:00
2025-10-31 15:23:24 +03:00
TEST_FILE = 'Documents/1C/1c-code-templates/Надулич.st'
2025-10-21 22:33:34 +03:00
2025-11-01 01:56:12 +03:00
def get_all_test_files():
"""Автоматически находим все файлы в директории"""
st_files = Path(__file__).parent.glob("data/*.st")
list_st_files = [f for f in st_files if f.is_file()]
list_st_files.append(Path.home()/TEST_FILE)
env_st_templates = os.getenv("ST_TEMPLATES")
if env_st_templates:
st_templates = Path(env_st_templates)
if st_templates.is_file():
list_st_files.append(st_templates)
return [pytest.param(e, id=e.name) for e in list_st_files]
@pytest.fixture(scope="class", name="test_file_path", params=get_all_test_files())
def test_data_path(request):
return Path(request.param)
2025-10-21 22:33:34 +03:00
@pytest.fixture(scope="class")
2025-10-31 15:23:24 +03:00
def test_data(test_file_path):
2025-10-21 22:33:34 +03:00
file_data = test_file_path.read_text(encoding='utf-8-sig')
return file_data
@pytest.fixture(scope="class")
2025-11-01 02:18:51 +03:00
def temp_src_class(tmp_path_factory):
2025-10-21 22:33:34 +03:00
"""
2025-11-01 02:18:51 +03:00
Создаёт временную папку 'src' для класса тестов.
2025-10-21 22:33:34 +03:00
Папка автоматически удаляется после теста.
"""
return tmp_path_factory.mktemp("src")
2025-11-01 02:18:51 +03:00
@pytest.fixture()
def temp_src(tmp_path):
"""
Создаёт временную папку 'src' для теста.
Папка автоматически удаляется после теста.
"""
return tmp_path / "src"