diff --git a/tests/functional2/testlib/fixtures/file_helper.py b/tests/functional2/testlib/fixtures/file_helper.py index cbab611a5..037ebaae8 100644 --- a/tests/functional2/testlib/fixtures/file_helper.py +++ b/tests/functional2/testlib/fixtures/file_helper.py @@ -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) - result[key] = merge_file_declaration(a[key], b[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 diff --git a/tests/functional2/testlib/fixtures/test_file_helper.py b/tests/functional2/testlib/fixtures/test_file_helper.py index 565f2b16b..f25f4929f 100644 --- a/tests/functional2/testlib/fixtures/test_file_helper.py +++ b/tests/functional2/testlib/fixtures/test_file_helper.py @@ -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)