Home | History | Annotate | Download | only in test
      1 """Test the errno module
      2    Roger E. Masse
      3 """
      4 
      5 import errno
      6 import unittest
      7 
      8 std_c_errors = frozenset(['EDOM', 'ERANGE'])
      9 
     10 class ErrnoAttributeTests(unittest.TestCase):
     11 
     12     def test_for_improper_attributes(self):
     13         # No unexpected attributes should be on the module.
     14         for error_code in std_c_errors:
     15             self.assertTrue(hasattr(errno, error_code),
     16                             "errno is missing %s" % error_code)
     17 
     18     def test_using_errorcode(self):
     19         # Every key value in errno.errorcode should be on the module.
     20         for value in errno.errorcode.values():
     21             self.assertTrue(hasattr(errno, value),
     22                             '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__.keys():
     29             if attribute.isupper():
     30                 self.assertIn(getattr(errno, attribute), errno.errorcode,
     31                               'no %s attr in errno.errorcode' % attribute)
     32 
     33 
     34 if __name__ == '__main__':
     35     unittest.main()
     36