Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 1 | from test import support |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 2 | import unittest |
Alexandre Vassalotti | b66c67d | 2009-07-22 04:27:34 +0000 | [diff] [blame^] | 3 | import sys |
R. David Murray | a21e4ca | 2009-03-31 23:16:50 +0000 | [diff] [blame] | 4 | |
| 5 | # Skip test if nis module does not exist. |
| 6 | nis = support.import_module('nis') |
Barry Warsaw | 3236b33 | 1996-12-11 01:01:38 +0000 | [diff] [blame] | 7 | |
Alexandre Vassalotti | b66c67d | 2009-07-22 04:27:34 +0000 | [diff] [blame^] | 8 | if sys.platform.startswith("sunos"): |
| 9 | raise unittest.SkipTest("test_nis hangs on Solaris") |
Benjamin Peterson | e9ea19e | 2008-08-19 23:02:38 +0000 | [diff] [blame] | 10 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 11 | class NisTests(unittest.TestCase): |
| 12 | def test_maps(self): |
| 13 | try: |
| 14 | maps = nis.maps() |
Guido van Rossum | b940e11 | 2007-01-10 16:19:56 +0000 | [diff] [blame] | 15 | except nis.error as msg: |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 16 | # NIS is probably not active, so this test isn't useful |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 17 | if support.verbose: |
Christian Heimes | d5e2b6f | 2008-03-19 21:50:51 +0000 | [diff] [blame] | 18 | print("Test Skipped:", msg) |
Benjamin Peterson | e549ead | 2009-03-28 21:42:05 +0000 | [diff] [blame] | 19 | # Can't raise SkipTest as regrtest only recognizes the exception |
Christian Heimes | d5e2b6f | 2008-03-19 21:50:51 +0000 | [diff] [blame] | 20 | # import time. |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 21 | return |
| 22 | try: |
| 23 | # On some systems, this map is only accessible to the |
| 24 | # super user |
| 25 | maps.remove("passwd.adjunct.byname") |
| 26 | except ValueError: |
| 27 | pass |
Barry Warsaw | 4c4d5ce | 1997-05-15 18:27:49 +0000 | [diff] [blame] | 28 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 29 | done = 0 |
| 30 | for nismap in maps: |
| 31 | mapping = nis.cat(nismap) |
| 32 | for k, v in mapping.items(): |
| 33 | if not k: |
| 34 | continue |
| 35 | if nis.match(k, nismap) != v: |
| 36 | self.fail("NIS match failed for key `%s' in map `%s'" % (k, nismap)) |
| 37 | else: |
| 38 | # just test the one key, otherwise this test could take a |
| 39 | # very long time |
| 40 | done = 1 |
| 41 | break |
| 42 | if done: |
| 43 | break |
| 44 | |
| 45 | def test_main(): |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 46 | support.run_unittest(NisTests) |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 47 | |
| 48 | if __name__ == '__main__': |
| 49 | test_main() |