/Lib/test/test_errno.py

http://unladen-swallow.googlecode.com/ · Python · 40 lines · 22 code · 12 blank · 6 comment · 5 complexity · 022d70400784b6ed34e12c9612231c21 MD5 · raw file

  1. #! /usr/bin/env python
  2. """Test the errno module
  3. Roger E. Masse
  4. """
  5. import errno
  6. from test import test_support
  7. import unittest
  8. std_c_errors = frozenset(['EDOM', 'ERANGE'])
  9. class ErrnoAttributeTests(unittest.TestCase):
  10. def test_for_improper_attributes(self):
  11. # No unexpected attributes should be on the module.
  12. for error_code in std_c_errors:
  13. self.assert_(hasattr(errno, error_code),
  14. "errno is missing %s" % error_code)
  15. def test_using_errorcode(self):
  16. # Every key value in errno.errorcode should be on the module.
  17. for value in errno.errorcode.itervalues():
  18. self.assert_(hasattr(errno, value), 'no %s attr in errno' % value)
  19. class ErrorcodeTests(unittest.TestCase):
  20. def test_attributes_in_errorcode(self):
  21. for attribute in errno.__dict__.iterkeys():
  22. if attribute.isupper():
  23. self.assert_(getattr(errno, attribute) in errno.errorcode,
  24. 'no %s attr in errno.errorcode' % attribute)
  25. def test_main():
  26. test_support.run_unittest(ErrnoAttributeTests, ErrorcodeTests)
  27. if __name__ == '__main__':
  28. test_main()