Roger E. Masse | 8ba76d3 | 1996-12-16 20:20:33 +0000 | [diff] [blame] | 1 | """Test the errno module |
| 2 | Roger E. Masse |
| 3 | """ |
Roger E. Masse | 9c6db35 | 1996-12-16 20:40:20 +0000 | [diff] [blame] | 4 | |
| 5 | import errno |
Christian Heimes | b186d00 | 2008-03-18 15:15:01 +0000 | [diff] [blame] | 6 | import unittest |
Roger E. Masse | 8ba76d3 | 1996-12-16 20:20:33 +0000 | [diff] [blame] | 7 | |
Christian Heimes | ada8c3b | 2008-03-18 18:26:33 +0000 | [diff] [blame] | 8 | std_c_errors = frozenset(['EDOM', 'ERANGE']) |
Christian Heimes | b186d00 | 2008-03-18 15:15:01 +0000 | [diff] [blame] | 9 | |
| 10 | class ErrnoAttributeTests(unittest.TestCase): |
| 11 | |
| 12 | def test_for_improper_attributes(self): |
| 13 | # No unexpected attributes should be on the module. |
Christian Heimes | ada8c3b | 2008-03-18 18:26:33 +0000 | [diff] [blame] | 14 | for error_code in std_c_errors: |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 15 | self.assertTrue(hasattr(errno, error_code), |
Christian Heimes | ada8c3b | 2008-03-18 18:26:33 +0000 | [diff] [blame] | 16 | "errno is missing %s" % error_code) |
Christian Heimes | b186d00 | 2008-03-18 15:15:01 +0000 | [diff] [blame] | 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(): |
Barry Warsaw | 31c604d | 2010-09-22 20:58:04 +0000 | [diff] [blame] | 21 | self.assertTrue(hasattr(errno, value), |
| 22 | 'no %s attr in errno' % value) |
Christian Heimes | b186d00 | 2008-03-18 15:15:01 +0000 | [diff] [blame] | 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(): |
Ezio Melotti | b58e0bd | 2010-01-23 15:40:09 +0000 | [diff] [blame] | 30 | self.assertIn(getattr(errno, attribute), errno.errorcode, |
| 31 | 'no %s attr in errno.errorcode' % attribute) |
Christian Heimes | b186d00 | 2008-03-18 15:15:01 +0000 | [diff] [blame] | 32 | |
| 33 | |
Christian Heimes | b186d00 | 2008-03-18 15:15:01 +0000 | [diff] [blame] | 34 | if __name__ == '__main__': |
Zachary Ware | 38c707e | 2015-04-13 15:00:43 -0500 | [diff] [blame] | 35 | unittest.main() |