aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_utils.py
diff options
context:
space:
mode:
authorEugene Triguba <eugenetriguba@gmail.com>2020-08-07 20:25:00 -0500
committerGitHub <noreply@github.com>2020-08-07 20:25:00 -0500
commit05dba35cab34c2524b945da0164327b7b8a1159d (patch)
treee1f263a316839c0d32a413c120a3c92426f36817 /tests/test_utils.py
parentCreate python-package-ci.yml (diff)
parentFix ConfigFile default (diff)
downloadconfig-file-05dba35cab34c2524b945da0164327b7b8a1159d.zip
Merge pull request #24 from eugenetriguba/dev
v0.11.0
Diffstat (limited to 'tests/test_utils.py')
-rw-r--r--tests/test_utils.py78
1 files changed, 66 insertions, 12 deletions
diff --git a/tests/test_utils.py b/tests/test_utils.py
index 6779d18..663aaba 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -1,19 +1,73 @@
+from pathlib import Path
+
import pytest
-from config_file.utils import split_on_dot
+from config_file.utils import Default, split_on_dot
+
+
+def test_that_split_on_dot_splits_the_line_correctly():
+ """
+ config_file.utils.split_on_dot
+
+ Ensure splitting a string with dots in it returns an
+ array of strings split on those dots.
+ """
+ assert split_on_dot("section.key.blah") == ["section", "key", "blah"]
-@pytest.mark.parametrize(
- "test_input, only_last_dot, expected_result",
- [("section.key.blah", False, ["section", "key", "blah"])],
-)
-def test_that_split_on_dot_splits_the_line_correctly(
- test_input, only_last_dot, expected_result
-):
- assert split_on_dot(test_input, only_last_dot=only_last_dot) == expected_result
+def test_that_split_on_dot_can_only_split_on_the_last_one():
+ """
+ config_file.utils.split_on_dot
+ Ensure that the only_last_dot parameter only splits the input
+ on the last dot.
+ """
+ assert split_on_dot("test.input.should.only.split.on.last", only_last_dot=True) == [
+ "test.input.should.only.split.on",
+ "last",
+ ]
-@pytest.mark.parametrize("test_input", ["this line has no dots in it"])
-def test_that_split_on_dot_raises_error_when_there_is_no_dot(test_input):
+
+def test_that_split_on_dot_raises_error_when_there_is_no_dot():
+ """
+ config_file.utils.split_on_dot
+
+ Ensure that a ValueError is raised if the input to split_on_dot
+ has no dot (.) in it.
+ """
with pytest.raises(ValueError):
- split_on_dot(test_input)
+ split_on_dot("this line has no dots in it")
+
+
+def test_that_split_on_dot_can_accept_path_objects():
+ """
+ config_file.utils.split_on_dot
+
+ Ensure that a pathlib.Path object is able to be
+ given to split_on_dot.
+ """
+ split = split_on_dot(Path("some.file.path.with.dots"))
+
+ assert split == ["some", "file", "path", "with", "dots"]
+
+
+def test_that_default_is_initialized_correctly():
+ """
+ config_file.utils.Default
+
+ Ensure that the Default class's value attribute
+ is the same value that it was constructed with.
+ """
+ default = Default(5)
+ assert default.value == 5
+
+
+def test_that_default_has_the_correct_repr_format():
+ """
+ config_file.utils.Default
+
+ Ensure that when the Default class is coerced to
+ a string, it has the correct format and output.
+ """
+ default = Default("test")
+ assert str(default) == "Default Value: test (<class 'str'>)"