summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier de Gaye <xdegaye@users.sourceforge.net>2016-12-13 08:11:38 (GMT)
committerXavier de Gaye <xdegaye@users.sourceforge.net>2016-12-13 08:11:38 (GMT)
commitfb24eead481a00c9bb86c436461971790fce7937 (patch)
tree87bafc251bfe09ef6f0ba8d75e0fd1a8a8e5a535
parent3432f2f47c1d3d2e97f13d58aef1bc5a72a8976c (diff)
downloadcpython-fb24eead481a00c9bb86c436461971790fce7937.zip
cpython-fb24eead481a00c9bb86c436461971790fce7937.tar.gz
cpython-fb24eead481a00c9bb86c436461971790fce7937.tar.bz2
Issue #26856: Fix the tests assuming that the pwd module has getpwall() and
assuming some invariants about uids that are not valid for Android.
-rw-r--r--Lib/test/test_pathlib.py2
-rw-r--r--Lib/test/test_pwd.py26
2 files changed, 22 insertions, 6 deletions
diff --git a/Lib/test/test_pathlib.py b/Lib/test/test_pathlib.py
index f98c1fe..d25b133 100644
--- a/Lib/test/test_pathlib.py
+++ b/Lib/test/test_pathlib.py
@@ -2080,6 +2080,8 @@ class PosixPathTest(_BasePathTest, unittest.TestCase):
self.assertEqual(given, expect)
self.assertEqual(set(p.rglob("FILEd*")), set())
+ @unittest.skipUnless(hasattr(pwd, 'getpwall'),
+ 'pwd module does not expose getpwall()')
def test_expanduser(self):
P = self.cls
support.import_module('pwd')
diff --git a/Lib/test/test_pwd.py b/Lib/test/test_pwd.py
index b7b1a4a..ac9cff7 100644
--- a/Lib/test/test_pwd.py
+++ b/Lib/test/test_pwd.py
@@ -4,10 +4,19 @@ from test import support
pwd = support.import_module('pwd')
+def _getpwall():
+ # Android does not have getpwall.
+ if hasattr(pwd, 'getpwall'):
+ return pwd.getpwall()
+ elif hasattr(pwd, 'getpwuid'):
+ return [pwd.getpwuid(0)]
+ else:
+ return []
+
class PwdTest(unittest.TestCase):
def test_values(self):
- entries = pwd.getpwall()
+ entries = _getpwall()
for e in entries:
self.assertEqual(len(e), 7)
@@ -33,7 +42,7 @@ class PwdTest(unittest.TestCase):
# and check afterwards (done in test_values_extended)
def test_values_extended(self):
- entries = pwd.getpwall()
+ entries = _getpwall()
entriesbyname = {}
entriesbyuid = {}
@@ -57,12 +66,13 @@ class PwdTest(unittest.TestCase):
self.assertRaises(TypeError, pwd.getpwuid, 3.14)
self.assertRaises(TypeError, pwd.getpwnam)
self.assertRaises(TypeError, pwd.getpwnam, 42)
- self.assertRaises(TypeError, pwd.getpwall, 42)
+ if hasattr(pwd, 'getpwall'):
+ self.assertRaises(TypeError, pwd.getpwall, 42)
# try to get some errors
bynames = {}
byuids = {}
- for (n, p, u, g, gecos, d, s) in pwd.getpwall():
+ for (n, p, u, g, gecos, d, s) in _getpwall():
bynames[n] = u
byuids[u] = n
@@ -96,13 +106,17 @@ class PwdTest(unittest.TestCase):
# loop, say), pwd.getpwuid() might still be able to find data for that
# uid. Using sys.maxint may provoke the same problems, but hopefully
# it will be a more repeatable failure.
+ # Android accepts a very large span of uids including sys.maxsize and
+ # -1; it raises KeyError with 1 or 2 for example.
fakeuid = sys.maxsize
self.assertNotIn(fakeuid, byuids)
- self.assertRaises(KeyError, pwd.getpwuid, fakeuid)
+ if not support.is_android:
+ self.assertRaises(KeyError, pwd.getpwuid, fakeuid)
# -1 shouldn't be a valid uid because it has a special meaning in many
# uid-related functions
- self.assertRaises(KeyError, pwd.getpwuid, -1)
+ if not support.is_android:
+ self.assertRaises(KeyError, pwd.getpwuid, -1)
# should be out of uid_t range
self.assertRaises(KeyError, pwd.getpwuid, 2**128)
self.assertRaises(KeyError, pwd.getpwuid, -2**128)