blob: 3f4496563e3f13159f4f5670c871270b1f3e85fc [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
10errors = ['E2BIG', 'EACCES', 'EADDRINUSE', 'EADDRNOTAVAIL', 'EADV',
Guido van Rossum41360a41998-03-26 19:42:58 +000011 'EAFNOSUPPORT', 'EAGAIN', 'EALREADY', 'EBADE', 'EBADF',
12 'EBADFD', 'EBADMSG', 'EBADR', 'EBADRQC', 'EBADSLT',
13 'EBFONT', 'EBUSY', 'ECHILD', 'ECHRNG', 'ECOMM',
14 'ECONNABORTED', 'ECONNREFUSED', 'ECONNRESET',
15 'EDEADLK', 'EDEADLOCK', 'EDESTADDRREQ', 'EDOM',
16 'EDQUOT', 'EEXIST', 'EFAULT', 'EFBIG', 'EHOSTDOWN',
17 'EHOSTUNREACH', 'EIDRM', 'EILSEQ', 'EINPROGRESS',
18 'EINTR', 'EINVAL', 'EIO', 'EISCONN', 'EISDIR',
19 'EL2HLT', 'EL2NSYNC', 'EL3HLT', 'EL3RST', 'ELIBACC',
20 'ELIBBAD', 'ELIBEXEC', 'ELIBMAX', 'ELIBSCN', 'ELNRNG',
21 'ELOOP', 'EMFILE', 'EMLINK', 'EMSGSIZE', 'EMULTIHOP',
22 'ENAMETOOLONG', 'ENETDOWN', 'ENETRESET', 'ENETUNREACH',
23 'ENFILE', 'ENOANO', 'ENOBUFS', 'ENOCSI', 'ENODATA',
24 'ENODEV', 'ENOENT', 'ENOEXEC', 'ENOLCK', 'ENOLINK',
25 'ENOMEM', 'ENOMSG', 'ENONET', 'ENOPKG', 'ENOPROTOOPT',
26 'ENOSPC', 'ENOSR', 'ENOSTR', 'ENOSYS', 'ENOTBLK',
27 'ENOTCONN', 'ENOTDIR', 'ENOTEMPTY', 'ENOTOBACCO', 'ENOTSOCK',
28 'ENOTTY', 'ENOTUNIQ', 'ENXIO', 'EOPNOTSUPP',
29 'EOVERFLOW', 'EPERM', 'EPFNOSUPPORT', 'EPIPE',
30 'EPROTO', 'EPROTONOSUPPORT', 'EPROTOTYPE',
31 'ERANGE', 'EREMCHG', 'EREMOTE', 'ERESTART',
32 'EROFS', 'ESHUTDOWN', 'ESOCKTNOSUPPORT', 'ESPIPE',
33 'ESRCH', 'ESRMNT', 'ESTALE', 'ESTRPIPE', 'ETIME',
34 'ETIMEDOUT', 'ETOOMANYREFS', 'ETXTBSY', 'EUNATCH',
35 'EUSERS', 'EWOULDBLOCK', 'EXDEV', 'EXFULL']
Roger E. Masse8ba76d31996-12-16 20:20:33 +000036
Brett Cannonb7ec8e52008-03-18 03:46:22 +000037
38class ErrnoAttributeTests(unittest.TestCase):
39
40 def test_for_improper_attributes(self):
41 # No unexpected attributes should be on the module.
42 errors_set = set(errors)
43 for attribute in errno.__dict__.iterkeys():
44 if attribute.isupper():
45 self.assert_(attribute in errors_set)
46
47 def test_using_errorcode(self):
48 # Every key value in errno.errorcode should be on the module.
49 for value in errno.errorcode.itervalues():
50 self.assert_(hasattr(errno, value))
51
52
53class ErrorcodeTests(unittest.TestCase):
54
55 def test_attributes_in_errorcode(self):
56 for attribute in errno.__dict__.iterkeys():
57 if attribute.isupper():
58 self.assert_(getattr(errno, attribute) in errno.errorcode)
59
60
61def test_main():
62 test_support.run_unittest(ErrnoAttributeTests, ErrorcodeTests)
63
64
65if __name__ == '__main__':
66 test_main()