Home | History | Annotate | Download | only in test
      1 from test import test_support
      2 import unittest
      3 
      4 nis = test_support.import_module('nis')
      5 
      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
     23 
     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
     39 
     40 def test_main():
     41     test_support.run_unittest(NisTests)
     42 
     43 if __name__ == '__main__':
     44     test_main()
     45