Skip to content

Commit

Permalink
fix dict merges with atomic base
Browse files Browse the repository at this point in the history
  • Loading branch information
trehn committed Jul 4, 2018
1 parent b14a750 commit cd35f74
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
6 changes: 5 additions & 1 deletion bundlewrap/utils/dicts.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,11 @@ def merge_dict(base, update):
merged = base.copy()

for key, value in update.items():
merge = key in base and not isinstance(value, _Atomic)
merge = (
key in base and
not isinstance(value, _Atomic) and
not isinstance(base[key], _Atomic)
)
if merge and isinstance(base[key], dict):
merged[key] = merge_dict(base[key], value)
elif (
Expand Down
16 changes: 15 additions & 1 deletion tests/unit/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,21 @@
from __future__ import unicode_literals

from bundlewrap.utils.dicts import merge_dict
from bundlewrap.metadata import blame_changed_paths
from bundlewrap.metadata import atomic, blame_changed_paths


def test_atomic_no_merge_base():
assert merge_dict(
{1: atomic([5])},
{1: [6, 7]},
) == {1: [6, 7]}


def test_atomic_no_merge_update():
assert merge_dict(
{1: [5]},
{1: atomic([6, 7])},
) == {1: [6, 7]}


def test_blame_and_merge():
Expand Down

0 comments on commit cd35f74

Please sign in to comment.