1 from test import support
2 from test.support import import_helper
3 import unittest
4 import warnings
5
6
7 # Skip test if nis module does not exist.
8 with warnings.catch_warnings():
9 warnings.simplefilter("ignore", DeprecationWarning)
10 nis = import_helper.import_module('nis')
11
12
13 class ESC[4;38;5;81mNisTests(ESC[4;38;5;149munittestESC[4;38;5;149m.ESC[4;38;5;149mTestCase):
14 def test_maps(self):
15 try:
16 maps = nis.maps()
17 except nis.error as msg:
18 # NIS is probably not active, so this test isn't useful
19 self.skipTest(str(msg))
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
26
27 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
43 if __name__ == '__main__':
44 unittest.main()