blob: 28425e2057313a8b1fa7ee5461c24584ef366883 [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
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:
17 self.assert_(hasattr(errno, error_code),
18 "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():
23 self.assert_(hasattr(errno, value), 'no %s attr in errno' % value)
24
25
26class ErrorcodeTests(unittest.TestCase):
27
28 def test_attributes_in_errorcode(self):
29 for attribute in errno.__dict__.keys():
30 if attribute.isupper():
31 self.assert_(getattr(errno, attribute) in errno.errorcode,
32 'no %s attr in errno.errorcode' % attribute)
33
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()