/Lib/test/test_nis.py

http://unladen-swallow.googlecode.com/ · Python · 43 lines · 32 code · 4 blank · 7 comment · 12 complexity · 7d258c1d9990c12b84e42ccef4600c9b MD5 · raw file

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