Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_pwd.py @ 5817:48b94de85bf3 legacy-trunk
Extensive changes by AMK.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Thu, 17 Jul 1997 16:29:42 +0000 |
| parents | f1b038758bda |
| children | aedd2d0dcb31 |
| rev | line source |
|---|---|
|
4825
b8a97ad5f7ce
test_rotor.py: New test of the rotor module.
Barry Warsaw <barry@python.org>
parents:
4682
diff
changeset
|
1 from test_support import verbose |
| 4682 | 2 import pwd |
| 3 import string | |
| 4 | |
|
4825
b8a97ad5f7ce
test_rotor.py: New test of the rotor module.
Barry Warsaw <barry@python.org>
parents:
4682
diff
changeset
|
5 print 'pwd.getpwall()' |
| 4682 | 6 entries = pwd.getpwall() |
| 7 | |
| 8 for e in entries: | |
| 9 name = e[0] | |
| 10 uid = e[2] | |
| 11 if verbose: | |
| 12 print name, uid | |
|
4825
b8a97ad5f7ce
test_rotor.py: New test of the rotor module.
Barry Warsaw <barry@python.org>
parents:
4682
diff
changeset
|
13 print 'pwd.getpwuid()' |
| 4682 | 14 dbuid = pwd.getpwuid(uid) |
| 15 if dbuid[0] <> name: | |
| 16 print 'Mismatch in pwd.getpwuid()' | |
|
4825
b8a97ad5f7ce
test_rotor.py: New test of the rotor module.
Barry Warsaw <barry@python.org>
parents:
4682
diff
changeset
|
17 print 'pwd.getpwnam()' |
| 4682 | 18 dbname = pwd.getpwnam(name) |
| 19 if dbname[2] <> uid: | |
| 20 print 'Mismatch in pwd.getpwnam()' | |
|
4825
b8a97ad5f7ce
test_rotor.py: New test of the rotor module.
Barry Warsaw <barry@python.org>
parents:
4682
diff
changeset
|
21 else: |
|
b8a97ad5f7ce
test_rotor.py: New test of the rotor module.
Barry Warsaw <barry@python.org>
parents:
4682
diff
changeset
|
22 print 'name matches uid' |
| 4682 | 23 break |
| 24 | |
| 25 # try to get some errors | |
| 26 bynames = {} | |
| 27 byuids = {} | |
| 28 for n, p, u, g, gecos, d, s in entries: | |
| 29 bynames[n] = u | |
| 30 byuids[u] = n | |
| 31 | |
| 32 allnames = bynames.keys() | |
| 33 namei = 0 | |
| 34 fakename = allnames[namei] | |
| 35 while bynames.has_key(fakename): | |
| 36 chars = map(None, fakename) | |
| 37 for i in range(len(chars)): | |
| 38 if chars[i] == 'z': | |
| 39 chars[i] = 'A' | |
| 40 break | |
| 41 elif chars[i] == 'Z': | |
| 42 continue | |
| 43 else: | |
| 44 chars[i] = chr(ord(chars[i]) + 1) | |
| 45 break | |
| 46 else: | |
| 47 namei = namei + 1 | |
| 48 try: | |
| 49 fakename = allnames[namei] | |
| 50 except IndexError: | |
| 51 # should never happen... if so, just forget it | |
| 52 break | |
| 53 fakename = string.join(map(None, chars), '') | |
| 54 | |
| 55 try: | |
| 56 pwd.getpwnam(fakename) | |
| 57 except KeyError: | |
|
4825
b8a97ad5f7ce
test_rotor.py: New test of the rotor module.
Barry Warsaw <barry@python.org>
parents:
4682
diff
changeset
|
58 print 'caught expected exception' |
| 4682 | 59 else: |
| 60 print 'fakename', fakename, 'did not except pwd.getpwnam()' | |
| 61 | |
|
5562
3f3d2d474aca
More robust way of choosing a non-existant uid (faster, too).
Guido van Rossum <guido@python.org>
parents:
4825
diff
changeset
|
62 # Choose a non-existant uid. |
|
3f3d2d474aca
More robust way of choosing a non-existant uid (faster, too).
Guido van Rossum <guido@python.org>
parents:
4825
diff
changeset
|
63 fakeuid = 4127 |
|
3f3d2d474aca
More robust way of choosing a non-existant uid (faster, too).
Guido van Rossum <guido@python.org>
parents:
4825
diff
changeset
|
64 while byuids.has_key(fakeuid): |
|
5563
f1b038758bda
More robust way of choosing a non-existant uid (faster, too).
Guido van Rossum <guido@python.org>
parents:
5562
diff
changeset
|
65 fakeuid = (fakeuid * 3) % 0x10000 |
| 4682 | 66 |
| 67 try: | |
| 68 pwd.getpwuid(fakeuid) | |
| 69 except KeyError: | |
|
4825
b8a97ad5f7ce
test_rotor.py: New test of the rotor module.
Barry Warsaw <barry@python.org>
parents:
4682
diff
changeset
|
70 print 'caught expected exception' |
| 4682 | 71 else: |
| 72 print 'fakeuid', fakeuid, 'did not except pwd.getpwuid()' |
