blob: a22142f4069ba92eb4a8ef25e55e96762fb2bca9 [file] [log] [blame]
Benjamin Petersonee8712c2008-05-20 21:35:26 +00001from test import support
Hai Shi883bc632020-07-06 17:12:49 +08002from test.support import import_helper
Thomas Wouters89f507f2006-12-13 04:49:30 +00003import unittest
R. David Murraya21e4ca2009-03-31 23:16:50 +00004
Hai Shi883bc632020-07-06 17:12:49 +08005
R. David Murraya21e4ca2009-03-31 23:16:50 +00006# Skip test if nis module does not exist.
Hai Shi883bc632020-07-06 17:12:49 +08007nis = import_helper.import_module('nis')
Barry Warsaw3236b331996-12-11 01:01:38 +00008
Benjamin Petersone9ea19e2008-08-19 23:02:38 +00009
Thomas Wouters89f507f2006-12-13 04:49:30 +000010class NisTests(unittest.TestCase):
11 def test_maps(self):
12 try:
13 maps = nis.maps()
Guido van Rossumb940e112007-01-10 16:19:56 +000014 except nis.error as msg:
Thomas Wouters89f507f2006-12-13 04:49:30 +000015 # NIS is probably not active, so this test isn't useful
Zachary Ware9fe6d862013-12-08 00:20:35 -060016 self.skipTest(str(msg))
Thomas Wouters89f507f2006-12-13 04:49:30 +000017 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
Thomas Wouters89f507f2006-12-13 04:49:30 +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
39
Thomas Wouters89f507f2006-12-13 04:49:30 +000040if __name__ == '__main__':
Zachary Ware38c707e2015-04-13 15:00:43 -050041 unittest.main()