mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-05 23:09:32 +01:00
* test: remove never used copy of load_stage_file() * dvc: save comments and custom formatting in stage files * Add a couple of TODOs * test: test repro doesn't clear comments and formatting in .dvc As part of this I started writing pytest-like tests and added commonly used fixtures. * test: simplify and prettify dvc formatting retained test Also test that line comments after md5 fields are retained. * test: fix tests * dvc: fix stage and metrics opens not closed * dvc: always use utf-8 in stage files It used to encode in system default encoding. Not sure if PyYAML was handling this silently or we were just lucky all the way. * test: unit test apply_diff() * test: remove TODOs and ASK * dvc: polish dvc-formatting PR * dvc: move stage load/dump utils to a new stage utils file * dvc: clean up apply_diff() * test: test stage md5 ignores comments * test: remove pytests starting marker
50 lines
1.0 KiB
Python
50 lines
1.0 KiB
Python
from dvc.utils.collections import apply_diff
|
|
|
|
|
|
class MyDict(dict):
|
|
pass
|
|
|
|
|
|
class MyInt(int):
|
|
pass
|
|
|
|
|
|
def test_apply_diff_is_inplace():
|
|
dest = MyDict()
|
|
dest.attr = 42
|
|
apply_diff({}, dest)
|
|
|
|
assert type(dest) is MyDict, "Preserves class"
|
|
assert dest.attr == 42, "Preserves custom attrs"
|
|
|
|
|
|
def test_apply_diff_mapping():
|
|
src = {"a": 1}
|
|
dest = {"b": 2}
|
|
apply_diff(src, dest)
|
|
assert dest == src, "Adds and removes keys"
|
|
|
|
src = {"a": 1}
|
|
dest = {"a": MyInt(1)}
|
|
apply_diff(src, dest)
|
|
assert type(dest["a"]) is MyInt, "Does not replace equals"
|
|
|
|
src = {"d": {"a": 1}}
|
|
inner = {}
|
|
dest = {"d": inner}
|
|
apply_diff(src, dest)
|
|
assert dest["d"] is inner, "Updates inner dicts"
|
|
|
|
|
|
def test_apply_diff_seq():
|
|
src = [1]
|
|
dest = [MyInt(1)]
|
|
apply_diff(src, dest)
|
|
assert type(dest[0]) is MyInt, "Does not replace equals"
|
|
|
|
src = {"l": [1]}
|
|
inner = []
|
|
dest = {"l": inner}
|
|
apply_diff(src, dest)
|
|
assert dest["l"] is inner, "Updates inner lists"
|