44
55pwd = support .import_module ('pwd' )
66
7- def _getpwall ():
8- # Android does not have getpwall.
9- if hasattr (pwd , 'getpwall' ):
10- return pwd .getpwall ()
11- elif hasattr (pwd , 'getpwuid' ):
12- return [pwd .getpwuid (0 )]
13- else :
14- return []
15-
7+ @unittest .skipUnless (hasattr (pwd , 'getpwall' ), 'Does not have getpwall()' )
168class PwdTest (unittest .TestCase ):
179
1810 def test_values (self ):
19- entries = _getpwall ()
11+ entries = pwd . getpwall ()
2012
2113 for e in entries :
2214 self .assertEqual (len (e ), 7 )
@@ -42,7 +34,7 @@ def test_values(self):
4234 # and check afterwards (done in test_values_extended)
4335
4436 def test_values_extended (self ):
45- entries = _getpwall ()
37+ entries = pwd . getpwall ()
4638 entriesbyname = {}
4739 entriesbyuid = {}
4840
@@ -66,13 +58,12 @@ def test_errors(self):
6658 self .assertRaises (TypeError , pwd .getpwuid , 3.14 )
6759 self .assertRaises (TypeError , pwd .getpwnam )
6860 self .assertRaises (TypeError , pwd .getpwnam , 42 )
69- if hasattr (pwd , 'getpwall' ):
70- self .assertRaises (TypeError , pwd .getpwall , 42 )
61+ self .assertRaises (TypeError , pwd .getpwall , 42 )
7162
7263 # try to get some errors
7364 bynames = {}
7465 byuids = {}
75- for (n , p , u , g , gecos , d , s ) in _getpwall ():
66+ for (n , p , u , g , gecos , d , s ) in pwd . getpwall ():
7667 bynames [n ] = u
7768 byuids [u ] = n
7869
@@ -106,17 +97,13 @@ def test_errors(self):
10697 # loop, say), pwd.getpwuid() might still be able to find data for that
10798 # uid. Using sys.maxint may provoke the same problems, but hopefully
10899 # it will be a more repeatable failure.
109- # Android accepts a very large span of uids including sys.maxsize and
110- # -1; it raises KeyError with 1 or 2 for example.
111100 fakeuid = sys .maxsize
112101 self .assertNotIn (fakeuid , byuids )
113- if not support .is_android :
114- self .assertRaises (KeyError , pwd .getpwuid , fakeuid )
102+ self .assertRaises (KeyError , pwd .getpwuid , fakeuid )
115103
116104 # -1 shouldn't be a valid uid because it has a special meaning in many
117105 # uid-related functions
118- if not support .is_android :
119- self .assertRaises (KeyError , pwd .getpwuid , - 1 )
106+ self .assertRaises (KeyError , pwd .getpwuid , - 1 )
120107 # should be out of uid_t range
121108 self .assertRaises (KeyError , pwd .getpwuid , 2 ** 128 )
122109 self .assertRaises (KeyError , pwd .getpwuid , - 2 ** 128 )
0 commit comments