summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_posix.py
diff options
context:
space:
mode:
authorxdegaye <xdegaye@gmail.com>2017-11-12 16:31:07 (GMT)
committerGitHub <noreply@github.com>2017-11-12 16:31:07 (GMT)
commit92c2ca7633c881a56157f2fb8b2e1b8c7114e5fb (patch)
treee2f19b5353b11b39f9f375aaa5e785156b033ada /Lib/test/test_posix.py
parente0582a37c8d1776a2fd4968e9216f3a05f780276 (diff)
downloadcpython-92c2ca7633c881a56157f2fb8b2e1b8c7114e5fb.zip
cpython-92c2ca7633c881a56157f2fb8b2e1b8c7114e5fb.tar.gz
cpython-92c2ca7633c881a56157f2fb8b2e1b8c7114e5fb.tar.bz2
bpo-28759: Skip some tests on PermissionError raised by Android (GH-4350)
Access to mkfifo(), mknod() and hard link creation is controled by SELinux on Android. Also remove test.support.android_not_root.
Diffstat (limited to 'Lib/test/test_posix.py')
-rw-r--r--Lib/test/test_posix.py26
1 files changed, 15 insertions, 11 deletions
diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py
index dba50e0..44b8d6a 100644
--- a/Lib/test/test_posix.py
+++ b/Lib/test/test_posix.py
@@ -2,7 +2,6 @@
from test import support
from test.support.script_helper import assert_python_ok
-android_not_root = support.android_not_root
# Skip these tests if there is no posix module.
posix = support.import_module('posix')
@@ -504,15 +503,16 @@ 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)
+ try:
+ posix.mkfifo(support.TESTFN, stat.S_IRUSR | stat.S_IWUSR)
+ except PermissionError as e:
+ self.skipTest('posix.mkfifo(): %s' % e)
self.assertTrue(stat.S_ISFIFO(posix.stat(support.TESTFN).st_mode))
@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).
@@ -523,7 +523,7 @@ class PosixTester(unittest.TestCase):
except OSError as e:
# Some old systems don't allow unprivileged users to use
# mknod(), or only support creating device nodes.
- self.assertIn(e.errno, (errno.EPERM, errno.EINVAL))
+ self.assertIn(e.errno, (errno.EPERM, errno.EINVAL, errno.EACCES))
else:
self.assertTrue(stat.S_ISFIFO(posix.stat(support.TESTFN).st_mode))
@@ -533,7 +533,7 @@ class PosixTester(unittest.TestCase):
posix.mknod(path=support.TESTFN, mode=mode, device=0,
dir_fd=None)
except OSError as e:
- self.assertIn(e.errno, (errno.EPERM, errno.EINVAL))
+ self.assertIn(e.errno, (errno.EPERM, errno.EINVAL, errno.EACCES))
@unittest.skipUnless(hasattr(posix, 'stat'), 'test needs posix.stat()')
@unittest.skipUnless(hasattr(posix, 'makedev'), 'test needs posix.makedev()')
@@ -1018,11 +1018,13 @@ 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:
posix.link(support.TESTFN, support.TESTFN + 'link', src_dir_fd=f, dst_dir_fd=f)
+ except PermissionError as e:
+ self.skipTest('posix.link(): %s' % e)
+ else:
# should have same inodes
self.assertEqual(posix.stat(support.TESTFN)[1],
posix.stat(support.TESTFN + 'link')[1])
@@ -1042,7 +1044,6 @@ 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).
@@ -1054,7 +1055,7 @@ class PosixTester(unittest.TestCase):
except OSError as e:
# Some old systems don't allow unprivileged users to use
# mknod(), or only support creating device nodes.
- self.assertIn(e.errno, (errno.EPERM, errno.EINVAL))
+ self.assertIn(e.errno, (errno.EPERM, errno.EINVAL, errno.EACCES))
else:
self.assertTrue(stat.S_ISFIFO(posix.stat(support.TESTFN).st_mode))
finally:
@@ -1126,12 +1127,15 @@ 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)
try:
- posix.mkfifo(support.TESTFN, stat.S_IRUSR | stat.S_IWUSR, dir_fd=f)
+ try:
+ posix.mkfifo(support.TESTFN,
+ stat.S_IRUSR | stat.S_IWUSR, dir_fd=f)
+ except PermissionError as e:
+ self.skipTest('posix.mkfifo(): %s' % e)
self.assertTrue(stat.S_ISFIFO(posix.stat(support.TESTFN).st_mode))
finally:
posix.close(f)