diff options
author | Thomas Wouters <thomas@python.org> | 2006-08-21 19:07:27 (GMT) |
---|---|---|
committer | Thomas Wouters <thomas@python.org> | 2006-08-21 19:07:27 (GMT) |
commit | 00ee7baf49430d8a6eed355a5fd7a05179325747 (patch) | |
tree | da92c2dbd8a9acf04b234200e12a299a6ea55ece /Lib/test | |
parent | 18a67ba0bd6d23da454e975f814dad50d7e09cdb (diff) | |
download | cpython-00ee7baf49430d8a6eed355a5fd7a05179325747.zip cpython-00ee7baf49430d8a6eed355a5fd7a05179325747.tar.gz cpython-00ee7baf49430d8a6eed355a5fd7a05179325747.tar.bz2 |
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
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)
........
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/exception_hierarchy.txt | 1 | ||||
-rw-r--r-- | Lib/test/inspect_fodder2.py | 9 | ||||
-rw-r--r-- | Lib/test/output/test_cgi | 2 | ||||
-rw-r--r-- | Lib/test/test_bytes.py | 8 | ||||
-rw-r--r-- | Lib/test/test_bz2.py | 11 | ||||
-rw-r--r-- | Lib/test/test_cgi.py | 69 | ||||
-rw-r--r-- | Lib/test/test_compiler.py | 7 | ||||
-rw-r--r-- | Lib/test/test_format.py | 8 | ||||
-rw-r--r-- | Lib/test/test_index.py | 182 | ||||
-rw-r--r-- | Lib/test/test_inspect.py | 3 | ||||
-rw-r--r-- | Lib/test/test_logging.py | 4 | ||||
-rw-r--r-- | Lib/test/test_mailbox.py | 13 | ||||
-rw-r--r-- | Lib/test/test_signal.py | 149 | ||||
-rw-r--r-- | Lib/test/test_socketserver.py | 9 | ||||
-rw-r--r-- | Lib/test/test_tarfile.py | 21 | ||||
-rw-r--r-- | Lib/test/test_threading.py | 70 | ||||
-rw-r--r-- | Lib/test/test_threadsignals.py | 2 | ||||
-rw-r--r-- | Lib/test/test_urllib2.py | 77 | ||||
-rw-r--r-- | Lib/test/test_uuid.py | 97 | ||||
-rw-r--r-- | Lib/test/test_xml_etree_c.py | 11 |
20 files changed, 587 insertions, 166 deletions
diff --git a/Lib/test/exception_hierarchy.txt b/Lib/test/exception_hierarchy.txt index 58131d7..a03f7bb 100644 --- a/Lib/test/exception_hierarchy.txt +++ b/Lib/test/exception_hierarchy.txt @@ -45,3 +45,4 @@ BaseException +-- UserWarning +-- FutureWarning +-- ImportWarning + +-- UnicodeWarning diff --git a/Lib/test/inspect_fodder2.py b/Lib/test/inspect_fodder2.py index f150ec6..3d978cf 100644 --- a/Lib/test/inspect_fodder2.py +++ b/Lib/test/inspect_fodder2.py @@ -88,3 +88,12 @@ extra85 = 'stop' def func88(): # comment return 90 + +# line 92 +def f(): + class X: + def g(): + "doc" + return 42 + return X +method_in_dynamic_class = f().g.im_func diff --git a/Lib/test/output/test_cgi b/Lib/test/output/test_cgi index d5d6f75..26eddfa 100644 --- a/Lib/test/output/test_cgi +++ b/Lib/test/output/test_cgi @@ -38,3 +38,5 @@ test_cgi Testing log Testing initlog 1 Testing log 2 +Test FieldStorage methods that use readline +Test basic FieldStorage multipart parsing diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py index d45ff64..06beb1d 100644 --- a/Lib/test/test_bytes.py +++ b/Lib/test/test_bytes.py @@ -60,13 +60,13 @@ class BytesTest(unittest.TestCase): self.assertRaises(ValueError, bytes, [-1]) self.assertRaises(ValueError, bytes, [-sys.maxint]) self.assertRaises(ValueError, bytes, [-sys.maxint-1]) - self.assertRaises(ValueError, bytes, [-sys.maxint-2]) - self.assertRaises(ValueError, bytes, [-10**100]) + self.assertRaises(TypeError, bytes, [-sys.maxint-2]) + self.assertRaises(TypeError, bytes, [-10**100]) self.assertRaises(ValueError, bytes, [256]) self.assertRaises(ValueError, bytes, [257]) self.assertRaises(ValueError, bytes, [sys.maxint]) - self.assertRaises(ValueError, bytes, [sys.maxint+1]) - self.assertRaises(ValueError, bytes, [10**100]) + self.assertRaises(TypeError, bytes, [sys.maxint+1]) + self.assertRaises(TypeError, bytes, [10**100]) def test_repr(self): self.assertEqual(repr(bytes()), "bytes()") diff --git a/Lib/test/test_bz2.py b/Lib/test/test_bz2.py index f198116..8561723 100644 --- a/Lib/test/test_bz2.py +++ b/Lib/test/test_bz2.py @@ -158,10 +158,21 @@ class BZ2FileTest(BaseTest): sio = StringIO(self.TEXT) bz2f.writelines(sio.readlines()) bz2f.close() + # patch #1535500 + self.assertRaises(ValueError, bz2f.writelines, ["a"]) f = open(self.filename, 'rb') self.assertEqual(self.decompress(f.read()), self.TEXT) f.close() + def testWriteMethodsOnReadOnlyFile(self): + bz2f = BZ2File(self.filename, "w") + bz2f.write("abc") + bz2f.close() + + bz2f = BZ2File(self.filename, "r") + self.assertRaises(IOError, bz2f.write, "a") + self.assertRaises(IOError, bz2f.writelines, ["a"]) + def testSeekForward(self): # "Test BZ2File.seek(150, 0)" self.createTempFile() diff --git a/Lib/test/test_cgi.py b/Lib/test/test_cgi.py index 8b0b482..8fe487b 100644 --- a/Lib/test/test_cgi.py +++ b/Lib/test/test_cgi.py @@ -2,6 +2,8 @@ from test.test_support import verify, verbose import cgi import os import sys +import tempfile +from StringIO import StringIO class HackedSysModule: # The regression test will have real values in sys.argv, which @@ -203,4 +205,71 @@ def main(): cgi.initlog("%s", "Testing log 3") cgi.log("Testing log 4") + print "Test FieldStorage methods that use readline" + # FieldStorage uses readline, which has the capacity to read all + # contents of the input file into memory; we use readline's size argument + # to prevent that for files that do not contain any newlines in + # non-GET/HEAD requests + class TestReadlineFile: + def __init__(self, file): + self.file = file + self.numcalls = 0 + + def readline(self, size=None): + self.numcalls += 1 + if size: + return self.file.readline(size) + else: + return self.file.readline() + + def __getattr__(self, name): + file = self.__dict__['file'] + a = getattr(file, name) + if not isinstance(a, int): + setattr(self, name, a) + return a + + f = TestReadlineFile(tempfile.TemporaryFile()) + f.write('x' * 256 * 1024) + f.seek(0) + env = {'REQUEST_METHOD':'PUT'} + fs = cgi.FieldStorage(fp=f, environ=env) + # if we're not chunking properly, readline is only called twice + # (by read_binary); if we are chunking properly, it will be called 5 times + # as long as the chunksize is 1 << 16. + verify(f.numcalls > 2) + + print "Test basic FieldStorage multipart parsing" + env = {'REQUEST_METHOD':'POST', 'CONTENT_TYPE':'multipart/form-data; boundary=---------------------------721837373350705526688164684', 'CONTENT_LENGTH':'558'} + postdata = """-----------------------------721837373350705526688164684 +Content-Disposition: form-data; name="id" + +1234 +-----------------------------721837373350705526688164684 +Content-Disposition: form-data; name="title" + + +-----------------------------721837373350705526688164684 +Content-Disposition: form-data; name="file"; filename="test.txt" +Content-Type: text/plain + +Testing 123. + +-----------------------------721837373350705526688164684 +Content-Disposition: form-data; name="submit" + + Add\x20 +-----------------------------721837373350705526688164684-- +""" + fs = cgi.FieldStorage(fp=StringIO(postdata), environ=env) + verify(len(fs.list) == 4) + expect = [{'name':'id', 'filename':None, 'value':'1234'}, + {'name':'title', 'filename':None, 'value':''}, + {'name':'file', 'filename':'test.txt','value':'Testing 123.\n'}, + {'name':'submit', 'filename':None, 'value':' Add '}] + for x in range(len(fs.list)): + for k, exp in expect[x].items(): + got = getattr(fs.list[x], k) + verify(got == exp) + main() diff --git a/Lib/test/test_compiler.py b/Lib/test/test_compiler.py index 1efb6a6..81f2ea8 100644 --- a/Lib/test/test_compiler.py +++ b/Lib/test/test_compiler.py @@ -116,6 +116,13 @@ class CompilerTest(unittest.TestCase): exec c in dct self.assertEquals(dct.get('result'), 3) + def testGenExp(self): + c = compiler.compile('list((i,j) for i in range(3) if i < 3' + ' for j in range(4) if j > 2)', + '<string>', + 'eval') + self.assertEquals(eval(c), [(0, 3), (1, 3), (2, 3)]) + NOLINENO = (compiler.ast.Module, compiler.ast.Stmt, compiler.ast.Discard) diff --git a/Lib/test/test_format.py b/Lib/test/test_format.py index 2959447..a9b3170 100644 --- a/Lib/test/test_format.py +++ b/Lib/test/test_format.py @@ -230,6 +230,14 @@ test_exc(u'no format', '1', TypeError, test_exc(u'no format', u'1', TypeError, "not all arguments converted during string formatting") +class Foobar(long): + def __oct__(self): + # Returning a non-string should not blow up. + return self + 1 + +test_exc('%o', Foobar(), TypeError, + "expected string or Unicode object, long found") + if sys.maxint == 2**31-1: # crashes 2.2.1 and earlier: try: diff --git a/Lib/test/test_index.py b/Lib/test/test_index.py index 45b3b2b..ecb566d 100644 --- a/Lib/test/test_index.py +++ b/Lib/test/test_index.py @@ -1,6 +1,7 @@ import unittest from test import test_support import operator +from sys import maxint class oldstyle: def __index__(self): @@ -10,68 +11,116 @@ class newstyle(object): def __index__(self): return self.ind +class TrapInt(int): + def __index__(self): + return self + +class TrapLong(long): + def __index__(self): + return self + class BaseTestCase(unittest.TestCase): def setUp(self): self.o = oldstyle() self.n = newstyle() - self.o2 = oldstyle() - self.n2 = newstyle() def test_basic(self): self.o.ind = -2 self.n.ind = 2 - assert(self.seq[self.n] == self.seq[2]) - assert(self.seq[self.o] == self.seq[-2]) - assert(operator.index(self.o) == -2) - assert(operator.index(self.n) == 2) + self.assertEqual(operator.index(self.o), -2) + self.assertEqual(operator.index(self.n), 2) + + def test_slice(self): + self.o.ind = 1 + self.n.ind = 2 + slc = slice(self.o, self.o, self.o) + check_slc = slice(1, 1, 1) + self.assertEqual(slc.indices(self.o), check_slc.indices(1)) + slc = slice(self.n, self.n, self.n) + check_slc = slice(2, 2, 2) + self.assertEqual(slc.indices(self.n), check_slc.indices(2)) + + def test_wrappers(self): + self.o.ind = 4 + self.n.ind = 5 + self.assertEqual(6 .__index__(), 6) + self.assertEqual(-7L.__index__(), -7) + self.assertEqual(self.o.__index__(), 4) + self.assertEqual(self.n.__index__(), 5) + + def test_subclasses(self): + r = range(10) + self.assertEqual(r[TrapInt(5):TrapInt(10)], r[5:10]) + self.assertEqual(r[TrapLong(5):TrapLong(10)], r[5:10]) + self.assertEqual(slice(TrapInt()).indices(0), (0,0,1)) + self.assertEqual(slice(TrapLong(0)).indices(0), (0,0,1)) def test_error(self): self.o.ind = 'dumb' self.n.ind = 'bad' - myfunc = lambda x, obj: obj.seq[x] self.failUnlessRaises(TypeError, operator.index, self.o) self.failUnlessRaises(TypeError, operator.index, self.n) - self.failUnlessRaises(TypeError, myfunc, self.o, self) - self.failUnlessRaises(TypeError, myfunc, self.n, self) + self.failUnlessRaises(TypeError, slice(self.o).indices, 0) + self.failUnlessRaises(TypeError, slice(self.n).indices, 0) + + +class SeqTestCase(unittest.TestCase): + # This test case isn't run directly. It just defines common tests + # to the different sequence types below + def setUp(self): + self.o = oldstyle() + self.n = newstyle() + self.o2 = oldstyle() + self.n2 = newstyle() + + def test_index(self): + self.o.ind = -2 + self.n.ind = 2 + self.assertEqual(self.seq[self.n], self.seq[2]) + self.assertEqual(self.seq[self.o], self.seq[-2]) def test_slice(self): self.o.ind = 1 self.o2.ind = 3 self.n.ind = 2 self.n2.ind = 4 - assert(self.seq[self.o:self.o2] == self.seq[1:3]) - assert(self.seq[self.n:self.n2] == self.seq[2:4]) + self.assertEqual(self.seq[self.o:self.o2], self.seq[1:3]) + self.assertEqual(self.seq[self.n:self.n2], self.seq[2:4]) def test_repeat(self): self.o.ind = 3 self.n.ind = 2 - assert(self.seq * self.o == self.seq * 3) - assert(self.seq * self.n == self.seq * 2) - assert(self.o * self.seq == self.seq * 3) - assert(self.n * self.seq == self.seq * 2) + self.assertEqual(self.seq * self.o, self.seq * 3) + self.assertEqual(self.seq * self.n, self.seq * 2) + self.assertEqual(self.o * self.seq, self.seq * 3) + self.assertEqual(self.n * self.seq, self.seq * 2) def test_wrappers(self): - n = self.n - n.ind = 5 - assert n.__index__() == 5 - assert 6 .__index__() == 6 - assert -7L.__index__() == -7 - assert self.seq.__getitem__(n) == self.seq[5] - assert self.seq.__mul__(n) == self.seq * 5 - assert self.seq.__rmul__(n) == self.seq * 5 - - def test_infinite_recusion(self): - class Trap1(int): - def __index__(self): - return self - class Trap2(long): - def __index__(self): - return self - self.failUnlessRaises(TypeError, operator.getitem, self.seq, Trap1()) - self.failUnlessRaises(TypeError, operator.getitem, self.seq, Trap2()) - - -class ListTestCase(BaseTestCase): + self.o.ind = 4 + self.n.ind = 5 + self.assertEqual(self.seq.__getitem__(self.o), self.seq[4]) + self.assertEqual(self.seq.__mul__(self.o), self.seq * 4) + self.assertEqual(self.seq.__rmul__(self.o), self.seq * 4) + self.assertEqual(self.seq.__getitem__(self.n), self.seq[5]) + self.assertEqual(self.seq.__mul__(self.n), self.seq * 5) + self.assertEqual(self.seq.__rmul__(self.n), self.seq * 5) + + def test_subclasses(self): + self.assertEqual(self.seq[TrapInt()], self.seq[0]) + self.assertEqual(self.seq[TrapLong()], self.seq[0]) + + def test_error(self): + self.o.ind = 'dumb' + self.n.ind = 'bad' + indexobj = lambda x, obj: obj.seq[x] + self.failUnlessRaises(TypeError, indexobj, self.o, self) + self.failUnlessRaises(TypeError, indexobj, self.n, self) + sliceobj = lambda x, obj: obj.seq[x:] + self.failUnlessRaises(TypeError, sliceobj, self.o, self) + self.failUnlessRaises(TypeError, sliceobj, self.n, self) + + +class ListTestCase(SeqTestCase): seq = [0,10,20,30,40,50] def test_setdelitem(self): @@ -82,36 +131,36 @@ class ListTestCase(BaseTestCase): del lst[self.n] lst[self.o] = 'X' lst[self.n] = 'Y' - assert lst == list('abYdefghXj') + self.assertEqual(lst, list('abYdefghXj')) lst = [5, 6, 7, 8, 9, 10, 11] lst.__setitem__(self.n, "here") - assert lst == [5, 6, "here", 8, 9, 10, 11] + self.assertEqual(lst, [5, 6, "here", 8, 9, 10, 11]) lst.__delitem__(self.n) - assert lst == [5, 6, 8, 9, 10, 11] + self.assertEqual(lst, [5, 6, 8, 9, 10, 11]) def test_inplace_repeat(self): self.o.ind = 2 self.n.ind = 3 lst = [6, 4] lst *= self.o - assert lst == [6, 4, 6, 4] + self.assertEqual(lst, [6, 4, 6, 4]) lst *= self.n - assert lst == [6, 4, 6, 4] * 3 + self.assertEqual(lst, [6, 4, 6, 4] * 3) lst = [5, 6, 7, 8, 9, 11] l2 = lst.__imul__(self.n) - assert l2 is lst - assert lst == [5, 6, 7, 8, 9, 11] * 3 + self.assert_(l2 is lst) + self.assertEqual(lst, [5, 6, 7, 8, 9, 11] * 3) -class TupleTestCase(BaseTestCase): +class TupleTestCase(SeqTestCase): seq = (0,10,20,30,40,50) -class StringTestCase(BaseTestCase): +class StringTestCase(SeqTestCase): seq = "this is a test" -class UnicodeTestCase(BaseTestCase): +class UnicodeTestCase(SeqTestCase): seq = u"this is a test" @@ -120,17 +169,54 @@ class XRangeTestCase(unittest.TestCase): def test_xrange(self): n = newstyle() n.ind = 5 - assert xrange(1, 20)[n] == 6 - assert xrange(1, 20).__getitem__(n) == 6 + self.assertEqual(xrange(1, 20)[n], 6) + self.assertEqual(xrange(1, 20).__getitem__(n), 6) + +class OverflowTestCase(unittest.TestCase): + + def setUp(self): + self.pos = 2**100 + self.neg = -self.pos + + def test_large_longs(self): + self.assertEqual(self.pos.__index__(), self.pos) + self.assertEqual(self.neg.__index__(), self.neg) + + def _getitem_helper(self, base): + class GetItem(base): + def __len__(self): + return maxint + def __getitem__(self, key): + return key + def __getslice__(self, i, j): + return i, j + x = GetItem() + self.assertEqual(x[self.pos], self.pos) + self.assertEqual(x[self.neg], self.neg) + self.assertEqual(x[self.neg:self.pos], (-1, maxint)) + self.assertEqual(x[self.neg:self.pos:1].indices(maxint), (0, maxint, 1)) + + def test_getitem(self): + self._getitem_helper(object) + + def test_getitem_classic(self): + class Empty: pass + self._getitem_helper(Empty) + + def test_sequence_repeat(self): + self.failUnlessRaises(OverflowError, lambda: "a" * self.pos) + self.failUnlessRaises(OverflowError, lambda: "a" * self.neg) def test_main(): test_support.run_unittest( + BaseTestCase, ListTestCase, TupleTestCase, StringTestCase, UnicodeTestCase, XRangeTestCase, + OverflowTestCase, ) if __name__ == "__main__": diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index 99140d2..e9f9ef1 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -276,6 +276,9 @@ class TestBuggyCases(GetSourceBase): def test_with_comment_instead_of_docstring(self): self.assertSourceEqual(mod2.func88, 88, 90) + def test_method_in_dynamic_class(self): + self.assertSourceEqual(mod2.method_in_dynamic_class, 95, 97) + # Helper for testing classify_class_attrs. def attrs_wo_objs(cls): return [t[:3] for t in inspect.classify_class_attrs(cls)] diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py index fe05123..d6dcc3c 100644 --- a/Lib/test/test_logging.py +++ b/Lib/test/test_logging.py @@ -493,7 +493,7 @@ def test4(): try: logging._handlers.clear() logging._handlers.update(saved_handlers) - logging._handlerList = saved_handler_list + logging._handlerList[:] = saved_handler_list loggerDict = logging.getLogger().manager.loggerDict loggerDict.clear() loggerDict.update(saved_loggers) @@ -560,7 +560,7 @@ def test5(): try: logging._handlers.clear() logging._handlers.update(saved_handlers) - logging._handlerList = saved_handler_list + logging._handlerList[:] = saved_handler_list loggerDict = logging.getLogger().manager.loggerDict loggerDict.clear() loggerDict.update(saved_loggers) diff --git a/Lib/test/test_mailbox.py b/Lib/test/test_mailbox.py index 04e856f..1837306 100644 --- a/Lib/test/test_mailbox.py +++ b/Lib/test/test_mailbox.py @@ -1,4 +1,5 @@ import os +import sys import time import stat import socket @@ -454,7 +455,7 @@ class TestMaildir(TestMailbox): def setUp(self): TestMailbox.setUp(self) - if os.name in ('nt', 'os2'): + if os.name in ('nt', 'os2') or sys.platform == 'cygwin': self._box.colon = '!' def test_add_MM(self): @@ -729,11 +730,13 @@ class _TestMboxMMDF(TestMailbox): # In the parent, sleep a bit to give the child time to acquire # the lock. time.sleep(0.5) - self.assertRaises(mailbox.ExternalClashError, - self._box.lock) + try: + self.assertRaises(mailbox.ExternalClashError, + self._box.lock) + finally: + # Wait for child to exit. Locking should now succeed. + exited_pid, status = os.waitpid(pid, 0) - # Wait for child to exit. Locking should now succeed. - exited_pid, status = os.waitpid(pid, 0) self._box.lock() self._box.unlock() diff --git a/Lib/test/test_signal.py b/Lib/test/test_signal.py index a6267d2..13d02bb 100644 --- a/Lib/test/test_signal.py +++ b/Lib/test/test_signal.py @@ -6,11 +6,16 @@ import os, sys, time if sys.platform[:3] in ('win', 'os2') or sys.platform=='riscos': raise TestSkipped, "Can't test signal on %s" % sys.platform +MAX_DURATION = 20 # Entire test should last at most 20 sec. + if verbose: x = '-x' else: x = '+x' + pid = os.getpid() +if verbose: + print "test runner's pid is", pid # Shell script that will send us asynchronous signals script = """ @@ -31,7 +36,7 @@ def handlerA(*args): global a_called a_called = True if verbose: - print "handlerA", args + print "handlerA invoked", args class HandlerBCalled(Exception): pass @@ -40,87 +45,110 @@ def handlerB(*args): global b_called b_called = True if verbose: - print "handlerB", args + print "handlerB invoked", args raise HandlerBCalled, args -MAX_DURATION = 20 -signal.alarm(MAX_DURATION) # Entire test should last at most 20 sec. +# Set up a child to send signals to us (the parent) after waiting long +# enough to receive the alarm. It seems we miss the alarm for some +# reason. This will hopefully stop the hangs on Tru64/Alpha. +# Alas, it doesn't. Tru64 appears to miss all the signals at times, or +# seemingly random subsets of them, and nothing done in force_test_exit +# so far has actually helped. +def force_test_exit(): + # Sigh, both imports seem necessary to avoid errors. + import os + fork_pid = os.fork() + if fork_pid: + # In parent. + return fork_pid + + # In child. + import os, time + try: + # Wait 5 seconds longer than the expected alarm to give enough + # time for the normal sequence of events to occur. This is + # just a stop-gap to try to prevent the test from hanging. + time.sleep(MAX_DURATION + 5) + print >> sys.__stdout__, ' child should not have to kill parent' + for signame in "SIGHUP", "SIGUSR1", "SIGUSR2", "SIGALRM": + os.kill(pid, getattr(signal, signame)) + print >> sys.__stdout__, " child sent", signame, "to", pid + time.sleep(1) + finally: + os._exit(0) + +# Install handlers. hup = signal.signal(signal.SIGHUP, handlerA) usr1 = signal.signal(signal.SIGUSR1, handlerB) usr2 = signal.signal(signal.SIGUSR2, signal.SIG_IGN) alrm = signal.signal(signal.SIGALRM, signal.default_int_handler) -vereq(signal.getsignal(signal.SIGHUP), handlerA) -vereq(signal.getsignal(signal.SIGUSR1), handlerB) -vereq(signal.getsignal(signal.SIGUSR2), signal.SIG_IGN) - try: - signal.signal(4242, handlerB) - raise TestFailed, 'expected ValueError for invalid signal # to signal()' -except ValueError: - pass -try: - signal.getsignal(4242) - raise TestFailed, 'expected ValueError for invalid signal # to getsignal()' -except ValueError: - pass + signal.alarm(MAX_DURATION) + vereq(signal.getsignal(signal.SIGHUP), handlerA) + vereq(signal.getsignal(signal.SIGUSR1), handlerB) + vereq(signal.getsignal(signal.SIGUSR2), signal.SIG_IGN) + vereq(signal.getsignal(signal.SIGALRM), signal.default_int_handler) -try: - signal.signal(signal.SIGUSR1, None) - raise TestFailed, 'expected TypeError for non-callable' -except TypeError: - pass + # Try to ensure this test exits even if there is some problem with alarm. + # Tru64/Alpha often hangs and is ultimately killed by the buildbot. + fork_pid = force_test_exit() -# Set up a child to send an alarm signal to us (the parent) after waiting -# long enough to receive the alarm. It seems we miss the alarm for some -# reason. This will hopefully stop the hangs on Tru64/Alpha. -def force_test_exit(): - # Sigh, both imports seem necessary to avoid errors. - import os - fork_pid = os.fork() - if fork_pid == 0: - # In child - import os, time - try: - # Wait 5 seconds longer than the expected alarm to give enough - # time for the normal sequence of events to occur. This is - # just a stop-gap to prevent the test from hanging. - time.sleep(MAX_DURATION + 5) - print >> sys.__stdout__, ' child should not have to kill parent' - for i in range(3): - os.kill(pid, signal.SIGALARM) - finally: - os._exit(0) - # In parent (or error) - return fork_pid + try: + signal.getsignal(4242) + raise TestFailed('expected ValueError for invalid signal # to ' + 'getsignal()') + except ValueError: + pass -try: - os.system(script) + try: + signal.signal(4242, handlerB) + raise TestFailed('expected ValueError for invalid signal # to ' + 'signal()') + except ValueError: + pass - # Try to ensure this test exits even if there is some problem with alarm. - # Tru64/Alpha sometimes hangs and is ultimately killed by the buildbot. - fork_pid = force_test_exit() - print "starting pause() loop..." + try: + signal.signal(signal.SIGUSR1, None) + raise TestFailed('expected TypeError for non-callable') + except TypeError: + pass + # Launch an external script to send us signals. + # We expect the external script to: + # send HUP, which invokes handlerA to set a_called + # send USR1, which invokes handlerB to set b_called and raise + # HandlerBCalled + # send USR2, which is ignored + # + # Then we expect the alarm to go off, and its handler raises + # KeyboardInterrupt, finally getting us out of the loop. + os.system(script) try: + print "starting pause() loop..." while 1: - if verbose: - print "call pause()..." try: + if verbose: + print "call pause()..." signal.pause() if verbose: print "pause() returned" except HandlerBCalled: if verbose: print "HandlerBCalled exception caught" - else: - pass except KeyboardInterrupt: if verbose: - print "KeyboardInterrupt (assume the alarm() went off)" + print "KeyboardInterrupt (the alarm() went off)" + + if not a_called: + print 'HandlerA not called' + + if not b_called: + print 'HandlerB not called' +finally: # Forcibly kill the child we created to ping us if there was a test error. try: # Make sure we don't kill ourself if there was a fork error. @@ -128,16 +156,11 @@ try: os.kill(fork_pid, signal.SIGKILL) except: # If the child killed us, it has probably exited. Killing a - # non-existant process will raise an error which we don't care about. + # non-existent process will raise an error which we don't care about. pass - if not a_called: - print 'HandlerA not called' - - if not b_called: - print 'HandlerB not called' - -finally: + # Restore handlers. + signal.alarm(0) # cancel alarm in case we died early signal.signal(signal.SIGHUP, hup) signal.signal(signal.SIGUSR1, usr1) signal.signal(signal.SIGUSR2, usr2) diff --git a/Lib/test/test_socketserver.py b/Lib/test/test_socketserver.py index dd4532f..e4cbb2b 100644 --- a/Lib/test/test_socketserver.py +++ b/Lib/test/test_socketserver.py @@ -181,10 +181,19 @@ else: if hasattr(os, 'fork') and os.name not in ('os2',): dgramservers.append(ForkingUnixDatagramServer) +def sloppy_cleanup(): + # See http://python.org/sf/1540386 + # We need to reap children here otherwise a child from one server + # can be left running for the next server and cause a test failure. + time.sleep(DELAY) + reap_children() + def testall(): testloop(socket.AF_INET, tcpservers, MyStreamHandler, teststream) + sloppy_cleanup() testloop(socket.AF_INET, udpservers, MyDatagramHandler, testdgram) if hasattr(socket, 'AF_UNIX'): + sloppy_cleanup() testloop(socket.AF_UNIX, streamservers, MyStreamHandler, teststream) # Alas, on Linux (at least) recvfrom() doesn't return a meaningful # client address so this cannot work: diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py index 8ee0f41..ebcb8c5 100644 --- a/Lib/test/test_tarfile.py +++ b/Lib/test/test_tarfile.py @@ -324,6 +324,27 @@ class WriteSize0Test(BaseTest): class WriteStreamTest(WriteTest): sep = '|' + def test_padding(self): + self.dst.close() + + if self.comp == "gz": + f = gzip.GzipFile(self.dstname) + s = f.read() + f.close() + elif self.comp == "bz2": + f = bz2.BZ2Decompressor() + s = file(self.dstname).read() + s = f.decompress(s) + self.assertEqual(len(f.unused_data), 0, "trailing data") + else: + f = file(self.dstname) + s = f.read() + f.close() + + self.assertEqual(s.count("\0"), tarfile.RECORDSIZE, + "incorrect zero padding") + + class WriteGNULongTest(unittest.TestCase): """This testcase checks for correct creation of GNU Longname and Longlink extensions. diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py index 79335ea..8614ecb 100644 --- a/Lib/test/test_threading.py +++ b/Lib/test/test_threading.py @@ -131,6 +131,76 @@ class ThreadTests(unittest.TestCase): threading._DummyThread)) del threading._active[tid] + # PyThreadState_SetAsyncExc() is a CPython-only gimmick, not (currently) + # exposed at the Python level. This test relies on ctypes to get at it. + def test_PyThreadState_SetAsyncExc(self): + try: + import ctypes + except ImportError: + if verbose: + print "test_PyThreadState_SetAsyncExc can't import ctypes" + return # can't do anything + + set_async_exc = ctypes.pythonapi.PyThreadState_SetAsyncExc + + class AsyncExc(Exception): + pass + + exception = ctypes.py_object(AsyncExc) + + # `worker_started` is set by the thread when it's inside a try/except + # block waiting to catch the asynchronously set AsyncExc exception. + # `worker_saw_exception` is set by the thread upon catching that + # exception. + worker_started = threading.Event() + worker_saw_exception = threading.Event() + + class Worker(threading.Thread): + def run(self): + self.id = thread.get_ident() + self.finished = False + + try: + while True: + worker_started.set() + time.sleep(0.1) + except AsyncExc: + self.finished = True + worker_saw_exception.set() + + t = Worker() + t.setDaemon(True) # so if this fails, we don't hang Python at shutdown + t.start() + if verbose: + print " started worker thread" + + # Try a thread id that doesn't make sense. + if verbose: + print " trying nonsensical thread id" + result = set_async_exc(ctypes.c_long(-1), exception) + self.assertEqual(result, 0) # no thread states modified + + # Now raise an exception in the worker thread. + if verbose: + print " waiting for worker thread to get started" + worker_started.wait() + if verbose: + print " verifying worker hasn't exited" + self.assert_(not t.finished) + if verbose: + print " attempting to raise asynch exception in worker" + result = set_async_exc(ctypes.c_long(t.id), exception) + self.assertEqual(result, 1) # one thread state modified + if verbose: + print " waiting for worker to say it caught the exception" + worker_saw_exception.wait(timeout=10) + self.assert_(t.finished) + if verbose: + print " all OK -- joining worker" + if t.finished: + t.join() + # else the thread is still running, and we have no way to kill it + def test_main(): test.test_support.run_unittest(ThreadTests) diff --git a/Lib/test/test_threadsignals.py b/Lib/test/test_threadsignals.py index 51e3d97..1f10fe7 100644 --- a/Lib/test/test_threadsignals.py +++ b/Lib/test/test_threadsignals.py @@ -49,7 +49,7 @@ class ThreadSignals(unittest.TestCase): # and might be out of order.) If we haven't seen # the signals yet, send yet another signal and # wait for it return. - if signal_blackboard[signal.SIGUSR2]['tripped'] == 0 \ + if signal_blackboard[signal.SIGUSR1]['tripped'] == 0 \ or signal_blackboard[signal.SIGUSR2]['tripped'] == 0: signal.alarm(1) signal.pause() diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py index 4df854e..be7d0c8 100644 --- a/Lib/test/test_urllib2.py +++ b/Lib/test/test_urllib2.py @@ -46,6 +46,69 @@ class TrivialTests(unittest.TestCase): self.assertEquals(urllib2.parse_http_list(string), list) +def test_request_headers_dict(): + """ + The Request.headers dictionary is not a documented interface. It should + stay that way, because the complete set of headers are only accessible + through the .get_header(), .has_header(), .header_items() interface. + However, .headers pre-dates those methods, and so real code will be using + the dictionary. + + The introduction in 2.4 of those methods was a mistake for the same reason: + code that previously saw all (urllib2 user)-provided headers in .headers + now sees only a subset (and the function interface is ugly and incomplete). + A better change would have been to replace .headers dict with a dict + subclass (or UserDict.DictMixin instance?) that preserved the .headers + interface and also provided access to the "unredirected" headers. It's + probably too late to fix that, though. + + + Check .capitalize() case normalization: + + >>> url = "http://example.com" + >>> Request(url, headers={"Spam-eggs": "blah"}).headers["Spam-eggs"] + 'blah' + >>> Request(url, headers={"spam-EggS": "blah"}).headers["Spam-eggs"] + 'blah' + + Currently, Request(url, "Spam-eggs").headers["Spam-Eggs"] raises KeyError, + but that could be changed in future. + + """ + +def test_request_headers_methods(): + """ + Note the case normalization of header names here, to .capitalize()-case. + This should be preserved for backwards-compatibility. (In the HTTP case, + normalization to .title()-case is done by urllib2 before sending headers to + httplib). + + >>> url = "http://example.com" + >>> r = Request(url, headers={"Spam-eggs": "blah"}) + >>> r.has_header("Spam-eggs") + True + >>> r.header_items() + [('Spam-eggs', 'blah')] + >>> r.add_header("Foo-Bar", "baz") + >>> items = r.header_items() + >>> items.sort() + >>> items + [('Foo-bar', 'baz'), ('Spam-eggs', 'blah')] + + Note that e.g. r.has_header("spam-EggS") is currently False, and + r.get_header("spam-EggS") returns None, but that could be changed in + future. + + >>> r.has_header("Not-there") + False + >>> print r.get_header("Not-there") + None + >>> r.get_header("Not-there", "default") + 'default' + + """ + + def test_password_manager(self): """ >>> mgr = urllib2.HTTPPasswordMgr() @@ -676,11 +739,11 @@ class HandlerTests(unittest.TestCase): r = MockResponse(200, "OK", {}, "") newreq = h.do_request_(req) if data is None: # GET - self.assert_("Content-Length" not in req.unredirected_hdrs) - self.assert_("Content-Type" not in req.unredirected_hdrs) + self.assert_("Content-length" not in req.unredirected_hdrs) + self.assert_("Content-type" not in req.unredirected_hdrs) else: # POST - self.assertEqual(req.unredirected_hdrs["Content-Length"], "0") - self.assertEqual(req.unredirected_hdrs["Content-Type"], + self.assertEqual(req.unredirected_hdrs["Content-length"], "0") + self.assertEqual(req.unredirected_hdrs["Content-type"], "application/x-www-form-urlencoded") # XXX the details of Host could be better tested self.assertEqual(req.unredirected_hdrs["Host"], "example.com") @@ -692,8 +755,8 @@ class HandlerTests(unittest.TestCase): req.add_unredirected_header("Host", "baz") req.add_unredirected_header("Spam", "foo") newreq = h.do_request_(req) - self.assertEqual(req.unredirected_hdrs["Content-Length"], "foo") - self.assertEqual(req.unredirected_hdrs["Content-Type"], "bar") + self.assertEqual(req.unredirected_hdrs["Content-length"], "foo") + self.assertEqual(req.unredirected_hdrs["Content-type"], "bar") self.assertEqual(req.unredirected_hdrs["Host"], "baz") self.assertEqual(req.unredirected_hdrs["Spam"], "foo") @@ -847,7 +910,7 @@ class HandlerTests(unittest.TestCase): 407, 'Proxy-Authenticate: Basic realm="%s"\r\n\r\n' % realm) opener.add_handler(auth_handler) opener.add_handler(http_handler) - self._test_basic_auth(opener, auth_handler, "Proxy-Authorization", + self._test_basic_auth(opener, auth_handler, "Proxy-authorization", realm, http_handler, password_manager, "http://acme.example.com:3128/protected", "proxy.example.com:3128", diff --git a/Lib/test/test_uuid.py b/Lib/test/test_uuid.py index 0586cfd..90671be 100644 --- a/Lib/test/test_uuid.py +++ b/Lib/test/test_uuid.py @@ -16,12 +16,13 @@ class TestUUID(TestCase): def test_UUID(self): equal = self.assertEqual ascending = [] - for (string, curly, hex, bytes, fields, integer, urn, + for (string, curly, hex, bytes, bytes_le, fields, integer, urn, time, clock_seq, variant, version) in [ ('00000000-0000-0000-0000-000000000000', '{00000000-0000-0000-0000-000000000000}', '00000000000000000000000000000000', '\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0', + '\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0', (0, 0, 0, 0, 0, 0), 0, 'urn:uuid:00000000-0000-0000-0000-000000000000', @@ -30,6 +31,7 @@ class TestUUID(TestCase): '{00010203-0405-0607-0809-0a0b0c0d0e0f}', '000102030405060708090a0b0c0d0e0f', '\0\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\x0d\x0e\x0f', + '\x03\x02\x01\0\x05\x04\x07\x06\x08\t\n\x0b\x0c\x0d\x0e\x0f', (0x00010203L, 0x0405, 0x0607, 8, 9, 0x0a0b0c0d0e0fL), 0x000102030405060708090a0b0c0d0e0fL, 'urn:uuid:00010203-0405-0607-0809-0a0b0c0d0e0f', @@ -38,6 +40,7 @@ class TestUUID(TestCase): '{02d9e6d5-9467-382e-8f9b-9300a64ac3cd}', '02d9e6d59467382e8f9b9300a64ac3cd', '\x02\xd9\xe6\xd5\x94\x67\x38\x2e\x8f\x9b\x93\x00\xa6\x4a\xc3\xcd', + '\xd5\xe6\xd9\x02\x67\x94\x2e\x38\x8f\x9b\x93\x00\xa6\x4a\xc3\xcd', (0x02d9e6d5L, 0x9467, 0x382e, 0x8f, 0x9b, 0x9300a64ac3cdL), 0x02d9e6d59467382e8f9b9300a64ac3cdL, 'urn:uuid:02d9e6d5-9467-382e-8f9b-9300a64ac3cd', @@ -46,6 +49,7 @@ class TestUUID(TestCase): '{12345678-1234-5678-1234-567812345678}', '12345678123456781234567812345678', '\x12\x34\x56\x78'*4, + '\x78\x56\x34\x12\x34\x12\x78\x56\x12\x34\x56\x78\x12\x34\x56\x78', (0x12345678, 0x1234, 0x5678, 0x12, 0x34, 0x567812345678), 0x12345678123456781234567812345678, 'urn:uuid:12345678-1234-5678-1234-567812345678', @@ -54,6 +58,7 @@ class TestUUID(TestCase): '{6ba7b810-9dad-11d1-80b4-00c04fd430c8}', '6ba7b8109dad11d180b400c04fd430c8', '\x6b\xa7\xb8\x10\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8', + '\x10\xb8\xa7\x6b\xad\x9d\xd1\x11\x80\xb4\x00\xc0\x4f\xd4\x30\xc8', (0x6ba7b810L, 0x9dad, 0x11d1, 0x80, 0xb4, 0x00c04fd430c8L), 0x6ba7b8109dad11d180b400c04fd430c8L, 'urn:uuid:6ba7b810-9dad-11d1-80b4-00c04fd430c8', @@ -62,6 +67,7 @@ class TestUUID(TestCase): '{6ba7b811-9dad-11d1-80b4-00c04fd430c8}', '6ba7b8119dad11d180b400c04fd430c8', '\x6b\xa7\xb8\x11\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8', + '\x11\xb8\xa7\x6b\xad\x9d\xd1\x11\x80\xb4\x00\xc0\x4f\xd4\x30\xc8', (0x6ba7b811L, 0x9dad, 0x11d1, 0x80, 0xb4, 0x00c04fd430c8L), 0x6ba7b8119dad11d180b400c04fd430c8L, 'urn:uuid:6ba7b811-9dad-11d1-80b4-00c04fd430c8', @@ -70,6 +76,7 @@ class TestUUID(TestCase): '{6ba7b812-9dad-11d1-80b4-00c04fd430c8}', '6ba7b8129dad11d180b400c04fd430c8', '\x6b\xa7\xb8\x12\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8', + '\x12\xb8\xa7\x6b\xad\x9d\xd1\x11\x80\xb4\x00\xc0\x4f\xd4\x30\xc8', (0x6ba7b812L, 0x9dad, 0x11d1, 0x80, 0xb4, 0x00c04fd430c8L), 0x6ba7b8129dad11d180b400c04fd430c8L, 'urn:uuid:6ba7b812-9dad-11d1-80b4-00c04fd430c8', @@ -78,6 +85,7 @@ class TestUUID(TestCase): '{6ba7b814-9dad-11d1-80b4-00c04fd430c8}', '6ba7b8149dad11d180b400c04fd430c8', '\x6b\xa7\xb8\x14\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8', + '\x14\xb8\xa7\x6b\xad\x9d\xd1\x11\x80\xb4\x00\xc0\x4f\xd4\x30\xc8', (0x6ba7b814L, 0x9dad, 0x11d1, 0x80, 0xb4, 0x00c04fd430c8L), 0x6ba7b8149dad11d180b400c04fd430c8L, 'urn:uuid:6ba7b814-9dad-11d1-80b4-00c04fd430c8', @@ -86,6 +94,7 @@ class TestUUID(TestCase): '{7d444840-9dc0-11d1-b245-5ffdce74fad2}', '7d4448409dc011d1b2455ffdce74fad2', '\x7d\x44\x48\x40\x9d\xc0\x11\xd1\xb2\x45\x5f\xfd\xce\x74\xfa\xd2', + '\x40\x48\x44\x7d\xc0\x9d\xd1\x11\xb2\x45\x5f\xfd\xce\x74\xfa\xd2', (0x7d444840L, 0x9dc0, 0x11d1, 0xb2, 0x45, 0x5ffdce74fad2L), 0x7d4448409dc011d1b2455ffdce74fad2L, 'urn:uuid:7d444840-9dc0-11d1-b245-5ffdce74fad2', @@ -94,6 +103,7 @@ class TestUUID(TestCase): '{e902893a-9d22-3c7e-a7b8-d6e313b71d9f}', 'e902893a9d223c7ea7b8d6e313b71d9f', '\xe9\x02\x89\x3a\x9d\x22\x3c\x7e\xa7\xb8\xd6\xe3\x13\xb7\x1d\x9f', + '\x3a\x89\x02\xe9\x22\x9d\x7e\x3c\xa7\xb8\xd6\xe3\x13\xb7\x1d\x9f', (0xe902893aL, 0x9d22, 0x3c7e, 0xa7, 0xb8, 0xd6e313b71d9fL), 0xe902893a9d223c7ea7b8d6e313b71d9fL, 'urn:uuid:e902893a-9d22-3c7e-a7b8-d6e313b71d9f', @@ -102,6 +112,7 @@ class TestUUID(TestCase): '{eb424026-6f54-4ef8-a4d0-bb658a1fc6cf}', 'eb4240266f544ef8a4d0bb658a1fc6cf', '\xeb\x42\x40\x26\x6f\x54\x4e\xf8\xa4\xd0\xbb\x65\x8a\x1f\xc6\xcf', + '\x26\x40\x42\xeb\x54\x6f\xf8\x4e\xa4\xd0\xbb\x65\x8a\x1f\xc6\xcf', (0xeb424026L, 0x6f54, 0x4ef8, 0xa4, 0xd0, 0xbb658a1fc6cfL), 0xeb4240266f544ef8a4d0bb658a1fc6cfL, 'urn:uuid:eb424026-6f54-4ef8-a4d0-bb658a1fc6cf', @@ -110,6 +121,7 @@ class TestUUID(TestCase): '{f81d4fae-7dec-11d0-a765-00a0c91e6bf6}', 'f81d4fae7dec11d0a76500a0c91e6bf6', '\xf8\x1d\x4f\xae\x7d\xec\x11\xd0\xa7\x65\x00\xa0\xc9\x1e\x6b\xf6', + '\xae\x4f\x1d\xf8\xec\x7d\xd0\x11\xa7\x65\x00\xa0\xc9\x1e\x6b\xf6', (0xf81d4faeL, 0x7dec, 0x11d0, 0xa7, 0x65, 0x00a0c91e6bf6L), 0xf81d4fae7dec11d0a76500a0c91e6bf6L, 'urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6', @@ -118,6 +130,7 @@ class TestUUID(TestCase): '{fffefdfc-fffe-fffe-fffe-fffefdfcfbfa}', 'fffefdfcfffefffefffefffefdfcfbfa', '\xff\xfe\xfd\xfc\xff\xfe\xff\xfe\xff\xfe\xff\xfe\xfd\xfc\xfb\xfa', + '\xfc\xfd\xfe\xff\xfe\xff\xfe\xff\xff\xfe\xff\xfe\xfd\xfc\xfb\xfa', (0xfffefdfcL, 0xfffe, 0xfffe, 0xff, 0xfe, 0xfffefdfcfbfaL), 0xfffefdfcfffefffefffefffefdfcfbfaL, 'urn:uuid:fffefdfc-fffe-fffe-fffe-fffefdfcfbfa', @@ -126,6 +139,7 @@ class TestUUID(TestCase): '{ffffffff-ffff-ffff-ffff-ffffffffffff}', 'ffffffffffffffffffffffffffffffff', '\xff'*16, + '\xff'*16, (0xffffffffL, 0xffffL, 0xffffL, 0xff, 0xff, 0xffffffffffffL), 0xffffffffffffffffffffffffffffffffL, 'urn:uuid:ffffffff-ffff-ffff-ffff-ffffffffffff', @@ -134,12 +148,14 @@ class TestUUID(TestCase): equivalents = [] # Construct each UUID in several different ways. for u in [uuid.UUID(string), uuid.UUID(curly), uuid.UUID(hex), - uuid.UUID(bytes=bytes), uuid.UUID(fields=fields), - uuid.UUID(int=integer), uuid.UUID(urn)]: + uuid.UUID(bytes=bytes), uuid.UUID(bytes_le=bytes_le), + uuid.UUID(fields=fields), uuid.UUID(int=integer), + uuid.UUID(urn)]: # Test all conversions and properties of the UUID object. equal(str(u), string) equal(int(u), integer) equal(u.bytes, bytes) + equal(u.bytes_le, bytes_le) equal(u.fields, fields) equal(u.time_low, fields[0]) equal(u.time_mid, fields[1]) @@ -189,6 +205,11 @@ class TestUUID(TestCase): badvalue(lambda: uuid.UUID(bytes='\0'*15)) badvalue(lambda: uuid.UUID(bytes='\0'*17)) + # Badly formed bytes_le. + badvalue(lambda: uuid.UUID(bytes_le='abc')) + badvalue(lambda: uuid.UUID(bytes_le='\0'*15)) + badvalue(lambda: uuid.UUID(bytes_le='\0'*17)) + # Badly formed fields. badvalue(lambda: uuid.UUID(fields=(1,))) badvalue(lambda: uuid.UUID(fields=(1, 2, 3, 4, 5))) @@ -221,51 +242,43 @@ class TestUUID(TestCase): uuid.UUID(h) uuid.UUID(hex=h) uuid.UUID(bytes=b) + uuid.UUID(bytes_le=b) uuid.UUID(fields=f) uuid.UUID(int=i) # Wrong number of arguments (positional). badtype(lambda: uuid.UUID()) badtype(lambda: uuid.UUID(h, b)) - badtype(lambda: uuid.UUID(h, b, f)) - badtype(lambda: uuid.UUID(h, b, f, i)) - - # Duplicate arguments (named). - badtype(lambda: uuid.UUID(hex=h, bytes=b)) - badtype(lambda: uuid.UUID(hex=h, fields=f)) - badtype(lambda: uuid.UUID(hex=h, int=i)) - badtype(lambda: uuid.UUID(bytes=b, fields=f)) - badtype(lambda: uuid.UUID(bytes=b, int=i)) - badtype(lambda: uuid.UUID(fields=f, int=i)) - badtype(lambda: uuid.UUID(hex=h, bytes=b, fields=f)) - badtype(lambda: uuid.UUID(hex=h, bytes=b, int=i)) - badtype(lambda: uuid.UUID(hex=h, fields=f, int=i)) - badtype(lambda: uuid.UUID(bytes=b, int=i, fields=f)) - badtype(lambda: uuid.UUID(hex=h, bytes=b, int=i, fields=f)) - - # Duplicate arguments (positional and named). - badtype(lambda: uuid.UUID(h, hex=h)) - badtype(lambda: uuid.UUID(h, bytes=b)) - badtype(lambda: uuid.UUID(h, fields=f)) - badtype(lambda: uuid.UUID(h, int=i)) - badtype(lambda: uuid.UUID(h, hex=h, bytes=b)) - badtype(lambda: uuid.UUID(h, hex=h, fields=f)) - badtype(lambda: uuid.UUID(h, hex=h, int=i)) - badtype(lambda: uuid.UUID(h, bytes=b, fields=f)) - badtype(lambda: uuid.UUID(h, bytes=b, int=i)) - badtype(lambda: uuid.UUID(h, fields=f, int=i)) - badtype(lambda: uuid.UUID(h, hex=h, bytes=b, fields=f)) - badtype(lambda: uuid.UUID(h, hex=h, bytes=b, int=i)) - badtype(lambda: uuid.UUID(h, hex=h, fields=f, int=i)) - badtype(lambda: uuid.UUID(h, bytes=b, int=i, fields=f)) - badtype(lambda: uuid.UUID(h, hex=h, bytes=b, int=i, fields=f)) + badtype(lambda: uuid.UUID(h, b, b)) + badtype(lambda: uuid.UUID(h, b, b, f)) + badtype(lambda: uuid.UUID(h, b, b, f, i)) + + # Duplicate arguments. + for hh in [[], [('hex', h)]]: + for bb in [[], [('bytes', b)]]: + for bble in [[], [('bytes_le', b)]]: + for ii in [[], [('int', i)]]: + for ff in [[], [('fields', f)]]: + args = dict(hh + bb + bble + ii + ff) + if len(args) != 0: + badtype(lambda: uuid.UUID(h, **args)) + if len(args) != 1: + badtype(lambda: uuid.UUID(**args)) # Immutability. u = uuid.UUID(h) badtype(lambda: setattr(u, 'hex', h)) badtype(lambda: setattr(u, 'bytes', b)) + badtype(lambda: setattr(u, 'bytes_le', b)) badtype(lambda: setattr(u, 'fields', f)) badtype(lambda: setattr(u, 'int', i)) + badtype(lambda: setattr(u, 'time_low', 0)) + badtype(lambda: setattr(u, 'time_mid', 0)) + badtype(lambda: setattr(u, 'time_hi_version', 0)) + badtype(lambda: setattr(u, 'time_hi_version', 0)) + badtype(lambda: setattr(u, 'clock_seq_hi_variant', 0)) + badtype(lambda: setattr(u, 'clock_seq_low', 0)) + badtype(lambda: setattr(u, 'node', 0)) def check_node(self, node, source): individual_group_bit = (node >> 40L) & 1 @@ -356,11 +369,17 @@ class TestUUID(TestCase): def test_uuid1(self): equal = self.assertEqual - # Make sure uuid4() generates UUIDs that are actually version 1. + # Make sure uuid1() generates UUIDs that are actually version 1. for u in [uuid.uuid1() for i in range(10)]: equal(u.variant, uuid.RFC_4122) equal(u.version, 1) + # Make sure the generated UUIDs are actually unique. + uuids = {} + for u in [uuid.uuid1() for i in range(1000)]: + uuids[u] = 1 + equal(len(uuids.keys()), 1000) + # Make sure the supplied node ID appears in the UUID. u = uuid.uuid1(0) equal(u.node, 0) @@ -408,6 +427,12 @@ class TestUUID(TestCase): equal(u.variant, uuid.RFC_4122) equal(u.version, 4) + # Make sure the generated UUIDs are actually unique. + uuids = {} + for u in [uuid.uuid4() for i in range(1000)]: + uuids[u] = 1 + equal(len(uuids.keys()), 1000) + def test_uuid5(self): equal = self.assertEqual diff --git a/Lib/test/test_xml_etree_c.py b/Lib/test/test_xml_etree_c.py index 56e7fed..250f791 100644 --- a/Lib/test/test_xml_etree_c.py +++ b/Lib/test/test_xml_etree_c.py @@ -204,6 +204,17 @@ def check_encoding(encoding): "<?xml version='1.0' encoding='%s'?><xml />" % encoding ) +def bug_1534630(): + """ + >>> bob = ET.TreeBuilder() + >>> e = bob.data("data") + >>> e = bob.start("tag", {}) + >>> e = bob.end("tag") + >>> e = bob.close() + >>> serialize(ET, e) + '<tag />' + """ + def test_main(): from test import test_xml_etree_c test_support.run_doctest(test_xml_etree_c, verbosity=True) |