blob: 7a37d3a6a59a09429585e9c551538883752ddc64 [file] [log] [blame]
Roger E. Masse8ba76d31996-12-16 20:20:33 +00001"""Test the errno module
2 Roger E. Masse
3"""
Roger E. Masse9c6db351996-12-16 20:40:20 +00004
5import errno
Brett Cannonb7ec8e52008-03-18 03:46:22 +00006from test import test_support
7import unittest
Roger E. Masse8ba76d31996-12-16 20:20:33 +00008
Brett Cannonf084e042008-03-18 15:52:00 +00009std_c_errors = frozenset(['EDOM', 'ERANGE'])
Brett Cannonb7ec8e52008-03-18 03:46:22 +000010
11class ErrnoAttributeTests(unittest.TestCase):
12
13 def test_for_improper_attributes(self):
14 # No unexpected attributes should be on the module.
Brett Cannonf084e042008-03-18 15:52:00 +000015 for error_code in std_c_errors:
Benjamin Peterson5c8da862009-06-30 22:57:08 +000016 self.assertTrue(hasattr(errno, error_code),
Brett Cannonf084e042008-03-18 15:52:00 +000017 "errno is missing %s" % error_code)
Brett Cannonb7ec8e52008-03-18 03:46:22 +000018
19 def test_using_errorcode(self):
20 # Every key value in errno.errorcode should be on the module.
21 for value in errno.errorcode.itervalues():
Benjamin Peterson5c8da862009-06-30 22:57:08 +000022 self.assertTrue(hasattr(errno, value), 'no %s attr in errno' % value)
Brett Cannonb7ec8e52008-03-18 03:46:22 +000023
24
25class ErrorcodeTests(unittest.TestCase):
26
27 def test_attributes_in_errorcode(self):
28 for attribute in errno.__dict__.iterkeys():
29 if attribute.isupper():
Ezio Melottiaa980582010-01-23 23:04:36 +000030 self.assertIn(getattr(errno, attribute), errno.errorcode,
31 'no %s attr in errno.errorcode' % attribute)
Brett Cannonb7ec8e52008-03-18 03:46:22 +000032
33
34def test_main():
35 test_support.run_unittest(ErrnoAttributeTests, ErrorcodeTests)
36
37
38if __name__ == '__main__':
39 test_main()