From 92a2e91061eaeb7b0b764e5bacc1a6b8d2ded071 Mon Sep 17 00:00:00 2001 From: Dom Batten Date: Fri, 4 Feb 2022 10:04:53 +0000 Subject: [PATCH 1/2] move `deep_merge` tests into test class --- src/maison/utils.py | 15 ++++--- tests/unit/test_utils.py | 86 +++++++++++++++++++++------------------- 2 files changed, 52 insertions(+), 49 deletions(-) diff --git a/src/maison/utils.py b/src/maison/utils.py index 5dcde4f..c7fb382 100644 --- a/src/maison/utils.py +++ b/src/maison/utils.py @@ -41,25 +41,24 @@ def get_file_path( if filename_path.is_absolute() and filename_path.is_file(): return filename_path - for path in _generate_search_paths(starting_path=starting_path): + start = starting_path or Path.cwd() + + for path in _generate_search_paths(starting_path=start): if path_contains_file(path=path, filename=filename): return path / filename return None -def _generate_search_paths( - starting_path: Optional[Path] = None, -) -> Generator[Path, None, None]: - """Generate paths from either a starting path or `Path.cwd()`. +def _generate_search_paths(starting_path: Path) -> Generator[Path, None, None]: + """Generate paths from a starting path and traversing up the tree. Args: - starting_path: an optional starting path to start yielding search paths + starting_path: a starting path to start yielding search paths Yields: - a path + a path from the tree """ - starting_path = starting_path or Path.cwd() for path in [starting_path, *starting_path.parents]: yield path diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py index ec9d008..117caa5 100644 --- a/tests/unit/test_utils.py +++ b/tests/unit/test_utils.py @@ -122,44 +122,48 @@ def test_absolute_path_not_exist(self) -> None: assert result is None -@mark.parametrize( - "a,b,expected", - [ - param( - {1: 2, 3: 4}, - {3: 5, 6: 7}, - {1: 2, 3: 5, 6: 7}, - id="simple", - ), - param( - {1: 2, 3: {4: 5, 6: 7}}, - {3: {6: 8, 9: 10}, 11: 12}, - {1: 2, 3: {4: 5, 6: 8, 9: 10}, 11: 12}, - id="nested", - ), - ], -) -def test_deep_merge( - a: Dict[Any, Any], - b: Dict[Any, Any], - expected: Dict[Any, Any], -) -> None: - """ - Given two dictionaries `a` and `b`, - when the `deep_merge` function is invoked with `a` and `b` as arguments, - Test that the returned value is as expected. - """ - assert deep_merge(a, b) == expected - assert a == expected - - -def test_deep_merge_dict_into_scalar() -> None: - """ - Given two incompatible dictionaries `a` and `b`, - when the `deep_merge` function is invoked with `a` and `b` as arguments, - Test that a RuntimeError is raised. - """ - a = {1: 2, 2: 5} - b = {1: {3: 4}} - with raises(RuntimeError): - deep_merge(a, b) +class TestDeepMerge: + """Tests for the `deep_merge` function.""" + + @mark.parametrize( + "a,b,expected", + [ + param( + {1: 2, 3: 4}, + {3: 5, 6: 7}, + {1: 2, 3: 5, 6: 7}, + id="simple", + ), + param( + {1: 2, 3: {4: 5, 6: 7}}, + {3: {6: 8, 9: 10}, 11: 12}, + {1: 2, 3: {4: 5, 6: 8, 9: 10}, 11: 12}, + id="nested", + ), + ], + ) + def test_success( + self, + a: Dict[Any, Any], + b: Dict[Any, Any], + expected: Dict[Any, Any], + ) -> None: + """ + Given two dictionaries `a` and `b`, + When the `deep_merge` function is invoked with `a` and `b` as arguments, + Then the returned value is as expected + """ + assert deep_merge(a, b) == expected + assert a == expected + + def test_incompatible_dicts(self) -> None: + """ + Given two incompatible dictionaries `a` and `b`, + When the `deep_merge` function is invoked with `a` and `b` as arguments, + Then a RuntimeError is raised + """ + dict_a = {1: 2, 2: 5} + dict_b = {1: {3: 4}} + + with raises(RuntimeError): + deep_merge(dict_a, dict_b) From 75a182f4d530d31556e21fd59bdf4c266693c6ff Mon Sep 17 00:00:00 2001 From: Dom Batten Date: Fri, 4 Feb 2022 10:05:20 +0000 Subject: [PATCH 2/2] bump version to 1.4.0 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index ae23f15..643c7e1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "maison" -version = "1.3.0" +version = "1.4.0" description = "Maison" authors = ["Dom Batten "] license = "MIT"