From 29a63a8b089ea2d89ce24fcf795f8a775c477e50 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Thu, 4 Apr 2024 11:17:08 +0200 Subject: add method AtLocation.as_emptypath for cloning a location --- tests/test_atlocation.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'tests/test_atlocation.py') diff --git a/tests/test_atlocation.py b/tests/test_atlocation.py index 9836f3b..5d7286a 100644 --- a/tests/test_atlocation.py +++ b/tests/test_atlocation.py @@ -80,7 +80,7 @@ class AtLocationTest(unittest.TestCase): def create_all( self, skip: typing.Container[str] = () ) -> typing.Iterator[tuple[str, typing.ContextManager[AtLocation]]]: - """Create various AtLocation objects referring to fils, directories + """Create various AtLocation objects referring to files, directories and other things in various ways. """ for loctype in ("relative", "absolute", "emptypath", "withfd"): @@ -146,6 +146,24 @@ class AtLocationTest(unittest.TestCase): self.assertEqual(atloc.access(os.R_OK), should_exist) self.assertEqual(atloc.exists(), should_exist) + def test_as_emptypath(self) -> None: + atloc = AtLocation(self.tempdir) + self.assertFalse(atloc.flags & linuxnamespaces.AtFlags.AT_EMPTY_PATH) + statres = atloc.stat() + atloc_ep = self.enterContext(atloc.as_emptypath()) + self.assertTrue(atloc_ep.flags & linuxnamespaces.AtFlags.AT_EMPTY_PATH) + self.assertGreaterEqual(atloc_ep.fd, 0) + self.assertEqual(atloc_ep.location, "") + self.assertEqual(atloc_ep.stat().st_ino, statres.st_ino) + atloc_dup = self.enterContext(atloc_ep.as_emptypath()) + self.assertTrue( + atloc_dup.flags & linuxnamespaces.AtFlags.AT_EMPTY_PATH + ) + self.assertGreaterEqual(atloc_ep.fd, 0) + self.assertNotEqual(atloc_dup.fd, atloc_ep.fd) + self.assertEqual(atloc_dup.location, "") + self.assertEqual(atloc_dup.stat().st_ino, statres.st_ino) + @atloc_subtest(skip=("absent", "file", "symlink")) def test_join_mkdir(self, _: str, atloc: AtLocation) -> None: subdir = atloc / "subdir" -- cgit v1.2.3