blob: 2a9f2a801844d4ad865bed194cc8f43a3df77a07 [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
Zachary Ware1f702212013-12-10 14:09:20 -060012 self.skipTest(str(msg))
Georg Brandl850b2be2006-10-29 19:24:43 +000013 try:
14 # On some systems, this map is only accessible to the
15 # super user
16 maps.remove("passwd.adjunct.byname")
17 except ValueError:
18 pass
Barry Warsaw4c4d5ce1997-05-15 18:27:49 +000019
Georg Brandl850b2be2006-10-29 19:24:43 +000020 done = 0
21 for nismap in maps:
22 mapping = nis.cat(nismap)
23 for k, v in mapping.items():
24 if not k:
25 continue
26 if nis.match(k, nismap) != v:
27 self.fail("NIS match failed for key `%s' in map `%s'" % (k, nismap))
28 else:
29 # just test the one key, otherwise this test could take a
30 # very long time
31 done = 1
32 break
33 if done:
34 break
Martin v. Löwise97c7592006-10-22 13:45:13 +000035
Georg Brandl850b2be2006-10-29 19:24:43 +000036def test_main():
Brett Cannon7919d982008-03-19 16:50:13 +000037 test_support.run_unittest(NisTests)
Georg Brandl850b2be2006-10-29 19:24:43 +000038
39if __name__ == '__main__':
40 test_main()