test_errno.py 1.0 KB

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