blob: 5c437e9ccea767ccfd358cbe2567d123e22dcf77 [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
Christian Heimesb186d002008-03-18 15:15:01 +00006import unittest
Roger E. Masse8ba76d31996-12-16 20:20:33 +00007
Christian Heimesada8c3b2008-03-18 18:26:33 +00008std_c_errors = frozenset(['EDOM', 'ERANGE'])
Christian Heimesb186d002008-03-18 15:15:01 +00009
10class ErrnoAttributeTests(unittest.TestCase):
11
12 def test_for_improper_attributes(self):
13 # No unexpected attributes should be on the module.
Christian Heimesada8c3b2008-03-18 18:26:33 +000014 for error_code in std_c_errors:
Benjamin Petersonc9c0f202009-06-30 23:06:06 +000015 self.assertTrue(hasattr(errno, error_code),
Christian Heimesada8c3b2008-03-18 18:26:33 +000016 "errno is missing %s" % error_code)
Christian Heimesb186d002008-03-18 15:15:01 +000017
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 Warsaw31c604d2010-09-22 20:58:04 +000021 self.assertTrue(hasattr(errno, value),
22 'no %s attr in errno' % value)
Christian Heimesb186d002008-03-18 15:15:01 +000023
24
25class ErrorcodeTests(unittest.TestCase):
26
27 def test_attributes_in_errorcode(self):
28 for attribute in errno.__dict__.keys():
29 if attribute.isupper():
Ezio Melottib58e0bd2010-01-23 15:40:09 +000030 self.assertIn(getattr(errno, attribute), errno.errorcode,
31 'no %s attr in errno.errorcode' % attribute)
Christian Heimesb186d002008-03-18 15:15:01 +000032
33
Christian Heimesb186d002008-03-18 15:15:01 +000034if __name__ == '__main__':
Zachary Ware38c707e2015-04-13 15:00:43 -050035 unittest.main()