You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.3 KiB

5 years ago
5 years ago
5 years ago
  1. import os
  2. import json
  3. import pytest
  4. import _pytest
  5. from tibi_hardlinks.backup_parser import parse_property_text
  6. # random_data fixture
  7. # sample data fixture
  8. TEST_PROPERTY_DATA_ROOT = "test_data/property_files"
  9. @pytest.fixture
  10. def canned_data_input(pytestconfig: _pytest.config.Config):
  11. # def canned_data_input():
  12. def get_canned_data(filename):
  13. full_path = os.path.join(
  14. pytestconfig.rootdir, TEST_PROPERTY_DATA_ROOT, filename
  15. )
  16. with open(full_path + ".txt", "r") as test_file:
  17. return test_file.read()
  18. return get_canned_data
  19. @pytest.fixture
  20. def canned_data_output(pytestconfig: _pytest.config.Config):
  21. # def canned_data_output():
  22. def get_canned_data(filename):
  23. full_path = os.path.join(
  24. pytestconfig.rootdir, TEST_PROPERTY_DATA_ROOT, filename
  25. )
  26. with open(full_path + ".json", "r") as test_file:
  27. return json.load(test_file)
  28. return get_canned_data
  29. @pytest.mark.parametrize("filename", [("example-new"), ("example-old")])
  30. def test_canned_data(filename, canned_data_input, canned_data_output):
  31. data = canned_data_input(filename)
  32. expected_output = canned_data_output(filename)
  33. experimental = parse_property_text(data)
  34. for key, value in expected_output.items():
  35. assert experimental[key] == value