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 ESC[4;38;5;81mErrnoAttributeTests(ESC[4;38;5;149munittestESC[4;38;5;149m.ESC[4;38;5;149mTestCase):
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 ESC[4;38;5;81mErrorcodeTests(ESC[4;38;5;149munittestESC[4;38;5;149m.ESC[4;38;5;149mTestCase):
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()