-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #191 from NCI-GDC/feat/DEV-2143-diff-and-merge-map…
…ping-functionality DEV-2143: add mapping diff/merge functionality
- Loading branch information
Showing
8 changed files
with
80 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ language: python | |
env: | ||
- ES_VERSION="7.7.1" | ||
python: | ||
- "3.6" | ||
- "3.7" | ||
|
||
before_install: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from typing import Dict | ||
|
||
import deepdiff | ||
import mergedeep | ||
|
||
|
||
def deep_merge_mapping_files(one: Dict, two: Dict) -> Dict: | ||
return mergedeep.merge(one, two, strategy=mergedeep.Strategy.ADDITIVE) | ||
|
||
|
||
def deep_diff_mapping_files(new: Dict, old: Dict) -> Dict: | ||
"""Return the dictionary of things that are in the old dict and not in the new""" | ||
diff = deepdiff.DeepDiff(new, old) | ||
return {} + deepdiff.Delta(diff, force=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import pytest | ||
from gdcmodels import mapping_utils | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"one,two,expected", | ||
[ | ||
( | ||
{"a": {"a": None}}, | ||
{"a": {"b": None}}, | ||
{"a": {"a": None, "b": None}}, | ||
), | ||
( | ||
{"a": {"a": {"a": None}}}, | ||
{"a": {"b": None}}, | ||
{"a": {"a": {"a": None}, "b": None}}, | ||
), | ||
], | ||
) | ||
def test_deep_merge_mapping_files(one, two, expected): | ||
assert mapping_utils.deep_merge_mapping_files(one, two) == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"old,new,difference", | ||
[ | ||
( | ||
{"a": {"a": None, "b": None}}, | ||
{"a": {"a": None}}, | ||
{"a": {"b": None}}, | ||
), | ||
( | ||
{"a": {"a": {"a": None}, "b": None}}, | ||
{"a": {"a": {"a": None}}}, | ||
{"a": {"b": None}}, | ||
), | ||
], | ||
) | ||
def test_deep_diff_mapping_files(old, new, difference): | ||
assert mapping_utils.deep_diff_mapping_files(new, old) == difference |