diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..13bd3c6 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1 @@ +from fixtures.load import canned_data_input, canned_data_output diff --git a/tests/fixtures/load.py b/tests/fixtures/load.py new file mode 100644 index 0000000..08ce710 --- /dev/null +++ b/tests/fixtures/load.py @@ -0,0 +1,36 @@ +import os +import json +import pytest +import _pytest + + +TEST_PROPERTY_DATA_ROOT = "test_data/property_files" + + +@pytest.fixture +def canned_data_input(pytestconfig: _pytest.config.Config): + # def canned_data_input(): + def get_canned_data(filename): + + full_path = os.path.join( + pytestconfig.rootdir, TEST_PROPERTY_DATA_ROOT, filename + ) + + with open(full_path + ".txt", "r") as test_file: + return test_file.read() + + return get_canned_data + + +@pytest.fixture +def canned_data_output(pytestconfig: _pytest.config.Config): + # def canned_data_output(): + def get_canned_data(filename): + full_path = os.path.join( + pytestconfig.rootdir, TEST_PROPERTY_DATA_ROOT, filename + ) + + with open(full_path + ".json", "r") as test_file: + return json.load(test_file) + + return get_canned_data diff --git a/tests/test_parser_on_data.py b/tests/test_parser_on_data.py index a1eef2b..ba31221 100644 --- a/tests/test_parser_on_data.py +++ b/tests/test_parser_on_data.py @@ -1,45 +1,13 @@ -import os -import json import pytest -import _pytest + from tibi_hardlinks.backup_parser import parse_property_text # random_data fixture # sample data fixture -TEST_PROPERTY_DATA_ROOT = "test_data/property_files" - - -@pytest.fixture -def canned_data_input(pytestconfig: _pytest.config.Config): - # def canned_data_input(): - def get_canned_data(filename): - - full_path = os.path.join( - pytestconfig.rootdir, TEST_PROPERTY_DATA_ROOT, filename - ) - - with open(full_path + ".txt", "r") as test_file: - return test_file.read() - - return get_canned_data - - -@pytest.fixture -def canned_data_output(pytestconfig: _pytest.config.Config): - # def canned_data_output(): - def get_canned_data(filename): - full_path = os.path.join( - pytestconfig.rootdir, TEST_PROPERTY_DATA_ROOT, filename - ) - - with open(full_path + ".json", "r") as test_file: - return json.load(test_file) - - return get_canned_data - +@pytest.mark.usefixtures("canned_data_input", "canned_data_output") @pytest.mark.parametrize("filename", [("example-new"), ("example-old")]) def test_canned_data(filename, canned_data_input, canned_data_output): data = canned_data_input(filename)