blob: 058dcb9a2355d74f0c5db0911cc5151376ddd768 [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
Benjamin Petersonee8712c2008-05-20 21:35:26 +00006from test import support
Christian Heimesb186d002008-03-18 15:15:01 +00007import unittest
Roger E. Masse8ba76d31996-12-16 20:20:33 +00008
Christian Heimesada8c3b2008-03-18 18:26:33 +00009std_c_errors = frozenset(['EDOM', 'ERANGE'])
Christian Heimesb186d002008-03-18 15:15:01 +000010
11class ErrnoAttributeTests(unittest.TestCase):
12
13 def test_for_improper_attributes(self):
14 # No unexpected attributes should be on the module.
Christian Heimesada8c3b2008-03-18 18:26:33 +000015 for error_code in std_c_errors:
Benjamin Petersonc9c0f202009-06-30 23:06:06 +000016 self.assertTrue(hasattr(errno, error_code),
Christian Heimesada8c3b2008-03-18 18:26:33 +000017 "errno is missing %s" % error_code)
Christian Heimesb186d002008-03-18 15:15:01 +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.values():
Barry Warsaw31c604d2010-09-22 20:58:04 +000022 self.assertTrue(hasattr(errno, value),
23 'no %s attr in errno' % value)
Christian Heimesb186d002008-03-18 15:15:01 +000024
25
26class ErrorcodeTests(unittest.TestCase):
27
28 def test_attributes_in_errorcode(self):
29 for attribute in errno.__dict__.keys():
30 if attribute.isupper():
Ezio Melottib58e0bd2010-01-23 15:40:09 +000031 self.assertIn(getattr(errno, attribute), errno.errorcode,
32 'no %s attr in errno.errorcode' % attribute)
Christian Heimesb186d002008-03-18 15:15:01 +000033
34
35def test_main():
Benjamin Petersonee8712c2008-05-20 21:35:26 +000036 support.run_unittest(ErrnoAttributeTests, ErrorcodeTests)
Christian Heimesb186d002008-03-18 15:15:01 +000037
38
39if __name__ == '__main__':
40 test_main()