home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 June / maximum-cd-2011-06.iso / DiscContents / LibO_3.3.1_Win_x86_install_multi.exe / libreoffice1.cab / test_nis.py < prev    next >
Encoding:
Python Source  |  2011-02-15  |  1.3 KB  |  44 lines

  1. from test import test_support
  2. import unittest
  3. import nis
  4.  
  5. class NisTests(unittest.TestCase):
  6.     def test_maps(self):
  7.         try:
  8.             maps = nis.maps()
  9.         except nis.error, msg:
  10.             # NIS is probably not active, so this test isn't useful
  11.             if test_support.verbose:
  12.                 print "Test Skipped:", msg
  13.             # Can't raise TestSkipped as regrtest only recognizes the exception
  14.             #   import time.
  15.             return
  16.         try:
  17.             # On some systems, this map is only accessible to the
  18.             # super user
  19.             maps.remove("passwd.adjunct.byname")
  20.         except ValueError:
  21.             pass
  22.  
  23.         done = 0
  24.         for nismap in maps:
  25.             mapping = nis.cat(nismap)
  26.             for k, v in mapping.items():
  27.                 if not k:
  28.                     continue
  29.                 if nis.match(k, nismap) != v:
  30.                     self.fail("NIS match failed for key `%s' in map `%s'" % (k, nismap))
  31.                 else:
  32.                     # just test the one key, otherwise this test could take a
  33.                     # very long time
  34.                     done = 1
  35.                     break
  36.             if done:
  37.                 break
  38.  
  39. def test_main():
  40.     test_support.run_unittest(NisTests)
  41.  
  42. if __name__ == '__main__':
  43.     test_main()
  44.