test_errno.py 1.1 KB

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