blob: 0026953f9ed68f6aa565c7e739ea9f8b5c176382 [file] [log] [blame]
Brett Cannon7919d982008-03-19 16:50:13 +00001from test import test_support
Georg Brandl850b2be2006-10-29 19:24:43 +00002import unittest
Barry Warsaw3236b331996-12-11 01:01:38 +00003import nis
4
Georg Brandl850b2be2006-10-29 19:24:43 +00005class 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
Brett Cannon7919d982008-03-19 16:50:13 +000011 if test_support.verbose:
12 print "Test Skipped:", msg
Benjamin Peterson888a39b2009-03-26 20:48:25 +000013 # Can't raise SkipTest as regrtest only recognizes the exception
Brett Cannon7919d982008-03-19 16:50:13 +000014 # import time.
Georg Brandl850b2be2006-10-29 19:24:43 +000015 return
16 try:
17 # On some systems, this map is only accessible to the
18 # super user
19 maps.remove("passwd.adjunct.byname")
20 except ValueError:
21 pass
Barry Warsaw4c4d5ce1997-05-15 18:27:49 +000022
Georg Brandl850b2be2006-10-29 19:24:43 +000023 done = 0
24 for nismap in maps:
25 mapping = nis.cat(nismap)
26 for k, v in mapping.items():
27 if not k:
28 continue
29 if nis.match(k, nismap) != v:
30 self.fail("NIS match failed for key `%s' in map `%s'" % (k, nismap))
31 else:
32 # just test the one key, otherwise this test could take a
33 # very long time
34 done = 1
35 break
36 if done:
37 break
Martin v. Löwise97c7592006-10-22 13:45:13 +000038
Georg Brandl850b2be2006-10-29 19:24:43 +000039def test_main():
Brett Cannon7919d982008-03-19 16:50:13 +000040 test_support.run_unittest(NisTests)
Georg Brandl850b2be2006-10-29 19:24:43 +000041
42if __name__ == '__main__':
43 test_main()