From f59bb9147a53776bc6ea468ba63002f15ed1d8d8 Mon Sep 17 00:00:00 2001 From: Carl Csaposs Date: Tue, 18 Jul 2023 17:35:14 +0000 Subject: [PATCH] Add test_rock_path.py --- tests/unit/test_rock_path.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 tests/unit/test_rock_path.py diff --git a/tests/unit/test_rock_path.py b/tests/unit/test_rock_path.py new file mode 100644 index 000000000..58971c75d --- /dev/null +++ b/tests/unit/test_rock_path.py @@ -0,0 +1,24 @@ +# Copyright 2023 Canonical Ltd. +# See LICENSE file for licensing details. +import functools +import pathlib + +import rock + +_Path = functools.partial(rock._Path, container_=None) + + +def test_path_joining(): + assert _Path("/foo") == _Path("/foo") + assert _Path("/foo") / "bar" == _Path("/foo/bar") + assert "/etc" / _Path("foo") / "bar" == _Path("/etc/foo/bar") + assert "/etc" / _Path("foo") / "bar" / "baz" == _Path("/etc/foo/bar/baz") + assert _Path("/etc", "foo", "bar", "baz") == _Path("/etc/foo/bar/baz") + assert _Path("foo") == _Path("foo") + assert "etc" / _Path("foo") / "bar" / "baz" == _Path("etc/foo/bar/baz") + + +def test_relative_to_container(): + assert _Path("/foo").relative_to_container == pathlib.PurePath("/foo") + assert _Path("/foo/bar").relative_to_container == pathlib.PurePath("/foo/bar") + assert _Path("baz").relative_to_container == pathlib.PurePath("baz")