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