test_util_path: extend test coverage of join_abs()

Add additional test cases for the `join_abs()` function based on a
suggestion from the PR review.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
This commit is contained in:
Tomáš Hozza 2024-12-30 07:22:46 +01:00 committed by Brian C. Lane
parent 6a4a7c31c6
commit 2f82179268

View file

@ -71,6 +71,7 @@ def test_in_tree():
@pytest.mark.parametrize("test_case", (
# Strings only
{
"args": ("",),
"expected": "/"
@ -99,10 +100,90 @@ def test_in_tree():
"args": ("/", "/foo", "/bar"),
"expected": "/foo/bar"
},
# Path only
{
"args": (Path(""),),
"expected": "/"
},
{
"args": (Path(""), Path("file")),
"expected": "/file"
},
{
"args": (Path(""), Path("/file")),
"expected": "/file"
},
{
"args": (Path("/tmp"), Path("/file")),
"expected": "/tmp/file"
},
{
"args": (Path("/tmp"), Path("/foo"), Path("/bar")),
"expected": "/tmp/foo/bar"
},
{
"args": (Path("/"), Path("/foo")),
"expected": "/foo"
},
{
"args": (Path("/"), Path("/foo"), Path("/bar")),
"expected": "/foo/bar"
},
# Mixed strings and Path
{
"args": (Path("/tmp"), "/foo", "/bar"),
"expected": "/tmp/foo/bar"
},
{
"args": ("/tmp", Path("/foo"), Path("/bar")),
"expected": "/tmp/foo/bar"
},
{
"args": ("/tmp", "/foo", Path("/bar")),
"expected": "/tmp/foo/bar"
},
# Dotted relative paths - strings
{
"args": ("/tmp", "../foo", "/bar"),
"expected": "/foo/bar"
},
{
"args": ("/tmp", "./foo", "/bar"),
"expected": "/tmp/foo/bar"
},
{
"args": ("/tmp", "..", "/bar"),
"expected": "/bar"
},
{
"args": ("..",),
"expected": "/"
},
{
"args": (".",),
"expected": "/"
},
# Dotted relative paths - mixed strings and Path
{
"args": ("/tmp", Path("../foo"), "/bar"),
"expected": "/foo/bar"
},
{
"args": ("/tmp", Path("./foo"), "/bar"),
"expected": "/tmp/foo/bar"
},
{
"args": ("/tmp", Path(".."), "/bar"),
"expected": "/bar"
},
{
"args": (Path(".."),),
"expected": "/"
},
{
"args": (Path("."),),
"expected": "/"
},
))
def test_join_abs(test_case):
assert path.join_abs(*test_case["args"]) == test_case["expected"]