From bb2540a70ca8864f8c62210872762fc7d0cc3a01 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sat, 6 Aug 2016 23:22:08 +0300 Subject: Issue #26800: Undocumented support of general bytes-like objects as paths in os functions is now deprecated. --- Lib/test/test_posix.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'Lib/test/test_posix.py') diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py index 6a1c82917a..de22513e34 100644 --- a/Lib/test/test_posix.py +++ b/Lib/test/test_posix.py @@ -407,8 +407,10 @@ class PosixTester(unittest.TestCase): def test_stat(self): self.assertTrue(posix.stat(support.TESTFN)) self.assertTrue(posix.stat(os.fsencode(support.TESTFN))) - self.assertTrue(posix.stat(bytearray(os.fsencode(support.TESTFN)))) + self.assertWarnsRegex(DeprecationWarning, + 'should be string, bytes or integer, not', + posix.stat, bytearray(os.fsencode(support.TESTFN))) self.assertRaisesRegex(TypeError, 'should be string, bytes or integer, not', posix.stat, None) -- cgit v1.2.1 From af8fbafe368b5cc4432e47bb0e38fd1e5c119840 Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Fri, 26 Aug 2016 14:44:48 -0700 Subject: Issue #26027, #27524: Add PEP 519/__fspath__() support to os and os.path. Thanks to Jelle Zijlstra for the initial patch against posixmodule.c. --- Lib/test/test_posix.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'Lib/test/test_posix.py') diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py index de22513e34..d2f58baae6 100644 --- a/Lib/test/test_posix.py +++ b/Lib/test/test_posix.py @@ -397,7 +397,7 @@ class PosixTester(unittest.TestCase): self.assertTrue(posix.stat(fp.fileno())) self.assertRaisesRegex(TypeError, - 'should be string, bytes or integer, not', + 'should be string, bytes, os.PathLike or integer, not', posix.stat, float(fp.fileno())) finally: fp.close() @@ -409,16 +409,16 @@ class PosixTester(unittest.TestCase): self.assertTrue(posix.stat(os.fsencode(support.TESTFN))) self.assertWarnsRegex(DeprecationWarning, - 'should be string, bytes or integer, not', + 'should be string, bytes, os.PathLike or integer, not', posix.stat, bytearray(os.fsencode(support.TESTFN))) self.assertRaisesRegex(TypeError, - 'should be string, bytes or integer, not', + 'should be string, bytes, os.PathLike or integer, not', posix.stat, None) self.assertRaisesRegex(TypeError, - 'should be string, bytes or integer, not', + 'should be string, bytes, os.PathLike or integer, not', posix.stat, list(support.TESTFN)) self.assertRaisesRegex(TypeError, - 'should be string, bytes or integer, not', + 'should be string, bytes, os.PathLike or integer, not', posix.stat, list(os.fsencode(support.TESTFN))) @unittest.skipUnless(hasattr(posix, 'mkfifo'), "don't have mkfifo()") -- cgit v1.2.1 From c612b99cfb7dc6e58fa313ed998ec36b3930815c Mon Sep 17 00:00:00 2001 From: Xavier de Gaye Date: Wed, 19 Oct 2016 11:00:26 +0200 Subject: Issue #26944: Fix test_posix for Android where 'id -G' is entirely wrong or missing the effective gid. --- Lib/test/test_posix.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'Lib/test/test_posix.py') diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py index d2f58baae6..63c74cd80d 100644 --- a/Lib/test/test_posix.py +++ b/Lib/test/test_posix.py @@ -799,7 +799,11 @@ class PosixTester(unittest.TestCase): groups = idg.read().strip() ret = idg.close() - if ret is not None or not groups: + try: + idg_groups = set(int(g) for g in groups.split()) + except ValueError: + idg_groups = set() + if ret is not None or not idg_groups: raise unittest.SkipTest("need working 'id -G'") # Issues 16698: OS X ABIs prior to 10.6 have limits on getgroups() @@ -810,12 +814,11 @@ class PosixTester(unittest.TestCase): raise unittest.SkipTest("getgroups(2) is broken prior to 10.6") # 'id -G' and 'os.getgroups()' should return the same - # groups, ignoring order and duplicates. - # #10822 - it is implementation defined whether posix.getgroups() - # includes the effective gid so we include it anyway, since id -G does - self.assertEqual( - set([int(x) for x in groups.split()]), - set(posix.getgroups() + [posix.getegid()])) + # groups, ignoring order, duplicates, and the effective gid. + # #10822/#26944 - It is implementation defined whether + # posix.getgroups() includes the effective gid. + symdiff = idg_groups.symmetric_difference(posix.getgroups()) + self.assertTrue(not symdiff or symdiff == {posix.getegid()}) # tests for the posix *at functions follow -- cgit v1.2.1 From eab15ffef9e7b28b1274aa48f0175efb43547d84 Mon Sep 17 00:00:00 2001 From: Xavier de Gaye Date: Tue, 13 Dec 2016 10:00:01 +0100 Subject: Issue #28759: Fix the tests that fail with PermissionError when run as a non-root user on Android where access rights are controled by SELinux MAC. --- Lib/test/test_posix.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'Lib/test/test_posix.py') diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py index 63c74cd80d..029d0815e9 100644 --- a/Lib/test/test_posix.py +++ b/Lib/test/test_posix.py @@ -1,6 +1,7 @@ "Test posix functions" from test import support +android_not_root = support.android_not_root # Skip these tests if there is no posix module. posix = support.import_module('posix') @@ -422,6 +423,7 @@ class PosixTester(unittest.TestCase): posix.stat, list(os.fsencode(support.TESTFN))) @unittest.skipUnless(hasattr(posix, 'mkfifo'), "don't have mkfifo()") + @unittest.skipIf(android_not_root, "mkfifo not allowed, non root user") def test_mkfifo(self): support.unlink(support.TESTFN) posix.mkfifo(support.TESTFN, stat.S_IRUSR | stat.S_IWUSR) @@ -429,6 +431,7 @@ class PosixTester(unittest.TestCase): @unittest.skipUnless(hasattr(posix, 'mknod') and hasattr(stat, 'S_IFIFO'), "don't have mknod()/S_IFIFO") + @unittest.skipIf(android_not_root, "mknod not allowed, non root user") def test_mknod(self): # Test using mknod() to create a FIFO (the only use specified # by POSIX). @@ -907,6 +910,7 @@ class PosixTester(unittest.TestCase): posix.close(f) @unittest.skipUnless(os.link in os.supports_dir_fd, "test needs dir_fd support in os.link()") + @unittest.skipIf(android_not_root, "hard link not allowed, non root user") def test_link_dir_fd(self): f = posix.open(posix.getcwd(), posix.O_RDONLY) try: @@ -930,6 +934,7 @@ class PosixTester(unittest.TestCase): @unittest.skipUnless((os.mknod in os.supports_dir_fd) and hasattr(stat, 'S_IFIFO'), "test requires both stat.S_IFIFO and dir_fd support for os.mknod()") + @unittest.skipIf(android_not_root, "mknod not allowed, non root user") def test_mknod_dir_fd(self): # Test using mknodat() to create a FIFO (the only use specified # by POSIX). @@ -1013,6 +1018,7 @@ class PosixTester(unittest.TestCase): posix.close(f) @unittest.skipUnless(os.mkfifo in os.supports_dir_fd, "test needs dir_fd support in os.mkfifo()") + @unittest.skipIf(android_not_root, "mkfifo not allowed, non root user") def test_mkfifo_dir_fd(self): support.unlink(support.TESTFN) f = posix.open(posix.getcwd(), posix.O_RDONLY) -- cgit v1.2.1