blob: 8d495505d13370b7b3966894c65063a35dc42ca8 [file] [log] [blame]
Brett Cannon7919d982008-03-19 16:50:13 +00001from test import test_support
Georg Brandl850b2be2006-10-29 19:24:43 +00002import unittest
R. David Murray3db8a342009-03-30 23:05:48 +00003
4nis = test_support.import_module('nis')
Barry Warsaw3236b331996-12-11 01:01:38 +00005
Georg Brandl850b2be2006-10-29 19:24:43 +00006class 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 Cannon7919d982008-03-19 16:50:13 +000012 if test_support.verbose:
13 print "Test Skipped:", msg
Benjamin Peterson888a39b2009-03-26 20:48:25 +000014 # Can't raise SkipTest as regrtest only recognizes the exception
Brett Cannon7919d982008-03-19 16:50:13 +000015 # import time.
Georg Brandl850b2be2006-10-29 19:24:43 +000016 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 Warsaw4c4d5ce1997-05-15 18:27:49 +000023
Georg Brandl850b2be2006-10-29 19:24:43 +000024 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öwise97c7592006-10-22 13:45:13 +000039
Georg Brandl850b2be2006-10-29 19:24:43 +000040def test_main():
Brett Cannon7919d982008-03-19 16:50:13 +000041 test_support.run_unittest(NisTests)
Georg Brandl850b2be2006-10-29 19:24:43 +000042
43if __name__ == '__main__':
44 test_main()