77 lines
1.9 KiB
Python
77 lines
1.9 KiB
Python
"""
|
|
Configuration for the tests
|
|
... and local Plugins
|
|
"""
|
|
import subprocess
|
|
from os.path import dirname, join
|
|
from typing import Callable, Generator
|
|
|
|
import pytest
|
|
from _pytest.config import Config
|
|
|
|
|
|
def get_csv(csv: str) -> str:
|
|
"""
|
|
Get CSV data
|
|
"""
|
|
with open(join(dirname(__file__), "assets", f"{csv}.csv"), "rb") as csv_fh:
|
|
csv_data = csv_fh.read()
|
|
return csv_data.decode("utf-8")
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def simple_test_csv() -> str:
|
|
"""
|
|
Provide simple CSV data
|
|
"""
|
|
return get_csv("simple-test")
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def bad_test_csv() -> str:
|
|
"""
|
|
Provide bad CSV data
|
|
"""
|
|
return get_csv("bad-test")
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def text_test_csv() -> str:
|
|
"""
|
|
Provide text-only CSV data
|
|
"""
|
|
return get_csv("text-only")
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def simple_fruit_test() -> Callable[[str], str]:
|
|
"""
|
|
Provide simple test case
|
|
"""
|
|
with open(join(dirname(__file__), "assets", "fruit_test.tpl"), "rt", encoding="utf-8") as test_fh:
|
|
test_data = test_fh.read()
|
|
return lambda file: test_data.replace("{{data_file}}", file)
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def simple_text_test() -> Callable[[str], str]:
|
|
"""
|
|
Provide simple text test case
|
|
"""
|
|
with open(join(dirname(__file__), "assets", "text_test.tpl"), "rt", encoding="utf-8") as test_fh:
|
|
test_data = test_fh.read()
|
|
return lambda file: test_data.replace("{{data_file}}", file)
|
|
|
|
|
|
@pytest.fixture(scope="session", autouse=True)
|
|
def install_plugin_locally(pytestconfig: Config) -> Generator[None, None, None]:
|
|
"""
|
|
Install the local package
|
|
"""
|
|
root = pytestconfig.rootpath
|
|
_ = subprocess.run(["pip", "install", "-e", "."], shell=True, cwd=root, check=True, capture_output=True)
|
|
yield
|
|
_ = subprocess.run(
|
|
["pip", "uninstall", "-y", "pytest_csv_params"], shell=True, cwd=root, check=True, capture_output=True
|
|
)
|