blob: bb8918f32f3ee21ba3fa835dd0ed1ddd351079f6 [file] [log] [blame]
Roger E. Masse8ba76d31996-12-16 20:20:33 +00001#! /usr/bin/env python
2"""Test the errno module
3 Roger E. Masse
4"""
Roger E. Masse9c6db351996-12-16 20:40:20 +00005
6import errno
Brett Cannonb7ec8e52008-03-18 03:46:22 +00007from test import test_support
8import unittest
Roger E. Masse8ba76d31996-12-16 20:20:33 +00009
Brett Cannonf084e042008-03-18 15:52:00 +000010std_c_errors = frozenset(['EDOM', 'ERANGE'])
Brett Cannonb7ec8e52008-03-18 03:46:22 +000011
12class ErrnoAttributeTests(unittest.TestCase):
13
14 def test_for_improper_attributes(self):
15 # No unexpected attributes should be on the module.
Brett Cannonf084e042008-03-18 15:52:00 +000016 for error_code in std_c_errors:
Benjamin Peterson5c8da862009-06-30 22:57:08 +000017 self.assertTrue(hasattr(errno, error_code),
Brett Cannonf084e042008-03-18 15:52:00 +000018 "errno is missing %s" % error_code)
Brett Cannonb7ec8e52008-03-18 03:46:22 +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.itervalues():
Benjamin Peterson5c8da862009-06-30 22:57:08 +000023 self.assertTrue(hasattr(errno, value), 'no %s attr in errno' % value)
Brett Cannonb7ec8e52008-03-18 03:46:22 +000024
25
26class ErrorcodeTests(unittest.TestCase):
27
28 def test_attributes_in_errorcode(self):
29 for attribute in errno.__dict__.iterkeys():
30 if attribute.isupper():
Ezio Melottiaa980582010-01-23 23:04:36 +000031 self.assertIn(getattr(errno, attribute), errno.errorcode,
32 'no %s attr in errno.errorcode' % attribute)
Brett Cannonb7ec8e52008-03-18 03:46:22 +000033
34
35def test_main():
36 test_support.run_unittest(ErrnoAttributeTests, ErrorcodeTests)
37
38
39if __name__ == '__main__':
40 test_main()