mirror of https://github.com/python/cpython
00ee7baf49
which unfortunately means the errors from the bytes type change somewhat: bytes([300]) still raises a ValueError, but bytes([10**100]) now raises a TypeError (either that, or bytes(1.0) also raises a ValueError -- PyNumber_AsSsize_t() can only raise one type of exception.) Merged revisions 51188-51433 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r51189 | kurt.kaiser | 2006-08-10 19:11:09 +0200 (Thu, 10 Aug 2006) | 4 lines Retrieval of previous shell command was not always preserving indentation since 1.2a1) Patch 1528468 Tal Einat. ........ r51190 | guido.van.rossum | 2006-08-10 19:41:07 +0200 (Thu, 10 Aug 2006) | 3 lines Chris McDonough's patch to defend against certain DoS attacks on FieldStorage. SF bug #1112549. ........ r51191 | guido.van.rossum | 2006-08-10 19:42:50 +0200 (Thu, 10 Aug 2006) | 2 lines News item for SF bug 1112549. ........ r51192 | guido.van.rossum | 2006-08-10 20:09:25 +0200 (Thu, 10 Aug 2006) | 2 lines Fix title -- it's rc1, not beta3. ........ r51194 | martin.v.loewis | 2006-08-10 21:04:00 +0200 (Thu, 10 Aug 2006) | 3 lines Update dangling references to the 3.2 database to mention that this is UCD 4.1 now. ........ r51195 | tim.peters | 2006-08-11 00:45:34 +0200 (Fri, 11 Aug 2006) | 6 lines Followup to bug #1069160. PyThreadState_SetAsyncExc(): internal correctness changes wrt refcount safety and deadlock avoidance. Also added a basic test case (relying on ctypes) and repaired the docs. ........ r51196 | tim.peters | 2006-08-11 00:48:45 +0200 (Fri, 11 Aug 2006) | 2 lines Whitespace normalization. ........ r51197 | tim.peters | 2006-08-11 01:22:13 +0200 (Fri, 11 Aug 2006) | 5 lines Whitespace normalization broke test_cgi, because a line of quoted test data relied on preserving a single trailing blank. Changed the string from raw to regular, and forced in the trailing blank via an explicit \x20 escape. ........ r51198 | tim.peters | 2006-08-11 02:49:01 +0200 (Fri, 11 Aug 2006) | 10 lines test_PyThreadState_SetAsyncExc(): This is failing on some 64-bit boxes. I have no idea what the ctypes docs mean by "integers", and blind-guessing here that it intended to mean the signed C "int" type, in which case perhaps I can repair this by feeding the thread id argument to type ctypes.c_long(). Also made the worker thread daemonic, so it doesn't hang Python shutdown if the test continues to fail. ........ r51199 | tim.peters | 2006-08-11 05:49:10 +0200 (Fri, 11 Aug 2006) | 6 lines force_test_exit(): This has been completely ineffective at stopping test_signal from hanging forever on the Tru64 buildbot. That could be because there's no such thing as signal.SIGALARM. Changed to the idiotic (but standard) signal.SIGALRM instead, and added some more debug output. ........ r51202 | neal.norwitz | 2006-08-11 08:09:41 +0200 (Fri, 11 Aug 2006) | 6 lines Fix the failures on cygwin (2006-08-10 fixed the actual locking issue). The first hunk changes the colon to an ! like other Windows variants. We need to always wait on the child so the lock gets released and no other tests fail. This is the try/finally in the second hunk. ........ r51205 | georg.brandl | 2006-08-11 09:15:38 +0200 (Fri, 11 Aug 2006) | 3 lines Add Chris McDonough (latest cgi.py patch) ........ r51206 | georg.brandl | 2006-08-11 09:26:10 +0200 (Fri, 11 Aug 2006) | 3 lines logging's atexit hook now runs even if the rest of the module has already been cleaned up. ........ r51212 | thomas.wouters | 2006-08-11 17:02:39 +0200 (Fri, 11 Aug 2006) | 4 lines Add ignore of *.pyc and *.pyo to Lib/xml/etree/. ........ r51215 | thomas.heller | 2006-08-11 21:55:35 +0200 (Fri, 11 Aug 2006) | 7 lines When a ctypes C callback function is called, zero out the result storage before converting the result to C data. See the comment in the code for details. Provide a better context for errors when the conversion of a callback function's result cannot be converted. ........ r51218 | neal.norwitz | 2006-08-12 03:43:40 +0200 (Sat, 12 Aug 2006) | 6 lines Klocwork made another run and found a bunch more problems. This is the first batch of fixes that should be easy to verify based on context. This fixes problem numbers: 220 (ast), 323-324 (symtable), 321-322 (structseq), 215 (array), 210 (hotshot), 182 (codecs), 209 (etree). ........ r51219 | neal.norwitz | 2006-08-12 03:45:47 +0200 (Sat, 12 Aug 2006) | 9 lines Even though _Py_Mangle() isn't truly public anyone can call it and there was no verification that privateobj was a PyString. If it wasn't a string, this could have allowed a NULL pointer to creep in below and crash. I wonder if this should be PyString_CheckExact? Must identifiers be strings or can they be subclasses? Klocwork #275 ........ r51220 | neal.norwitz | 2006-08-12 03:46:42 +0200 (Sat, 12 Aug 2006) | 5 lines It's highly unlikely, though possible for PyEval_Get*() to return NULLs. So be safe and do an XINCREF. Klocwork # 221-222. ........ r51221 | neal.norwitz | 2006-08-12 03:47:59 +0200 (Sat, 12 Aug 2006) | 7 lines This code is actually not used unless WITHOUT_COMPLEX is defined. However, there was no error checking that PyFloat_FromDouble returned a valid pointer. I believe this change is correct as it seemed to follow other code in the area. Klocwork # 292. ........ r51222 | neal.norwitz | 2006-08-12 03:49:12 +0200 (Sat, 12 Aug 2006) | 5 lines Handle NULL nodes while parsing. I'm not entirely sure this is correct. There might be something else that needs to be done to setup the error. Klocwork #295. ........ r51223 | neal.norwitz | 2006-08-12 03:50:38 +0200 (Sat, 12 Aug 2006) | 6 lines If _stat_float_times is false, we will try to INCREF ival which could be NULL. Return early in that case. The caller checks for PyErr_Occurred so this should be ok. Klocwork #297 ........ r51224 | neal.norwitz | 2006-08-12 03:51:12 +0200 (Sat, 12 Aug 2006) | 3 lines Move the assert which checks for a NULL pointer first. Klocwork #274. ........ r51225 | neal.norwitz | 2006-08-12 03:53:28 +0200 (Sat, 12 Aug 2006) | 5 lines Try to handle a malloc failure. I'm not entirely sure this is correct. There might be something else we need to do to handle the exception. Klocwork # 212-213 ........ r51226 | neal.norwitz | 2006-08-12 03:57:47 +0200 (Sat, 12 Aug 2006) | 6 lines I'm not sure why this code allocates this string for the error message. I think it would be better to always use snprintf and have the format limit the size of the name appropriately (like %.200s). Klocwork #340 ........ r51227 | neal.norwitz | 2006-08-12 04:06:34 +0200 (Sat, 12 Aug 2006) | 3 lines Check returned pointer is valid. Klocwork #233 ........ r51228 | neal.norwitz | 2006-08-12 04:12:30 +0200 (Sat, 12 Aug 2006) | 1 line Whoops, how did that get in there. :-) Revert all the parts of 51227 that were not supposed to go it. Only Modules/_ctypes/cfields.c was supposed to be changed ........ r51229 | neal.norwitz | 2006-08-12 04:33:36 +0200 (Sat, 12 Aug 2006) | 4 lines Don't deref v if it's NULL. Klocwork #214 ........ r51230 | neal.norwitz | 2006-08-12 05:16:54 +0200 (Sat, 12 Aug 2006) | 5 lines Check return of PyMem_MALLOC (garbage) is non-NULL. Check seq in both portions of if/else. Klocwork #289-290. ........ r51231 | neal.norwitz | 2006-08-12 05:17:41 +0200 (Sat, 12 Aug 2006) | 4 lines PyModule_GetDict() can fail, produce fatal errors if this happens on startup. Klocwork #298-299. ........ r51232 | neal.norwitz | 2006-08-12 05:18:50 +0200 (Sat, 12 Aug 2006) | 5 lines Verify verdat which is returned from malloc is not NULL. Ensure we don't pass NULL to free. Klocwork #306 (at least the first part, checking malloc) ........ r51233 | tim.peters | 2006-08-12 06:42:47 +0200 (Sat, 12 Aug 2006) | 35 lines test_signal: Signal handling on the Tru64 buildbot appears to be utterly insane. Plug some theoretical insecurities in the test script: - Verify that the SIGALRM handler was actually installed. - Don't call alarm() before the handler is installed. - Move everything that can fail inside the try/finally, so the test cleans up after itself more often. - Try sending all the expected signals in force_test_exit(), not just SIGALRM. Since that was fixed to actually send SIGALRM (instead of invisibly dying with an AttributeError), we've seen that sending SIGALRM alone does not stop this from hanging. - Move the "kill the child" business into the finally clause, so the child doesn't survive test failure to send SIGALRM to other tests later (there are also baffling SIGALRM-related failures in test_socket). - Cancel the alarm in the finally clause -- if the test dies early, we again don't want SIGALRM showing up to confuse a later test. Alas, this still relies on timing luck wrt the spawned script that sends the test signals, but it's hard to see how waiting for seconds can so often be so unlucky. test_threadedsignals: curiously, this test never fails on Tru64, but doesn't normally signal SIGALRM. Anyway, fixed an obvious (but probably inconsequential) logic error. ........ r51234 | tim.peters | 2006-08-12 07:17:41 +0200 (Sat, 12 Aug 2006) | 8 lines Ah, fudge. One of the prints here actually "shouldn't be" protected by "if verbose:", which caused the test to fail on all non-Windows boxes. Note that I deliberately didn't convert this to unittest yet, because I expect it would be even harder to debug this on Tru64 after conversion. ........ r51235 | georg.brandl | 2006-08-12 10:32:02 +0200 (Sat, 12 Aug 2006) | 3 lines Repair logging test spew caused by rev. 51206. ........ r51236 | neal.norwitz | 2006-08-12 19:03:09 +0200 (Sat, 12 Aug 2006) | 8 lines Patch #1538606, Patch to fix __index__() clipping. I modified this patch some by fixing style, some error checking, and adding XXX comments. This patch requires review and some changes are to be expected. I'm checking in now to get the greatest possible review and establish a baseline for moving forward. I don't want this to hold up release if possible. ........ r51238 | neal.norwitz | 2006-08-12 20:44:06 +0200 (Sat, 12 Aug 2006) | 10 lines Fix a couple of bugs exposed by the new __index__ code. The 64-bit buildbots were failing due to inappropriate clipping of numbers larger than 2**31 with new-style classes. (typeobject.c) In reviewing the code for classic classes, there were 2 problems. Any negative value return could be returned. Always return -1 if there was an error. Also make the checks similar with the new-style classes. I believe this is correct for 32 and 64 bit boxes, including Windows64. Add a test of classic classes too. ........ r51240 | neal.norwitz | 2006-08-13 02:20:49 +0200 (Sun, 13 Aug 2006) | 1 line SF bug #1539336, distutils example code missing ........ r51245 | neal.norwitz | 2006-08-13 20:10:10 +0200 (Sun, 13 Aug 2006) | 6 lines Move/copy assert for tstate != NULL before first use. Verify that PyEval_Get{Globals,Locals} returned valid pointers. Klocwork 231-232 ........ r51246 | neal.norwitz | 2006-08-13 20:10:28 +0200 (Sun, 13 Aug 2006) | 5 lines Handle a whole lot of failures from PyString_FromInternedString(). Should fix most of Klocwork 234-272. ........ r51247 | neal.norwitz | 2006-08-13 20:10:47 +0200 (Sun, 13 Aug 2006) | 8 lines cpathname could be NULL if it was longer than MAXPATHLEN. Don't try to write the .pyc to NULL. Check results of PyList_GetItem() and PyModule_GetDict() are not NULL. Klocwork 282, 283, 285 ........ r51248 | neal.norwitz | 2006-08-13 20:11:08 +0200 (Sun, 13 Aug 2006) | 6 lines Fix segfault when doing string formatting on subclasses of long if __oct__, __hex__ don't return a string. Klocwork 308 ........ r51250 | neal.norwitz | 2006-08-13 20:11:27 +0200 (Sun, 13 Aug 2006) | 5 lines Check return result of PyModule_GetDict(). Fix a bunch of refleaks in the init of the module. This would only be found when running python -v. ........ r51251 | neal.norwitz | 2006-08-13 20:11:43 +0200 (Sun, 13 Aug 2006) | 5 lines Handle malloc and fopen failures more gracefully. Klocwork 180-181 ........ r51252 | neal.norwitz | 2006-08-13 20:12:03 +0200 (Sun, 13 Aug 2006) | 7 lines It's very unlikely, though possible that source is not a string. Verify that PyString_AsString() returns a valid pointer. (The problem can arise when zlib.decompress doesn't return a string.) Klocwork 346 ........ r51253 | neal.norwitz | 2006-08-13 20:12:26 +0200 (Sun, 13 Aug 2006) | 5 lines Handle failures from lookup. Klocwork 341-342 ........ r51254 | neal.norwitz | 2006-08-13 20:12:45 +0200 (Sun, 13 Aug 2006) | 6 lines Handle failure from PyModule_GetDict() (Klocwork 208). Fix a bunch of refleaks in the init of the module. This would only be found when running python -v. ........ r51255 | neal.norwitz | 2006-08-13 20:13:02 +0200 (Sun, 13 Aug 2006) | 4 lines Really address the issue of where to place the assert for leftblock. (Followup of Klocwork 274) ........ r51256 | neal.norwitz | 2006-08-13 20:13:36 +0200 (Sun, 13 Aug 2006) | 4 lines Handle malloc failure. Klocwork 281 ........ r51258 | neal.norwitz | 2006-08-13 20:40:39 +0200 (Sun, 13 Aug 2006) | 4 lines Handle alloca failures. Klocwork 225-228 ........ r51259 | neal.norwitz | 2006-08-13 20:41:15 +0200 (Sun, 13 Aug 2006) | 1 line Get rid of compiler warning ........ r51261 | neal.norwitz | 2006-08-14 02:51:15 +0200 (Mon, 14 Aug 2006) | 1 line Ignore pgen.exe and kill_python.exe for cygwin ........ r51262 | neal.norwitz | 2006-08-14 02:59:03 +0200 (Mon, 14 Aug 2006) | 4 lines Can't return NULL from a void function. If there is a memory error, about the best we can do is call PyErr_WriteUnraisable and go on. We won't be able to do the call below either, so verify delstr is valid. ........ r51263 | neal.norwitz | 2006-08-14 03:49:54 +0200 (Mon, 14 Aug 2006) | 1 line Update purify doc some. ........ r51264 | thomas.heller | 2006-08-14 09:13:05 +0200 (Mon, 14 Aug 2006) | 2 lines Remove unused, buggy test function. Fixes klockwork issue #207. ........ r51265 | thomas.heller | 2006-08-14 09:14:09 +0200 (Mon, 14 Aug 2006) | 2 lines Check for NULL return value from new_CArgObject(). Fixes klockwork issues #183, #184, #185. ........ r51266 | thomas.heller | 2006-08-14 09:50:14 +0200 (Mon, 14 Aug 2006) | 2 lines Check for NULL return value of GenericCData_new(). Fixes klockwork issues #188, #189. ........ r51274 | thomas.heller | 2006-08-14 12:02:24 +0200 (Mon, 14 Aug 2006) | 2 lines Revert the change that tries to zero out a closure's result storage area because the size if unknown in source/callproc.c. ........ r51276 | marc-andre.lemburg | 2006-08-14 12:55:19 +0200 (Mon, 14 Aug 2006) | 11 lines Slightly revised version of patch #1538956: Replace UnicodeDecodeErrors raised during == and != compares of Unicode and other objects with a new UnicodeWarning. All other comparisons continue to raise exceptions. Exceptions other than UnicodeDecodeErrors are also left untouched. ........ r51277 | thomas.heller | 2006-08-14 13:17:48 +0200 (Mon, 14 Aug 2006) | 13 lines Apply the patch #1532975 plus ideas from the patch #1533481. ctypes instances no longer have the internal and undocumented '_as_parameter_' attribute which was used to adapt them to foreign function calls; this mechanism is replaced by a function pointer in the type's stgdict. In the 'from_param' class methods, try the _as_parameter_ attribute if other conversions are not possible. This makes the documented _as_parameter_ mechanism work as intended. Change the ctypes version number to 1.0.1. ........ r51278 | marc-andre.lemburg | 2006-08-14 13:44:34 +0200 (Mon, 14 Aug 2006) | 3 lines Readd NEWS items that were accidentally removed by r51276. ........ r51279 | georg.brandl | 2006-08-14 14:36:06 +0200 (Mon, 14 Aug 2006) | 3 lines Improve markup in PyUnicode_RichCompare. ........ r51280 | marc-andre.lemburg | 2006-08-14 14:57:27 +0200 (Mon, 14 Aug 2006) | 3 lines Correct an accidentally removed previous patch. ........ r51281 | thomas.heller | 2006-08-14 18:17:41 +0200 (Mon, 14 Aug 2006) | 3 lines Patch #1536908: Add support for AMD64 / OpenBSD. Remove the -no-stack-protector compiler flag for OpenBSD as it has been reported to be unneeded. ........ r51282 | thomas.heller | 2006-08-14 18:20:04 +0200 (Mon, 14 Aug 2006) | 1 line News item for rev 51281. ........ r51283 | georg.brandl | 2006-08-14 22:25:39 +0200 (Mon, 14 Aug 2006) | 3 lines Fix refleak introduced in rev. 51248. ........ r51284 | georg.brandl | 2006-08-14 23:34:08 +0200 (Mon, 14 Aug 2006) | 5 lines Make tabnanny recognize IndentationErrors raised by tokenize. Add a test to test_inspect to make sure indented source is recognized correctly. (fixes #1224621) ........ r51285 | georg.brandl | 2006-08-14 23:42:55 +0200 (Mon, 14 Aug 2006) | 3 lines Patch #1535500: fix segfault in BZ2File.writelines and make sure it raises the correct exceptions. ........ r51287 | georg.brandl | 2006-08-14 23:45:32 +0200 (Mon, 14 Aug 2006) | 3 lines Add an additional test: BZ2File write methods should raise IOError when file is read-only. ........ r51289 | georg.brandl | 2006-08-14 23:55:28 +0200 (Mon, 14 Aug 2006) | 3 lines Patch #1536071: trace.py should now find the full module name of a file correctly even on Windows. ........ r51290 | georg.brandl | 2006-08-15 00:01:24 +0200 (Tue, 15 Aug 2006) | 3 lines Cookie.py shouldn't "bogusly" use string._idmap. ........ r51291 | georg.brandl | 2006-08-15 00:10:24 +0200 (Tue, 15 Aug 2006) | 3 lines Patch #1511317: don't crash on invalid hostname info ........ r51292 | tim.peters | 2006-08-15 02:25:04 +0200 (Tue, 15 Aug 2006) | 2 lines Whitespace normalization. ........ r51293 | neal.norwitz | 2006-08-15 06:14:57 +0200 (Tue, 15 Aug 2006) | 3 lines Georg fixed one of my bugs, so I'll repay him with 2 NEWS entries. Now we're even. :-) ........ r51295 | neal.norwitz | 2006-08-15 06:58:28 +0200 (Tue, 15 Aug 2006) | 8 lines Fix the test for SocketServer so it should pass on cygwin and not fail sporadically on other platforms. This is really a band-aid that doesn't fix the underlying issue in SocketServer. It's not clear if it's worth it to fix SocketServer, however, I opened a bug to track it: http://python.org/sf/1540386 ........ r51296 | neal.norwitz | 2006-08-15 06:59:30 +0200 (Tue, 15 Aug 2006) | 3 lines Update the docstring to use a version a little newer than 1999. This was taken from a Debian patch. Should we update the version for each release? ........ r51298 | neal.norwitz | 2006-08-15 08:29:03 +0200 (Tue, 15 Aug 2006) | 2 lines Subclasses of int/long are allowed to define an __index__. ........ r51300 | thomas.heller | 2006-08-15 15:07:21 +0200 (Tue, 15 Aug 2006) | 1 line Check for NULL return value from new_CArgObject calls. ........ r51303 | kurt.kaiser | 2006-08-16 05:15:26 +0200 (Wed, 16 Aug 2006) | 2 lines The 'with' statement is now a Code Context block opener ........ r51304 | anthony.baxter | 2006-08-16 05:42:26 +0200 (Wed, 16 Aug 2006) | 1 line preparing for 2.5c1 ........ r51305 | anthony.baxter | 2006-08-16 05:58:37 +0200 (Wed, 16 Aug 2006) | 1 line preparing for 2.5c1 - no, really this time ........ r51306 | kurt.kaiser | 2006-08-16 07:01:42 +0200 (Wed, 16 Aug 2006) | 9 lines Patch #1540892: site.py Quitter() class attempts to close sys.stdin before raising SystemExit, allowing IDLE to honor quit() and exit(). M Lib/site.py M Lib/idlelib/PyShell.py M Lib/idlelib/CREDITS.txt M Lib/idlelib/NEWS.txt M Misc/NEWS ........ r51307 | ka-ping.yee | 2006-08-16 09:02:50 +0200 (Wed, 16 Aug 2006) | 6 lines Update code and tests to support the 'bytes_le' attribute (for little-endian byte order on Windows), and to work around clocks with low resolution yielding duplicate UUIDs. Anthony Baxter has approved this change. ........ r51308 | kurt.kaiser | 2006-08-16 09:04:17 +0200 (Wed, 16 Aug 2006) | 2 lines Get quit() and exit() to work cleanly when not using subprocess. ........ r51309 | marc-andre.lemburg | 2006-08-16 10:13:26 +0200 (Wed, 16 Aug 2006) | 2 lines Revert to having static version numbers again. ........ r51310 | martin.v.loewis | 2006-08-16 14:55:10 +0200 (Wed, 16 Aug 2006) | 2 lines Build _hashlib on Windows. Build OpenSSL with masm assembler code. Fixes #1535502. ........ r51311 | thomas.heller | 2006-08-16 15:03:11 +0200 (Wed, 16 Aug 2006) | 6 lines Add commented assert statements to check that the result of PyObject_stgdict() and PyType_stgdict() calls are non-NULL before dereferencing the result. Hopefully this fixes what klocwork is complaining about. Fix a few other nits as well. ........ r51312 | anthony.baxter | 2006-08-16 15:08:25 +0200 (Wed, 16 Aug 2006) | 1 line news entry for 51307 ........ r51313 | andrew.kuchling | 2006-08-16 15:22:20 +0200 (Wed, 16 Aug 2006) | 1 line Add UnicodeWarning ........ r51314 | andrew.kuchling | 2006-08-16 15:41:52 +0200 (Wed, 16 Aug 2006) | 1 line Bump document version to 1.0; remove pystone paragraph ........ r51315 | andrew.kuchling | 2006-08-16 15:51:32 +0200 (Wed, 16 Aug 2006) | 1 line Link to docs; remove an XXX comment ........ r51316 | martin.v.loewis | 2006-08-16 15:58:51 +0200 (Wed, 16 Aug 2006) | 1 line Make cl build step compile-only (/c). Remove libs from source list. ........ r51317 | thomas.heller | 2006-08-16 16:07:44 +0200 (Wed, 16 Aug 2006) | 5 lines The __repr__ method of a NULL py_object does no longer raise an exception. Remove a stray '?' character from the exception text when the value is retrieved of such an object. Includes tests. ........ r51318 | andrew.kuchling | 2006-08-16 16:18:23 +0200 (Wed, 16 Aug 2006) | 1 line Update bug/patch counts ........ r51319 | andrew.kuchling | 2006-08-16 16:21:14 +0200 (Wed, 16 Aug 2006) | 1 line Wording/typo fixes ........ r51320 | thomas.heller | 2006-08-16 17:10:12 +0200 (Wed, 16 Aug 2006) | 9 lines Remove the special casing of Py_None when converting the return value of the Python part of a callback function to C. If it cannot be converted, call PyErr_WriteUnraisable with the exception we got. Before, arbitrary data has been passed to the calling C code in this case. (I'm not really sure the NEWS entry is understandable, but I cannot find better words) ........ r51321 | marc-andre.lemburg | 2006-08-16 18:11:01 +0200 (Wed, 16 Aug 2006) | 2 lines Add NEWS item mentioning the reverted distutils version number patch. ........ r51322 | fredrik.lundh | 2006-08-16 18:47:07 +0200 (Wed, 16 Aug 2006) | 5 lines SF#1534630 ignore data that arrives before the opening start tag ........ r51324 | andrew.kuchling | 2006-08-16 19:11:18 +0200 (Wed, 16 Aug 2006) | 1 line Grammar fix ........ r51328 | thomas.heller | 2006-08-16 20:02:11 +0200 (Wed, 16 Aug 2006) | 12 lines Tutorial: Clarify somewhat how parameters are passed to functions (especially explain what integer means). Correct the table - Python integers and longs can both be used. Further clarification to the table comparing ctypes types, Python types, and C types. Reference: Replace integer by C ``int`` where it makes sense. ........ r51329 | kurt.kaiser | 2006-08-16 23:45:59 +0200 (Wed, 16 Aug 2006) | 8 lines File menu hotkeys: there were three 'p' assignments. Reassign the 'Save Copy As' and 'Print' hotkeys to 'y' and 't'. Change the Shell menu hotkey from 's' to 'l'. M Bindings.py M PyShell.py M NEWS.txt ........ r51330 | neil.schemenauer | 2006-08-17 01:38:05 +0200 (Thu, 17 Aug 2006) | 3 lines Fix a bug in the ``compiler`` package that caused invalid code to be generated for generator expressions. ........ r51342 | martin.v.loewis | 2006-08-17 21:19:32 +0200 (Thu, 17 Aug 2006) | 3 lines Merge 51340 and 51341 from 2.5 branch: Leave tk build directory to restore original path. Invoke debug mk1mf.pl after running Configure. ........ r51354 | martin.v.loewis | 2006-08-18 05:47:18 +0200 (Fri, 18 Aug 2006) | 3 lines Bug #1541863: uuid.uuid1 failed to generate unique identifiers on systems with low clock resolution. ........ r51355 | neal.norwitz | 2006-08-18 05:57:54 +0200 (Fri, 18 Aug 2006) | 1 line Add template for 2.6 on HEAD ........ r51356 | neal.norwitz | 2006-08-18 06:01:38 +0200 (Fri, 18 Aug 2006) | 1 line More post-release wibble ........ r51357 | neal.norwitz | 2006-08-18 06:58:33 +0200 (Fri, 18 Aug 2006) | 1 line Try to get Windows bots working again ........ r51358 | neal.norwitz | 2006-08-18 07:10:00 +0200 (Fri, 18 Aug 2006) | 1 line Try to get Windows bots working again. Take 2 ........ r51359 | neal.norwitz | 2006-08-18 07:39:20 +0200 (Fri, 18 Aug 2006) | 1 line Try to get Unix bots install working again. ........ r51360 | neal.norwitz | 2006-08-18 07:41:46 +0200 (Fri, 18 Aug 2006) | 1 line Set version to 2.6a0, seems more consistent. ........ r51362 | neal.norwitz | 2006-08-18 08:14:52 +0200 (Fri, 18 Aug 2006) | 1 line More version wibble ........ r51364 | georg.brandl | 2006-08-18 09:27:59 +0200 (Fri, 18 Aug 2006) | 4 lines Bug #1541682: Fix example in the "Refcount details" API docs. Additionally, remove a faulty example showing PySequence_SetItem applied to a newly created list object and add notes that this isn't a good idea. ........ r51366 | anthony.baxter | 2006-08-18 09:29:02 +0200 (Fri, 18 Aug 2006) | 3 lines Updating IDLE's version number to match Python's (as per python-dev discussion). ........ r51367 | anthony.baxter | 2006-08-18 09:30:07 +0200 (Fri, 18 Aug 2006) | 1 line RPM specfile updates ........ r51368 | georg.brandl | 2006-08-18 09:35:47 +0200 (Fri, 18 Aug 2006) | 2 lines Typo in tp_clear docs. ........ r51378 | andrew.kuchling | 2006-08-18 15:57:13 +0200 (Fri, 18 Aug 2006) | 1 line Minor edits ........ r51379 | thomas.heller | 2006-08-18 16:38:46 +0200 (Fri, 18 Aug 2006) | 6 lines Add asserts to check for 'impossible' NULL values, with comments. In one place where I'n not 1000% sure about the non-NULL, raise a RuntimeError for safety. This should fix the klocwork issues that Neal sent me. If so, it should be applied to the release25-maint branch also. ........ r51400 | neal.norwitz | 2006-08-19 06:22:33 +0200 (Sat, 19 Aug 2006) | 5 lines Move initialization of interned strings to before allocating the object so we don't leak op. (Fixes an earlier patch to this code) Klockwork #350 ........ r51401 | neal.norwitz | 2006-08-19 06:23:04 +0200 (Sat, 19 Aug 2006) | 4 lines Move assert to after NULL check, otherwise we deref NULL in the assert. Klocwork #307 ........ r51402 | neal.norwitz | 2006-08-19 06:25:29 +0200 (Sat, 19 Aug 2006) | 2 lines SF #1542693: Remove semi-colon at end of PyImport_ImportModuleEx macro ........ r51403 | neal.norwitz | 2006-08-19 06:28:55 +0200 (Sat, 19 Aug 2006) | 6 lines Move initialization to after the asserts for non-NULL values. Klocwork 286-287. (I'm not backporting this, but if someone wants to, feel free.) ........ r51404 | neal.norwitz | 2006-08-19 06:52:03 +0200 (Sat, 19 Aug 2006) | 6 lines Handle PyString_FromInternedString() failing (unlikely, but possible). Klocwork #325 (I'm not backporting this, but if someone wants to, feel free.) ........ r51416 | georg.brandl | 2006-08-20 15:15:39 +0200 (Sun, 20 Aug 2006) | 2 lines Patch #1542948: fix urllib2 header casing issue. With new test. ........ r51428 | jeremy.hylton | 2006-08-21 18:19:37 +0200 (Mon, 21 Aug 2006) | 3 lines Move peephole optimizer to separate file. ........ r51429 | jeremy.hylton | 2006-08-21 18:20:29 +0200 (Mon, 21 Aug 2006) | 2 lines Move peephole optimizer to separate file. (Forgot .h in previous checkin.) ........ r51432 | neal.norwitz | 2006-08-21 19:59:46 +0200 (Mon, 21 Aug 2006) | 5 lines Fix bug #1543303, tarfile adds padding that breaks gunzip. Patch # 1543897. Will backport to 2.5 ........ r51433 | neal.norwitz | 2006-08-21 20:01:30 +0200 (Mon, 21 Aug 2006) | 2 lines Add assert to make Klocwork happy (#276) ........ |
||
---|---|---|
.. | ||
crashers | ||
decimaltestdata | ||
leakers | ||
output | ||
185test.db | ||
README | ||
__init__.py | ||
audiotest.au | ||
autotest.py | ||
bad_coding.py | ||
bad_coding2.py | ||
badsyntax_future3.py | ||
badsyntax_future4.py | ||
badsyntax_future5.py | ||
badsyntax_future6.py | ||
badsyntax_future7.py | ||
badsyntax_future8.py | ||
badsyntax_future9.py | ||
badsyntax_nocaret.py | ||
cfgparser.1 | ||
check_soundcard.vbs | ||
cjkencodings_test.py | ||
doctest_aliases.py | ||
double_const.py | ||
empty.vbs | ||
exception_hierarchy.txt | ||
fork_wait.py | ||
greyrgb.uue | ||
inspect_fodder.py | ||
inspect_fodder2.py | ||
list_tests.py | ||
mapping_tests.py | ||
outstanding_bugs.py | ||
pickletester.py | ||
pyclbr_input.py | ||
pydocfodder.py | ||
pystone.py | ||
re_tests.py | ||
regex_tests.py | ||
regrtest.py | ||
reperf.py | ||
sample_doctest.py | ||
seq_tests.py | ||
sortperf.py | ||
string_tests.py | ||
test.xml | ||
test.xml.out | ||
test_MimeWriter.py | ||
test_StringIO.py | ||
test___all__.py | ||
test___future__.py | ||
test__locale.py | ||
test_aepack.py | ||
test_al.py | ||
test_anydbm.py | ||
test_applesingle.py | ||
test_array.py | ||
test_ast.py | ||
test_asynchat.py | ||
test_atexit.py | ||
test_audioop.py | ||
test_augassign.py | ||
test_base64.py | ||
test_bastion.py | ||
test_bigaddrspace.py | ||
test_bigmem.py | ||
test_binascii.py | ||
test_binhex.py | ||
test_binop.py | ||
test_bisect.py | ||
test_bool.py | ||
test_bsddb.py | ||
test_bsddb3.py | ||
test_bsddb185.py | ||
test_bufio.py | ||
test_builtin.py | ||
test_bytes.py | ||
test_bz2.py | ||
test_cProfile.py | ||
test_calendar.py | ||
test_call.py | ||
test_capi.py | ||
test_cd.py | ||
test_cfgparser.py | ||
test_cgi.py | ||
test_charmapcodec.py | ||
test_cl.py | ||
test_class.py | ||
test_cmath.py | ||
test_cmd_line.py | ||
test_code.py | ||
test_codeccallbacks.py | ||
test_codecencodings_cn.py | ||
test_codecencodings_hk.py | ||
test_codecencodings_jp.py | ||
test_codecencodings_kr.py | ||
test_codecencodings_tw.py | ||
test_codecmaps_cn.py | ||
test_codecmaps_hk.py | ||
test_codecmaps_jp.py | ||
test_codecmaps_kr.py | ||
test_codecmaps_tw.py | ||
test_codecs.py | ||
test_codeop.py | ||
test_coding.py | ||
test_colorsys.py | ||
test_commands.py | ||
test_compare.py | ||
test_compile.py | ||
test_compiler.py | ||
test_complex.py | ||
test_contains.py | ||
test_contextlib.py | ||
test_cookie.py | ||
test_cookielib.py | ||
test_copy.py | ||
test_copy_reg.py | ||
test_cpickle.py | ||
test_crypt.py | ||
test_csv.py | ||
test_ctypes.py | ||
test_curses.py | ||
test_datetime.py | ||
test_dbm.py | ||
test_decimal.py | ||
test_decorators.py | ||
test_defaultdict.py | ||
test_deque.py | ||
test_descr.py | ||
test_descrtut.py | ||
test_dict.py | ||
test_difflib.py | ||
test_difflib_expect.html | ||
test_dircache.py | ||
test_dis.py | ||
test_distutils.py | ||
test_dl.py | ||
test_doctest.py | ||
test_doctest.txt | ||
test_doctest2.py | ||
test_doctest2.txt | ||
test_doctest3.txt | ||
test_doctest4.txt | ||
test_dumbdbm.py | ||
test_dummy_thread.py | ||
test_dummy_threading.py | ||
test_email.py | ||
test_email_codecs.py | ||
test_email_renamed.py | ||
test_enumerate.py | ||
test_eof.py | ||
test_errno.py | ||
test_exception_variations.py | ||
test_exceptions.py | ||
test_extcall.py | ||
test_fcntl.py | ||
test_file.py | ||
test_filecmp.py | ||
test_fileinput.py | ||
test_float.py | ||
test_fnmatch.py | ||
test_fork1.py | ||
test_format.py | ||
test_fpformat.py | ||
test_frozen.py | ||
test_funcattrs.py | ||
test_functools.py | ||
test_future.py | ||
test_future1.py | ||
test_future2.py | ||
test_future3.py | ||
test_gc.py | ||
test_gdbm.py | ||
test_generators.py | ||
test_genexps.py | ||
test_getargs.py | ||
test_getargs2.py | ||
test_getopt.py | ||
test_gettext.py | ||
test_gl.py | ||
test_glob.py | ||
test_global.py | ||
test_grammar.py | ||
test_grp.py | ||
test_gzip.py | ||
test_hash.py | ||
test_hashlib.py | ||
test_heapq.py | ||
test_hexoct.py | ||
test_hmac.py | ||
test_hotshot.py | ||
test_htmllib.py | ||
test_htmlparser.py | ||
test_httplib.py | ||
test_imageop.py | ||
test_imaplib.py | ||
test_imgfile.py | ||
test_imp.py | ||
test_import.py | ||
test_importhooks.py | ||
test_index.py | ||
test_inspect.py | ||
test_ioctl.py | ||
test_isinstance.py | ||
test_iter.py | ||
test_iterlen.py | ||
test_itertools.py | ||
test_largefile.py | ||
test_linuxaudiodev.py | ||
test_list.py | ||
test_locale.py | ||
test_logging.py | ||
test_long.py | ||
test_long_future.py | ||
test_longexp.py | ||
test_macfs.py | ||
test_macostools.py | ||
test_macpath.py | ||
test_mailbox.py | ||
test_marshal.py | ||
test_math.py | ||
test_md5.py | ||
test_mhlib.py | ||
test_mimetools.py | ||
test_mimetypes.py | ||
test_minidom.py | ||
test_mmap.py | ||
test_module.py | ||
test_multibytecodec.py | ||
test_multibytecodec_support.py | ||
test_multifile.py | ||
test_mutants.py | ||
test_netrc.py | ||
test_new.py | ||
test_nis.py | ||
test_normalization.py | ||
test_ntpath.py | ||
test_old_mailbox.py | ||
test_opcodes.py | ||
test_openpty.py | ||
test_operations.py | ||
test_operator.py | ||
test_optparse.py | ||
test_os.py | ||
test_ossaudiodev.py | ||
test_parser.py | ||
test_peepholer.py | ||
test_pep247.py | ||
test_pep263.py | ||
test_pep277.py | ||
test_pep292.py | ||
test_pep352.py | ||
test_pickle.py | ||
test_pickletools.py | ||
test_pkg.py | ||
test_pkgimport.py | ||
test_platform.py | ||
test_plistlib.py | ||
test_poll.py | ||
test_popen.py | ||
test_popen2.py | ||
test_posix.py | ||
test_posixpath.py | ||
test_pow.py | ||
test_pprint.py | ||
test_profile.py | ||
test_profilehooks.py | ||
test_pty.py | ||
test_pwd.py | ||
test_pyclbr.py | ||
test_pyexpat.py | ||
test_queue.py | ||
test_quopri.py | ||
test_random.py | ||
test_re.py | ||
test_repr.py | ||
test_resource.py | ||
test_rfc822.py | ||
test_rgbimg.py | ||
test_richcmp.py | ||
test_robotparser.py | ||
test_runpy.py | ||
test_sax.py | ||
test_scope.py | ||
test_scriptpackages.py | ||
test_select.py | ||
test_set.py | ||
test_sets.py | ||
test_sgmllib.py | ||
test_sha.py | ||
test_shelve.py | ||
test_shlex.py | ||
test_shutil.py | ||
test_signal.py | ||
test_site.py | ||
test_slice.py | ||
test_socket.py | ||
test_socket_ssl.py | ||
test_socketserver.py | ||
test_softspace.py | ||
test_sort.py | ||
test_sqlite.py | ||
test_startfile.py | ||
test_str.py | ||
test_strftime.py | ||
test_string.py | ||
test_stringprep.py | ||
test_strop.py | ||
test_strptime.py | ||
test_struct.py | ||
test_structseq.py | ||
test_subprocess.py | ||
test_sunaudiodev.py | ||
test_sundry.py | ||
test_support.py | ||
test_symtable.py | ||
test_syntax.py | ||
test_sys.py | ||
test_tarfile.py | ||
test_tcl.py | ||
test_tempfile.py | ||
test_textwrap.py | ||
test_thread.py | ||
test_threaded_import.py | ||
test_threadedtempfile.py | ||
test_threading.py | ||
test_threading_local.py | ||
test_threadsignals.py | ||
test_time.py | ||
test_timeout.py | ||
test_tokenize.py | ||
test_trace.py | ||
test_traceback.py | ||
test_transformer.py | ||
test_tuple.py | ||
test_types.py | ||
test_ucn.py | ||
test_unary.py | ||
test_unicode.py | ||
test_unicode_file.py | ||
test_unicodedata.py | ||
test_unittest.py | ||
test_univnewlines.py | ||
test_unpack.py | ||
test_urllib.py | ||
test_urllib2.py | ||
test_urllib2net.py | ||
test_urllibnet.py | ||
test_urlparse.py | ||
test_userdict.py | ||
test_userlist.py | ||
test_userstring.py | ||
test_uu.py | ||
test_uuid.py | ||
test_wait3.py | ||
test_wait4.py | ||
test_warnings.py | ||
test_wave.py | ||
test_weakref.py | ||
test_whichdb.py | ||
test_winreg.py | ||
test_winsound.py | ||
test_with.py | ||
test_wsgiref.py | ||
test_xdrlib.py | ||
test_xml_etree.py | ||
test_xml_etree_c.py | ||
test_xmllib.py | ||
test_xmlrpc.py | ||
test_xpickle.py | ||
test_xrange.py | ||
test_zipfile.py | ||
test_zipfile64.py | ||
test_zipimport.py | ||
test_zlib.py | ||
testall.py | ||
testcodec.py | ||
testimg.uue | ||
testimgr.uue | ||
testrgb.uue | ||
testtar.tar | ||
tf_inherit_check.py | ||
threaded_import_hangers.py | ||
time_hashlib.py | ||
tokenize_tests.txt | ||
xmltests.py |
README
+++++++++++++++++++++++++++++++ Writing Python Regression Tests +++++++++++++++++++++++++++++++ :Author: Skip Montanaro :Contact: skip@mojam.com Introduction ============ If you add a new module to Python or modify the functionality of an existing module, you should write one or more test cases to exercise that new functionality. There are different ways to do this within the regression testing facility provided with Python; any particular test should use only one of these options. Each option requires writing a test module using the conventions of the selected option: - PyUnit_ based tests - doctest_ based tests - "traditional" Python test modules Regardless of the mechanics of the testing approach you choose, you will be writing unit tests (isolated tests of functions and objects defined by the module) using white box techniques. Unlike black box testing, where you only have the external interfaces to guide your test case writing, in white box testing you can see the code being tested and tailor your test cases to exercise it more completely. In particular, you will be able to refer to the C and Python code in the CVS repository when writing your regression test cases. .. _PyUnit: .. _unittest: http://www.python.org/doc/current/lib/module-unittest.html .. _doctest: http://www.python.org/doc/current/lib/module-doctest.html PyUnit based tests ------------------ The PyUnit_ framework is based on the ideas of unit testing as espoused by Kent Beck and the `Extreme Programming`_ (XP) movement. The specific interface provided by the framework is tightly based on the JUnit_ Java implementation of Beck's original SmallTalk test framework. Please see the documentation of the unittest_ module for detailed information on the interface and general guidelines on writing PyUnit based tests. The test_support helper module provides two functions for use by PyUnit based tests in the Python regression testing framework: - ``run_unittest()`` takes a ``unittest.TestCase`` derived class as a parameter and runs the tests defined in that class - ``run_suite()`` takes a populated ``TestSuite`` instance and runs the tests ``run_suite()`` is preferred because unittest files typically grow multiple test classes, and you might as well be prepared. All test methods in the Python regression framework have names that start with "``test_``" and use lower-case names with words separated with underscores. Test methods should *not* have docstrings! The unittest module prints the docstring if there is one, but otherwise prints the function name and the full class name. When there's a problem with a test, the latter information makes it easier to find the source for the test than the docstring. All PyUnit-based tests in the Python test suite use boilerplate that looks like this (with minor variations):: import unittest from test import test_support class MyTestCase1(unittest.TestCase): # Define setUp and tearDown only if needed def setUp(self): unittest.TestCase.setUp(self) ... additional initialization... def tearDown(self): ... additional finalization... unittest.TestCase.tearDown(self) def test_feature_one(self): # Testing feature one ...unit test for feature one... def test_feature_two(self): # Testing feature two ...unit test for feature two... ...etc... class MyTestCase2(unittest.TestCase): ...same structure as MyTestCase1... ...etc... def test_main(): suite = unittest.TestSuite() suite.addTest(unittest.makeSuite(MyTestCase1)) suite.addTest(unittest.makeSuite(MyTestCase2)) ...add more suites... test_support.run_suite(suite) if __name__ == "__main__": test_main() This has the advantage that it allows the unittest module to be used as a script to run individual tests as well as working well with the regrtest framework. .. _Extreme Programming: http://www.extremeprogramming.org/ .. _JUnit: http://www.junit.org/ doctest based tests ------------------- Tests written to use doctest_ are actually part of the docstrings for the module being tested. Each test is written as a display of an interactive session, including the Python prompts, statements that would be typed by the user, and the output of those statements (including tracebacks, although only the exception msg needs to be retained then). The module in the test package is simply a wrapper that causes doctest to run over the tests in the module. The test for the difflib module provides a convenient example:: import difflib from test import test_support test_support.run_doctest(difflib) If the test is successful, nothing is written to stdout (so you should not create a corresponding output/test_difflib file), but running regrtest with -v will give a detailed report, the same as if passing -v to doctest. A second argument can be passed to run_doctest to tell doctest to search ``sys.argv`` for -v instead of using test_support's idea of verbosity. This is useful for writing doctest-based tests that aren't simply running a doctest'ed Lib module, but contain the doctests themselves. Then at times you may want to run such a test directly as a doctest, independent of the regrtest framework. The tail end of test_descrtut.py is a good example:: def test_main(verbose=None): from test import test_support, test_descrtut test_support.run_doctest(test_descrtut, verbose) if __name__ == "__main__": test_main(1) If run via regrtest, ``test_main()`` is called (by regrtest) without specifying verbose, and then test_support's idea of verbosity is used. But when run directly, ``test_main(1)`` is called, and then doctest's idea of verbosity is used. See the documentation for the doctest module for information on writing tests using the doctest framework. "traditional" Python test modules --------------------------------- The mechanics of how the "traditional" test system operates are fairly straightforward. When a test case is run, the output is compared with the expected output that is stored in .../Lib/test/output. If the test runs to completion and the actual and expected outputs match, the test succeeds, if not, it fails. If an ``ImportError`` or ``test_support.TestSkipped`` error is raised, the test is not run. Executing Test Cases ==================== If you are writing test cases for module spam, you need to create a file in .../Lib/test named test_spam.py. In addition, if the tests are expected to write to stdout during a successful run, you also need to create an expected output file in .../Lib/test/output named test_spam ("..." represents the top-level directory in the Python source tree, the directory containing the configure script). If needed, generate the initial version of the test output file by executing:: ./python Lib/test/regrtest.py -g test_spam.py from the top-level directory. Any time you modify test_spam.py you need to generate a new expected output file. Don't forget to desk check the generated output to make sure it's really what you expected to find! All in all it's usually better not to have an expected-out file (note that doctest- and unittest-based tests do not). To run a single test after modifying a module, simply run regrtest.py without the -g flag:: ./python Lib/test/regrtest.py test_spam.py While debugging a regression test, you can of course execute it independently of the regression testing framework and see what it prints:: ./python Lib/test/test_spam.py To run the entire test suite: - [UNIX, + other platforms where "make" works] Make the "test" target at the top level:: make test - [WINDOWS] Run rt.bat from your PCBuild directory. Read the comments at the top of rt.bat for the use of special -d, -O and -q options processed by rt.bat. - [OTHER] You can simply execute the two runs of regrtest (optimized and non-optimized) directly:: ./python Lib/test/regrtest.py ./python -O Lib/test/regrtest.py But note that this way picks up whatever .pyc and .pyo files happen to be around. The makefile and rt.bat ways run the tests twice, the first time removing all .pyc and .pyo files from the subtree rooted at Lib/. Test cases generate output based upon values computed by the test code. When executed, regrtest.py compares the actual output generated by executing the test case with the expected output and reports success or failure. It stands to reason that if the actual and expected outputs are to match, they must not contain any machine dependencies. This means your test cases should not print out absolute machine addresses (e.g. the return value of the id() builtin function) or floating point numbers with large numbers of significant digits (unless you understand what you are doing!). Test Case Writing Tips ====================== Writing good test cases is a skilled task and is too complex to discuss in detail in this short document. Many books have been written on the subject. I'll show my age by suggesting that Glenford Myers' `"The Art of Software Testing"`_, published in 1979, is still the best introduction to the subject available. It is short (177 pages), easy to read, and discusses the major elements of software testing, though its publication predates the object-oriented software revolution, so doesn't cover that subject at all. Unfortunately, it is very expensive (about $100 new). If you can borrow it or find it used (around $20), I strongly urge you to pick up a copy. The most important goal when writing test cases is to break things. A test case that doesn't uncover a bug is much less valuable than one that does. In designing test cases you should pay attention to the following: * Your test cases should exercise all the functions and objects defined in the module, not just the ones meant to be called by users of your module. This may require you to write test code that uses the module in ways you don't expect (explicitly calling internal functions, for example - see test_atexit.py). * You should consider any boundary values that may tickle exceptional conditions (e.g. if you were writing regression tests for division, you might well want to generate tests with numerators and denominators at the limits of floating point and integer numbers on the machine performing the tests as well as a denominator of zero). * You should exercise as many paths through the code as possible. This may not always be possible, but is a goal to strive for. In particular, when considering if statements (or their equivalent), you want to create test cases that exercise both the true and false branches. For loops, you should create test cases that exercise the loop zero, one and multiple times. * You should test with obviously invalid input. If you know that a function requires an integer input, try calling it with other types of objects to see how it responds. * You should test with obviously out-of-range input. If the domain of a function is only defined for positive integers, try calling it with a negative integer. * If you are going to fix a bug that wasn't uncovered by an existing test, try to write a test case that exposes the bug (preferably before fixing it). * If you need to create a temporary file, you can use the filename in ``test_support.TESTFN`` to do so. It is important to remove the file when done; other tests should be able to use the name without cleaning up after your test. .. _"The Art of Software Testing": http://www.amazon.com/exec/obidos/ISBN=0471043281 Regression Test Writing Rules ============================= Each test case is different. There is no "standard" form for a Python regression test case, though there are some general rules (note that these mostly apply only to the "classic" tests; unittest_- and doctest_- based tests should follow the conventions natural to those frameworks):: * If your test case detects a failure, raise ``TestFailed`` (found in ``test.test_support``). * Import everything you'll need as early as possible. * If you'll be importing objects from a module that is at least partially platform-dependent, only import those objects you need for the current test case to avoid spurious ``ImportError`` exceptions that prevent the test from running to completion. * Print all your test case results using the ``print`` statement. For non-fatal errors, print an error message (or omit a successful completion print) to indicate the failure, but proceed instead of raising ``TestFailed``. * Use ``assert`` sparingly, if at all. It's usually better to just print what you got, and rely on regrtest's got-vs-expected comparison to catch deviations from what you expect. ``assert`` statements aren't executed at all when regrtest is run in -O mode; and, because they cause the test to stop immediately, can lead to a long & tedious test-fix, test-fix, test-fix, ... cycle when things are badly broken (and note that "badly broken" often includes running the test suite for the first time on new platforms or under new implementations of the language). Miscellaneous ============= There is a test_support module in the test package you can import for your test case. Import this module using either:: import test.test_support or:: from test import test_support test_support provides the following useful objects: * ``TestFailed`` - raise this exception when your regression test detects a failure. * ``TestSkipped`` - raise this if the test could not be run because the platform doesn't offer all the required facilities (like large file support), even if all the required modules are available. * ``ResourceDenied`` - this is raised when a test requires a resource that is not available. Primarily used by 'requires'. * ``verbose`` - you can use this variable to control print output. Many modules use it. Search for "verbose" in the test_*.py files to see lots of examples. * ``forget(module_name)`` - attempts to cause Python to "forget" that it loaded a module and erase any PYC files. * ``is_resource_enabled(resource)`` - Returns a boolean based on whether the resource is enabled or not. * ``requires(resource [, msg])`` - if the required resource is not available the ResourceDenied exception is raised. * ``verify(condition, reason='test failed')``. Use this instead of:: assert condition[, reason] ``verify()`` has two advantages over ``assert``: it works even in -O mode, and it raises ``TestFailed`` on failure instead of ``AssertionError``. * ``have_unicode`` - true if Unicode is available, false otherwise. * ``is_jython`` - true if the interpreter is Jython, false otherwise. * ``TESTFN`` - a string that should always be used as the filename when you need to create a temp file. Also use ``try``/``finally`` to ensure that your temp files are deleted before your test completes. Note that you cannot unlink an open file on all operating systems, so also be sure to close temp files before trying to unlink them. * ``sortdict(dict)`` - acts like ``repr(dict.items())``, but sorts the items first. This is important when printing a dict value, because the order of items produced by ``dict.items()`` is not defined by the language. * ``findfile(file)`` - you can call this function to locate a file somewhere along sys.path or in the Lib/test tree - see test_linuxaudiodev.py for an example of its use. * ``fcmp(x,y)`` - you can call this function to compare two floating point numbers when you expect them to only be approximately equal withing a fuzz factor (``test_support.FUZZ``, which defaults to 1e-6). * ``check_syntax(statement)`` - make sure that the statement is *not* correct Python syntax. Python and C statement coverage results are currently available at http://www.musi-cal.com/~skip/python/Python/dist/src/ As of this writing (July, 2000) these results are being generated nightly. You can refer to the summaries and the test coverage output files to see where coverage is adequate or lacking and write test cases to beef up the coverage. Some Non-Obvious regrtest Features ================================== * Automagic test detection: When you create a new test file test_spam.py, you do not need to modify regrtest (or anything else) to advertise its existence. regrtest searches for and runs all modules in the test directory with names of the form test_xxx.py. * Miranda output: If, when running test_spam.py, regrtest does not find an expected-output file test/output/test_spam, regrtest pretends that it did find one, containing the single line test_spam This allows new tests that don't expect to print anything to stdout to not bother creating expected-output files. * Two-stage testing: To run test_spam.py, regrtest imports test_spam as a module. Most tests run to completion as a side-effect of getting imported. After importing test_spam, regrtest also executes ``test_spam.test_main()``, if test_spam has a ``test_main`` attribute. This is rarely required with the "traditional" Python tests, and you shouldn't create a module global with name test_main unless you're specifically exploiting this gimmick. This usage does prove useful with PyUnit-based tests as well, however; defining a ``test_main()`` which is run by regrtest and a script-stub in the test module ("``if __name__ == '__main__': test_main()``") allows the test to be used like any other Python test and also work with the unittest.py-as-a-script approach, allowing a developer to run specific tests from the command line.