Georg Brandl | 850b2be | 2006-10-29 19:24:43 +0000 | [diff] [blame^] | 1 | from test.test_support import verbose, run_unittest |
| 2 | import unittest |
Barry Warsaw | 3236b33 | 1996-12-11 01:01:38 +0000 | [diff] [blame] | 3 | import nis |
| 4 | |
Georg Brandl | 850b2be | 2006-10-29 19:24:43 +0000 | [diff] [blame^] | 5 | class NisTests(unittest.TestCase): |
| 6 | def test_maps(self): |
| 7 | try: |
| 8 | maps = nis.maps() |
| 9 | except nis.error, msg: |
| 10 | # NIS is probably not active, so this test isn't useful |
| 11 | if verbose: |
| 12 | self.fail("(failing because of verbose mode) %s" % msg) |
| 13 | return |
| 14 | try: |
| 15 | # On some systems, this map is only accessible to the |
| 16 | # super user |
| 17 | maps.remove("passwd.adjunct.byname") |
| 18 | except ValueError: |
| 19 | pass |
Barry Warsaw | 4c4d5ce | 1997-05-15 18:27:49 +0000 | [diff] [blame] | 20 | |
Georg Brandl | 850b2be | 2006-10-29 19:24:43 +0000 | [diff] [blame^] | 21 | done = 0 |
| 22 | for nismap in maps: |
| 23 | mapping = nis.cat(nismap) |
| 24 | for k, v in mapping.items(): |
| 25 | if not k: |
| 26 | continue |
| 27 | if nis.match(k, nismap) != v: |
| 28 | self.fail("NIS match failed for key `%s' in map `%s'" % (k, nismap)) |
| 29 | else: |
| 30 | # just test the one key, otherwise this test could take a |
| 31 | # very long time |
| 32 | done = 1 |
| 33 | break |
| 34 | if done: |
| 35 | break |
Martin v. Löwis | e97c759 | 2006-10-22 13:45:13 +0000 | [diff] [blame] | 36 | |
Georg Brandl | 850b2be | 2006-10-29 19:24:43 +0000 | [diff] [blame^] | 37 | def test_main(): |
| 38 | run_unittest(NisTests) |
| 39 | |
| 40 | if __name__ == '__main__': |
| 41 | test_main() |