Roger E. Masse | 8ba76d3 | 1996-12-16 20:20:33 +0000 | [diff] [blame] | 1 | #! /usr/bin/env python |
| 2 | """Test the errno module |
| 3 | Roger E. Masse |
| 4 | """ |
Roger E. Masse | 9c6db35 | 1996-12-16 20:40:20 +0000 | [diff] [blame] | 5 | |
| 6 | import errno |
Brett Cannon | b7ec8e5 | 2008-03-18 03:46:22 +0000 | [diff] [blame] | 7 | from test import test_support |
| 8 | import unittest |
Roger E. Masse | 8ba76d3 | 1996-12-16 20:20:33 +0000 | [diff] [blame] | 9 | |
| 10 | errors = ['E2BIG', 'EACCES', 'EADDRINUSE', 'EADDRNOTAVAIL', 'EADV', |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 11 | 'EAFNOSUPPORT', 'EAGAIN', 'EALREADY', 'EBADE', 'EBADF', |
| 12 | 'EBADFD', 'EBADMSG', 'EBADR', 'EBADRQC', 'EBADSLT', |
| 13 | 'EBFONT', 'EBUSY', 'ECHILD', 'ECHRNG', 'ECOMM', |
| 14 | 'ECONNABORTED', 'ECONNREFUSED', 'ECONNRESET', |
Martin v. Löwis | 637f239 | 2008-03-18 12:45:37 +0000 | [diff] [blame] | 15 | 'EDEADLK', 'EDEADLOCK', 'EDESTADDRREQ', 'EDOTDOT', 'EDOM', |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 16 | 'EDQUOT', 'EEXIST', 'EFAULT', 'EFBIG', 'EHOSTDOWN', |
| 17 | 'EHOSTUNREACH', 'EIDRM', 'EILSEQ', 'EINPROGRESS', |
Martin v. Löwis | 637f239 | 2008-03-18 12:45:37 +0000 | [diff] [blame] | 18 | 'EINTR', 'EINVAL', 'EIO', 'EISCONN', 'EISDIR', 'EISNAM', |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 19 | 'EL2HLT', 'EL2NSYNC', 'EL3HLT', 'EL3RST', 'ELIBACC', |
| 20 | 'ELIBBAD', 'ELIBEXEC', 'ELIBMAX', 'ELIBSCN', 'ELNRNG', |
| 21 | 'ELOOP', 'EMFILE', 'EMLINK', 'EMSGSIZE', 'EMULTIHOP', |
Martin v. Löwis | 637f239 | 2008-03-18 12:45:37 +0000 | [diff] [blame] | 22 | 'ENAMETOOLONG', 'ENAVAIL', 'ENETDOWN', 'ENETRESET', 'ENETUNREACH', |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 23 | 'ENFILE', 'ENOANO', 'ENOBUFS', 'ENOCSI', 'ENODATA', |
| 24 | 'ENODEV', 'ENOENT', 'ENOEXEC', 'ENOLCK', 'ENOLINK', |
| 25 | 'ENOMEM', 'ENOMSG', 'ENONET', 'ENOPKG', 'ENOPROTOOPT', |
| 26 | 'ENOSPC', 'ENOSR', 'ENOSTR', 'ENOSYS', 'ENOTBLK', |
Martin v. Löwis | 637f239 | 2008-03-18 12:45:37 +0000 | [diff] [blame] | 27 | 'ENOTCONN', 'ENOTDIR', 'ENOTEMPTY', 'ENOTNAM', 'ENOTOBACCO', 'ENOTSOCK', |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 28 | 'ENOTTY', 'ENOTUNIQ', 'ENXIO', 'EOPNOTSUPP', |
| 29 | 'EOVERFLOW', 'EPERM', 'EPFNOSUPPORT', 'EPIPE', |
| 30 | 'EPROTO', 'EPROTONOSUPPORT', 'EPROTOTYPE', |
Martin v. Löwis | d43ca3b | 2008-03-18 12:20:15 +0000 | [diff] [blame] | 31 | 'ERANGE', 'EREMCHG', 'EREMOTE', 'EREMOTEIO', 'ERESTART', |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 32 | 'EROFS', 'ESHUTDOWN', 'ESOCKTNOSUPPORT', 'ESPIPE', |
| 33 | 'ESRCH', 'ESRMNT', 'ESTALE', 'ESTRPIPE', 'ETIME', |
Martin v. Löwis | 637f239 | 2008-03-18 12:45:37 +0000 | [diff] [blame] | 34 | 'ETIMEDOUT', 'ETOOMANYREFS', 'ETXTBSY', 'EUCLEAN', 'EUNATCH', |
Martin v. Löwis | afb416b | 2008-03-18 13:05:03 +0000 | [diff] [blame] | 35 | 'EUSERS', 'EWOULDBLOCK', 'EXDEV', 'EXFULL', |
| 36 | 'WSABASEERR', 'WSADESCRIPTIO', 'WSAEACCES', 'WSAEADDRINUSE', |
| 37 | 'WSAEADDRNOTAVAIL', 'WSAEAFNOSUPPORT', 'WSAEALREADY', |
| 38 | 'WSAEBADF', 'WSAECONNABORTED', 'WSAECONNREFUSED', |
| 39 | 'WSAECONNRESET', 'WSAEDESTADDRREQ', 'WSAEDISCON', |
| 40 | 'WSAEDQUOT', 'WSAEFAULT', 'WSAEHOSTDOWN', 'WSAEHOSTUNREACH', |
| 41 | 'WSAEINPROGRESS', 'WSAEINTR', 'WSAEINVAL', 'WSAEISCONN', |
| 42 | 'WSAELOOP', 'WSAEMFILE', 'WSAEMSGSIZE', 'WSAENAMETOOLONG', |
| 43 | 'WSAENETDOWN', 'WSAENETRESET', 'WSAENETUNREACH', |
| 44 | 'WSAENOBUFS', 'WSAENOPROTOOPT', 'WSAENOTCONN', |
| 45 | 'WSAENOTEMPTY', 'WSAENOTSOCK', 'WSAEOPNOTSUPP', |
| 46 | 'WSAEPFNOSUPPORT', 'WSAEPROCLIM', 'WSAEPROTONOSUPPORT', |
| 47 | 'WSAEPROTOTYPE', 'WSAEREMOTE', 'WSAESHUTDOWN', |
| 48 | 'WSAESOCKTNOSUPPORT', 'WSAESTALE', 'WSAETIMEDOUT', |
| 49 | 'WSAETOOMANYREFS', 'WSAEUSERS', 'WSAEWOULDBLOCK', |
| 50 | 'WSAGETASYNCBUFLE', 'WSAGETASYNCERRO', 'WSAGETSELECTERRO', |
| 51 | 'WSAGETSELECTEVEN', 'WSAHOS', 'WSAMAKEASYNCREPL', |
| 52 | 'WSAMAKESELECTREPL', 'WSAN', 'WSANOTINITIALISED', 'WSASY', |
| 53 | 'WSASYSNOTREADY', 'WSATR', 'WSAVERNOTSUPPORTED'] |
Roger E. Masse | 8ba76d3 | 1996-12-16 20:20:33 +0000 | [diff] [blame] | 54 | |
Brett Cannon | b7ec8e5 | 2008-03-18 03:46:22 +0000 | [diff] [blame] | 55 | |
| 56 | class ErrnoAttributeTests(unittest.TestCase): |
| 57 | |
| 58 | def test_for_improper_attributes(self): |
| 59 | # No unexpected attributes should be on the module. |
| 60 | errors_set = set(errors) |
| 61 | for attribute in errno.__dict__.iterkeys(): |
| 62 | if attribute.isupper(): |
Brett Cannon | 08811dd | 2008-03-18 05:43:04 +0000 | [diff] [blame] | 63 | self.assert_(attribute in errors_set, |
| 64 | "%s is an unexpected error value" % attribute) |
Brett Cannon | b7ec8e5 | 2008-03-18 03:46:22 +0000 | [diff] [blame] | 65 | |
| 66 | def test_using_errorcode(self): |
| 67 | # Every key value in errno.errorcode should be on the module. |
| 68 | for value in errno.errorcode.itervalues(): |
Neal Norwitz | d1befd7 | 2008-03-18 06:03:46 +0000 | [diff] [blame] | 69 | self.assert_(hasattr(errno, value), 'no %s attr in errno' % value) |
Brett Cannon | b7ec8e5 | 2008-03-18 03:46:22 +0000 | [diff] [blame] | 70 | |
| 71 | |
| 72 | class ErrorcodeTests(unittest.TestCase): |
| 73 | |
| 74 | def test_attributes_in_errorcode(self): |
| 75 | for attribute in errno.__dict__.iterkeys(): |
| 76 | if attribute.isupper(): |
Neal Norwitz | d1befd7 | 2008-03-18 06:03:46 +0000 | [diff] [blame] | 77 | self.assert_(getattr(errno, attribute) in errno.errorcode, |
| 78 | 'no %s attr in errno.errorcode' % attribute) |
Brett Cannon | b7ec8e5 | 2008-03-18 03:46:22 +0000 | [diff] [blame] | 79 | |
| 80 | |
| 81 | def test_main(): |
| 82 | test_support.run_unittest(ErrnoAttributeTests, ErrorcodeTests) |
| 83 | |
| 84 | |
| 85 | if __name__ == '__main__': |
| 86 | test_main() |