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