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