blob: f414a87796fc8f5dda3867705cff3e532dbfe5c5 [file] [log] [blame]
Benjamin Peterson90f5ba52010-03-11 22:53:45 +00001#! /usr/bin/env python3
Roger E. Masse8ba76d31996-12-16 20:20:33 +00002"""Test the errno module
3 Roger E. Masse
4"""
Roger E. Masse9c6db351996-12-16 20:40:20 +00005
6import errno
Benjamin Petersonee8712c2008-05-20 21:35:26 +00007from test import support
Christian Heimesb186d002008-03-18 15:15:01 +00008import unittest
Roger E. Masse8ba76d31996-12-16 20:20:33 +00009
Christian Heimesada8c3b2008-03-18 18:26:33 +000010std_c_errors = frozenset(['EDOM', 'ERANGE'])
Christian Heimesb186d002008-03-18 15:15:01 +000011
12class ErrnoAttributeTests(unittest.TestCase):
13
14 def test_for_improper_attributes(self):
15 # No unexpected attributes should be on the module.
Christian Heimesada8c3b2008-03-18 18:26:33 +000016 for error_code in std_c_errors:
Benjamin Petersonc9c0f202009-06-30 23:06:06 +000017 self.assertTrue(hasattr(errno, error_code),
Christian Heimesada8c3b2008-03-18 18:26:33 +000018 "errno is missing %s" % error_code)
Christian Heimesb186d002008-03-18 15:15:01 +000019
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 Warsaw31c604d2010-09-22 20:58:04 +000023 self.assertTrue(hasattr(errno, value),
24 'no %s attr in errno' % value)
Christian Heimesb186d002008-03-18 15:15:01 +000025
26
27class ErrorcodeTests(unittest.TestCase):
28
29 def test_attributes_in_errorcode(self):
30 for attribute in errno.__dict__.keys():
31 if attribute.isupper():
Ezio Melottib58e0bd2010-01-23 15:40:09 +000032 self.assertIn(getattr(errno, attribute), errno.errorcode,
33 'no %s attr in errno.errorcode' % attribute)
Christian Heimesb186d002008-03-18 15:15:01 +000034
35
36def test_main():
Benjamin Petersonee8712c2008-05-20 21:35:26 +000037 support.run_unittest(ErrnoAttributeTests, ErrorcodeTests)
Christian Heimesb186d002008-03-18 15:15:01 +000038
39
40if __name__ == '__main__':
41 test_main()