test_nis.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. from test import support
  2. from test.support import import_helper
  3. import unittest
  4. import warnings
  5. # Skip test if nis module does not exist.
  6. with warnings.catch_warnings():
  7. warnings.simplefilter("ignore", DeprecationWarning)
  8. nis = import_helper.import_module('nis')
  9. class NisTests(unittest.TestCase):
  10. def test_maps(self):
  11. try:
  12. maps = nis.maps()
  13. except nis.error as msg:
  14. # NIS is probably not active, so this test isn't useful
  15. self.skipTest(str(msg))
  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. done = 0
  23. for nismap in maps:
  24. mapping = nis.cat(nismap)
  25. for k, v in mapping.items():
  26. if not k:
  27. continue
  28. if nis.match(k, nismap) != v:
  29. self.fail("NIS match failed for key `%s' in map `%s'" % (k, nismap))
  30. else:
  31. # just test the one key, otherwise this test could take a
  32. # very long time
  33. done = 1
  34. break
  35. if done:
  36. break
  37. if __name__ == '__main__':
  38. unittest.main()