move sections
[python/dscho.git] / Lib / test / test_nis.py
blob8d495505d13370b7b3966894c65063a35dc42ca8
1 from test import test_support
2 import unittest
4 nis = test_support.import_module('nis')
6 class NisTests(unittest.TestCase):
7 def test_maps(self):
8 try:
9 maps = nis.maps()
10 except nis.error, msg:
11 # NIS is probably not active, so this test isn't useful
12 if test_support.verbose:
13 print "Test Skipped:", msg
14 # Can't raise SkipTest as regrtest only recognizes the exception
15 # import time.
16 return
17 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
24 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
40 def test_main():
41 test_support.run_unittest(NisTests)
43 if __name__ == '__main__':
44 test_main()