1from test import support 2import unittest 3 4# Skip test if nis module does not exist. 5nis = support.import_module('nis') 6 7 8class NisTests(unittest.TestCase): 9 def test_maps(self): 10 try: 11 maps = nis.maps() 12 except nis.error as msg: 13 # NIS is probably not active, so this test isn't useful 14 self.skipTest(str(msg)) 15 try: 16 # On some systems, this map is only accessible to the 17 # super user 18 maps.remove("passwd.adjunct.byname") 19 except ValueError: 20 pass 21 22 done = 0 23 for nismap in maps: 24 mapping = nis.cat(nismap) 25 for k, v in mapping.items(): 26 if not k: 27 continue 28 if nis.match(k, nismap) != v: 29 self.fail("NIS match failed for key `%s' in map `%s'" % (k, nismap)) 30 else: 31 # just test the one key, otherwise this test could take a 32 # very long time 33 done = 1 34 break 35 if done: 36 break 37 38if __name__ == '__main__': 39 unittest.main() 40