Skip to content

Commit a7d91e7

Browse files
Fix for removing items from dicts (#17)
* Fix for nested dict * Replace nested test with simpler test Also added pytest-cov to get an idea of what the code coverage is. Apparently lines 98-99 of diff.py were exactly *not* covered. Simply adding a test where an item is removed from a dict hits those two lines. Bonus: pytest-watch in dev tools.
1 parent 636ab3c commit a7d91e7

File tree

5 files changed

+82
-7
lines changed

5 files changed

+82
-7
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
- name: Lint
4040
run: poetry run flake8
4141
- name: Test
42-
run: poetry run pytest
42+
run: poetry run pytest -v --cov=patchdiff --cov-report=term-missing
4343

4444
build:
4545
name: Build and test wheel

patchdiff/diff.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def diff_dicts(input: Dict, output: Dict, ptr: Pointer) -> Tuple[List, List]:
9696
output_keys = set(output.keys())
9797
for key in input_keys - output_keys:
9898
ops.append({"op": "remove", "path": ptr.append(key)})
99-
rops.insert(0, {"op": "add", "path": ptr.append(key), "value": output[key]})
99+
rops.insert(0, {"op": "add", "path": ptr.append(key), "value": input[key]})
100100
for key in output_keys - input_keys:
101101
ops.append(
102102
{

poetry.lock

Lines changed: 69 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ flake8-black = "*"
1616
flake8-import-order = "*"
1717
flake8-print = "*"
1818
pytest = "*"
19+
pytest-cov = "*"
20+
pytest-watch = "*"
1921
twine = "*"
2022

2123
[build-system]

tests/test_diff.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,15 @@ def test_dicts():
122122
]
123123

124124

125+
def test_dicts_remove_item():
126+
a = {"a": 3, "b": 6}
127+
b = {"a": 3}
128+
ops, rops = diff(a, b)
129+
130+
assert ops == [{"op": "remove", "path": Pointer(["b"])}]
131+
assert rops == [{"op": "add", "path": Pointer(["b"]), "value": 6}]
132+
133+
125134
def test_sets():
126135
a = {"a", "b"}
127136
b = {"a", "c"}

0 commit comments

Comments
 (0)