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