Benjamin Peterson | 90f5ba5 | 2010-03-11 22:53:45 +0000 | [diff] [blame] | 1 | #! /usr/bin/env python3 |
Roger E. Masse | 8ba76d3 | 1996-12-16 20:20:33 +0000 | [diff] [blame] | 2 | """Test the errno module |
| 3 | Roger E. Masse |
| 4 | """ |
Roger E. Masse | 9c6db35 | 1996-12-16 20:40:20 +0000 | [diff] [blame] | 5 | |
| 6 | import errno |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 7 | from test import support |
Christian Heimes | b186d00 | 2008-03-18 15:15:01 +0000 | [diff] [blame] | 8 | import unittest |
Roger E. Masse | 8ba76d3 | 1996-12-16 20:20:33 +0000 | [diff] [blame] | 9 | |
Christian Heimes | ada8c3b | 2008-03-18 18:26:33 +0000 | [diff] [blame] | 10 | std_c_errors = frozenset(['EDOM', 'ERANGE']) |
Christian Heimes | b186d00 | 2008-03-18 15:15:01 +0000 | [diff] [blame] | 11 | |
| 12 | class ErrnoAttributeTests(unittest.TestCase): |
| 13 | |
| 14 | def test_for_improper_attributes(self): |
| 15 | # No unexpected attributes should be on the module. |
Christian Heimes | ada8c3b | 2008-03-18 18:26:33 +0000 | [diff] [blame] | 16 | for error_code in std_c_errors: |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 17 | self.assertTrue(hasattr(errno, error_code), |
Christian Heimes | ada8c3b | 2008-03-18 18:26:33 +0000 | [diff] [blame] | 18 | "errno is missing %s" % error_code) |
Christian Heimes | b186d00 | 2008-03-18 15:15:01 +0000 | [diff] [blame] | 19 | |
| 20 | def test_using_errorcode(self): |
| 21 | # Every key value in errno.errorcode should be on the module. |
| 22 | for value in errno.errorcode.values(): |
Barry Warsaw | 31c604d | 2010-09-22 20:58:04 +0000 | [diff] [blame] | 23 | self.assertTrue(hasattr(errno, value), |
| 24 | 'no %s attr in errno' % value) |
Christian Heimes | b186d00 | 2008-03-18 15:15:01 +0000 | [diff] [blame] | 25 | |
| 26 | |
| 27 | class ErrorcodeTests(unittest.TestCase): |
| 28 | |
| 29 | def test_attributes_in_errorcode(self): |
| 30 | for attribute in errno.__dict__.keys(): |
| 31 | if attribute.isupper(): |
Ezio Melotti | b58e0bd | 2010-01-23 15:40:09 +0000 | [diff] [blame] | 32 | self.assertIn(getattr(errno, attribute), errno.errorcode, |
| 33 | 'no %s attr in errno.errorcode' % attribute) |
Christian Heimes | b186d00 | 2008-03-18 15:15:01 +0000 | [diff] [blame] | 34 | |
| 35 | |
| 36 | def test_main(): |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 37 | support.run_unittest(ErrnoAttributeTests, ErrorcodeTests) |
Christian Heimes | b186d00 | 2008-03-18 15:15:01 +0000 | [diff] [blame] | 38 | |
| 39 | |
| 40 | if __name__ == '__main__': |
| 41 | test_main() |