Skip to content

Commit

Permalink
Merge pull request #97 from dbatten5/bump-version
Browse files Browse the repository at this point in the history
Bump version
  • Loading branch information
dbatten5 authored Feb 4, 2022
2 parents 351f787 + 75a182f commit dd2ae24
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 50 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "maison"
version = "1.3.0"
version = "1.4.0"
description = "Maison"
authors = ["Dom Batten <dominic.batten@googlemail.com>"]
license = "MIT"
Expand Down
15 changes: 7 additions & 8 deletions src/maison/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
86 changes: 45 additions & 41 deletions tests/unit/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit dd2ae24

Please sign in to comment.