blob: 830c24d781303add92b8f810d6bb9bcc2de8f337 [file] [log] [blame]
Benjamin Petersonee8712c2008-05-20 21:35:26 +00001from test import support
Thomas Wouters89f507f2006-12-13 04:49:30 +00002import unittest
Alexandre Vassalottib66c67d2009-07-22 04:27:34 +00003import sys
R. David Murraya21e4ca2009-03-31 23:16:50 +00004
5# Skip test if nis module does not exist.
6nis = support.import_module('nis')
Barry Warsaw3236b331996-12-11 01:01:38 +00007
Benjamin Petersone9ea19e2008-08-19 23:02:38 +00008
Thomas Wouters89f507f2006-12-13 04:49:30 +00009class NisTests(unittest.TestCase):
10 def test_maps(self):
11 try:
12 maps = nis.maps()
Guido van Rossumb940e112007-01-10 16:19:56 +000013 except nis.error as msg:
Thomas Wouters89f507f2006-12-13 04:49:30 +000014 # NIS is probably not active, so this test isn't useful
Benjamin Petersonee8712c2008-05-20 21:35:26 +000015 if support.verbose:
Christian Heimesd5e2b6f2008-03-19 21:50:51 +000016 print("Test Skipped:", msg)
Benjamin Petersone549ead2009-03-28 21:42:05 +000017 # Can't raise SkipTest as regrtest only recognizes the exception
Christian Heimesd5e2b6f2008-03-19 21:50:51 +000018 # import time.
Thomas Wouters89f507f2006-12-13 04:49:30 +000019 return
20 try:
21 # On some systems, this map is only accessible to the
22 # super user
23 maps.remove("passwd.adjunct.byname")
24 except ValueError:
25 pass
Barry Warsaw4c4d5ce1997-05-15 18:27:49 +000026
Thomas Wouters89f507f2006-12-13 04:49:30 +000027 done = 0
28 for nismap in maps:
29 mapping = nis.cat(nismap)
30 for k, v in mapping.items():
31 if not k:
32 continue
33 if nis.match(k, nismap) != v:
34 self.fail("NIS match failed for key `%s' in map `%s'" % (k, nismap))
35 else:
36 # just test the one key, otherwise this test could take a
37 # very long time
38 done = 1
39 break
40 if done:
41 break
42
43def test_main():
Benjamin Petersonee8712c2008-05-20 21:35:26 +000044 support.run_unittest(NisTests)
Thomas Wouters89f507f2006-12-13 04:49:30 +000045
46if __name__ == '__main__':
47 test_main()