Back to index

python3.2  3.2.2
test_errno.py
Go to the documentation of this file.
00001 #! /usr/bin/env python3
00002 """Test the errno module
00003    Roger E. Masse
00004 """
00005 
00006 import errno
00007 from test import support
00008 import unittest
00009 
00010 std_c_errors = frozenset(['EDOM', 'ERANGE'])
00011 
00012 class ErrnoAttributeTests(unittest.TestCase):
00013 
00014     def test_for_improper_attributes(self):
00015         # No unexpected attributes should be on the module.
00016         for error_code in std_c_errors:
00017             self.assertTrue(hasattr(errno, error_code),
00018                             "errno is missing %s" % error_code)
00019 
00020     def test_using_errorcode(self):
00021         # Every key value in errno.errorcode should be on the module.
00022         for value in errno.errorcode.values():
00023             self.assertTrue(hasattr(errno, value),
00024                             'no %s attr in errno' % value)
00025 
00026 
00027 class ErrorcodeTests(unittest.TestCase):
00028 
00029     def test_attributes_in_errorcode(self):
00030         for attribute in errno.__dict__.keys():
00031             if attribute.isupper():
00032                 self.assertIn(getattr(errno, attribute), errno.errorcode,
00033                               'no %s attr in errno.errorcode' % attribute)
00034 
00035 
00036 def test_main():
00037     support.run_unittest(ErrnoAttributeTests, ErrorcodeTests)
00038 
00039 
00040 if __name__ == '__main__':
00041     test_main()