aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorEugene Triguba <eugenetriguba@gmail.com>2020-08-01 17:58:32 -0500
committerEugene Triguba <eugenetriguba@gmail.com>2020-08-01 17:58:32 -0500
commit032196104a59761bd75b5d594440d1e8ef16965a (patch)
treeefd67c11ac11ba7a64dc09e53b1f329916384d06 /tests
parentRaise FileNotFoundError if the config file does not exist (diff)
downloadconfig-file-032196104a59761bd75b5d594440d1e8ef16965a.zip
Add ConfigFilePath to refactor out file specific code
Diffstat (limited to 'tests')
-rw-r--r--tests/conftest.py11
-rw-r--r--tests/test_config_file.py9
-rw-r--r--tests/test_config_file_path.py0
3 files changed, 8 insertions, 12 deletions
diff --git a/tests/conftest.py b/tests/conftest.py
index 70e88c7..faf1630 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -4,7 +4,7 @@ from typing import Callable, Tuple, Type, Union
import pytest
from config_file import AbstractParser, ConfigFile
-from config_file.utils import create_config_path
+from config_file.config_file_path import ConfigFilePath
@pytest.fixture
@@ -37,7 +37,7 @@ def template_original_file() -> Callable[[Path], Path]:
if isinstance(template_path, str):
template_path = Path(template_path)
- original_path = create_config_path(template_path, original=True)
+ original_path = ConfigFilePath(template_path).original_path
original_path.touch()
original_path.write_text(template_path.read_text(encoding="utf-8"))
@@ -54,12 +54,7 @@ def template_and_parser(
file_type: str, template_name: str = "default"
) -> Tuple[Path, Type[AbstractParser]]:
test_file = template_file(file_type, template_name)
- text = test_file.read_text(encoding="utf-8")
-
- parser = ConfigFile._ConfigFile__find_parser_by_file_type(
- file_contents=text, file_type=file_type, file_path=test_file
- )
- return test_file, parser
+ return test_file, ConfigFile(test_file)._ConfigFile__parser
return func
diff --git a/tests/test_config_file.py b/tests/test_config_file.py
index d655397..548951b 100644
--- a/tests/test_config_file.py
+++ b/tests/test_config_file.py
@@ -30,7 +30,7 @@ def templated_config_file(template_and_config_file):
def test_that_config_file_is_initialized_correctly(template_and_config_file):
template_file, config = template_and_config_file()
- assert config.path == template_file
+ assert config.file_path == template_file
assert config.stringify() == template_file.read_text()
assert isinstance(config._ConfigFile__parser, AbstractParser)
@@ -41,7 +41,7 @@ def test_that_a_tidle_in_the_config_path_expands_to_the_absolute_path():
try:
Path(config_path).expanduser().touch()
- assert ConfigFile(config_path).path == Path.home() / config_name
+ assert ConfigFile(config_path).file_path == Path.home() / config_name
finally:
Path(config_path).expanduser().unlink()
@@ -66,7 +66,7 @@ def test_that_config_file_can_restore_the_original(
templated_config_file, template_original_file
):
config = templated_config_file()
- original_file = template_original_file(config.path)
+ original_file = template_original_file(config.file_path)
config.set("header_one.number_key", 5)
config.restore_original()
@@ -80,7 +80,8 @@ def test_missing_config_file_during_restore(templated_config_file):
with pytest.raises(FileNotFoundError) as error:
config.restore_original()
- assert "file to restore to does not exist" in str(error)
+ assert "The specified config file" in str(error)
+ assert "does not exist" in str(error)
@pytest.mark.parametrize(
diff --git a/tests/test_config_file_path.py b/tests/test_config_file_path.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/test_config_file_path.py