| 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 ErrnoAttributeTests(unittest.TestCase): |
| 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.assertHasAttr(errno, error_code) |
| 16 |
|
| 17 |
def test_using_errorcode(self): |
| 18 |
# Every key value in errno.errorcode should be on the module. |
| 19 |
for value in errno.errorcode.values(): |
| 20 |
self.assertHasAttr(errno, value) |
| 21 |
|
| 22 |
|
| 23 |
class ErrorcodeTests(unittest.TestCase): |
| 24 |
|
| 25 |
def test_attributes_in_errorcode(self): |
| 26 |
for attribute in errno.__dict__.keys(): |
| 27 |
if attribute.isupper(): |
| 28 |
self.assertIn(getattr(errno, attribute), errno.errorcode, |
| 29 |
'no %s attr in errno.errorcode' % attribute) |
| 30 |
|
| 31 |
|
| 32 |
if __name__ == '__main__': |
| 33 |
unittest.main() |