test_nis.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. from test import test_support
  2. import unittest
  3. nis = test_support.import_module('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. self.skipTest(str(msg))
  11. try:
  12. # On some systems, this map is only accessible to the
  13. # super user
  14. maps.remove("passwd.adjunct.byname")
  15. except ValueError:
  16. pass
  17. done = 0
  18. for nismap in maps:
  19. mapping = nis.cat(nismap)
  20. for k, v in mapping.items():
  21. if not k:
  22. continue
  23. if nis.match(k, nismap) != v:
  24. self.fail("NIS match failed for key `%s' in map `%s'" % (k, nismap))
  25. else:
  26. # just test the one key, otherwise this test could take a
  27. # very long time
  28. done = 1
  29. break
  30. if done:
  31. break
  32. def test_main():
  33. test_support.run_unittest(NisTests)
  34. if __name__ == '__main__':
  35. test_main()