[elbe-devel] [PATCH 5/6] elbevalidate: path: implement some pathname attributes

Thomas Weißschuh thomas.weissschuh at linutronix.de
Mon May 27 14:12:18 CEST 2024


These mostly just defer to the local posixpath.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
 elbevalidate/path.py              | 28 ++++++++++++++++++++++++++++
 elbevalidate/test_elbevalidate.py |  7 +++++++
 2 files changed, 35 insertions(+)

diff --git a/elbevalidate/path.py b/elbevalidate/path.py
index 0cd2ef9e2015..36b7c4cbc346 100644
--- a/elbevalidate/path.py
+++ b/elbevalidate/path.py
@@ -52,6 +52,34 @@ class _PurePath:
     def __repr__(self):
         return f'{self.__class__.__name__}({str(self)})'
 
+    @property
+    def parts(self):
+        return self._p.parts
+
+    @property
+    def parents(self):
+        return [self._create_from_posixpath(p) for p in self._p.parents]
+
+    @property
+    def parent(self):
+        return self._create_from_posixpath(self._p.parent)
+
+    @property
+    def name(self):
+        return self._p.name
+
+    @property
+    def suffix(self):
+        return self._p.suffix
+
+    @property
+    def suffixes(self):
+        return self._p.suffixes
+
+    @property
+    def stem(self):
+        return self._p.stem
+
 
 @contextlib.contextmanager
 def _guestfs_ctx():
diff --git a/elbevalidate/test_elbevalidate.py b/elbevalidate/test_elbevalidate.py
index 2bc9545e4c47..f34eca5df01d 100644
--- a/elbevalidate/test_elbevalidate.py
+++ b/elbevalidate/test_elbevalidate.py
@@ -108,6 +108,13 @@ def test_elbevalidate(tmp_path):
         assert 'DEVNAME' not in part0_blkid
 
         with part0.files() as root:
+            path = root.joinpath('foo.tar.gz')
+            assert path.suffix == '.gz'
+            assert path.suffixes == ['.tar', '.gz']
+            assert path.stem == 'foo.tar'
+            assert path.parent == root.root
+            assert path.parents == [root.root]
+
             assert root.joinpath('foo').exists()
             assert not root.joinpath('bar').exists()
 

-- 
2.45.1



More information about the elbe-devel mailing list