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