tests/functional2: fix bad error message when merging files
The error message used to only contain the last key of the merge failure this commit changes the message to contain the full path to the merge conflict, resolving ambiguity Change-Id: I9848a559b1b888e50a548eef8609bf34506040de
This commit is contained in:
@@ -146,9 +146,13 @@ def merge_file_declaration(a: FileDeclaration, b: FileDeclaration) -> FileDeclar
|
||||
result[key] = a.get(key) or b.get(key)
|
||||
continue
|
||||
if isinstance(a[key], Fileish) or isinstance(b[key], Fileish):
|
||||
msg = "Cannot merge files; got two different values for the same path %s"
|
||||
msg = "Cannot merge files; got two different values for the same path"
|
||||
raise ValueError(msg, key)
|
||||
try:
|
||||
result[key] = merge_file_declaration(a[key], b[key])
|
||||
except ValueError as e:
|
||||
msg, path = e.args
|
||||
raise ValueError(msg, f"{key}/{path}")
|
||||
|
||||
return result
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ from functional2.testlib.fixtures.file_helper import (
|
||||
File,
|
||||
Symlink,
|
||||
AssetSymlink,
|
||||
merge_file_declaration,
|
||||
)
|
||||
|
||||
|
||||
@@ -249,3 +250,39 @@ def test_file_symlink(files: Path):
|
||||
assert link.is_symlink()
|
||||
# check that this is actually relative and not an absolute path
|
||||
assert str(link.readlink()) == "../tg"
|
||||
|
||||
|
||||
def test_merge_fd_merges_correctly():
|
||||
fa = File("a")
|
||||
fc = File("c")
|
||||
fd = File("d")
|
||||
ff = File("f")
|
||||
fd1 = {"a": fa, "b": {"c": fc}}
|
||||
|
||||
fd2 = {"b": {"d": fd}, "e": {"f": ff}}
|
||||
|
||||
expected = {"a": fa, "b": {"c": fc, "d": fd}, "e": {"f": ff}}
|
||||
|
||||
result = merge_file_declaration(fd1, fd2)
|
||||
assert result == expected
|
||||
|
||||
|
||||
def test_merge_fd_throws_on_conflict():
|
||||
fd1 = {"a": {"b": File("b")}}
|
||||
fd2 = {"a": File("a")}
|
||||
|
||||
with pytest.raises(
|
||||
ValueError, match="('Cannot merge files; got two different values for the same path', 'a')"
|
||||
):
|
||||
merge_file_declaration(fd1, fd2)
|
||||
|
||||
|
||||
def test_merge_fd_throws_on_conflict_with_full_path():
|
||||
fd1 = {"a": {"b": {"c": {"d": File("d")}}}}
|
||||
fd2 = {"a": {"b": {"c": {"d": File("different file")}}}}
|
||||
|
||||
with pytest.raises(
|
||||
ValueError,
|
||||
match="('Cannot merge files; got two different values for the same path', 'a/b/c/d')",
|
||||
):
|
||||
merge_file_declaration(fd1, fd2)
|
||||
|
||||
Reference in New Issue
Block a user