diff options
author | Helmut Grohne <helmut@subdivi.de> | 2024-04-04 11:17:08 +0200 |
---|---|---|
committer | Helmut Grohne <helmut@subdivi.de> | 2024-04-04 11:17:08 +0200 |
commit | 29a63a8b089ea2d89ce24fcf795f8a775c477e50 (patch) | |
tree | c0f128e94b9208ba35c1816f447a67533ccd6931 /tests | |
parent | ccc087a1fe4447ed44d32d1a4ae61f4cf266c5a6 (diff) | |
download | python-linuxnamespaces-29a63a8b089ea2d89ce24fcf795f8a775c477e50.tar.gz |
add method AtLocation.as_emptypath for cloning a location
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_atlocation.py | 20 |
1 files changed, 19 insertions, 1 deletions
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" |