summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorThomas Wouters <thomas@python.org>2006-06-08 15:35:45 (GMT)
committerThomas Wouters <thomas@python.org>2006-06-08 15:35:45 (GMT)
commit73e5a5b65d66f4fba9c4f626bcd6400f4a7215e6 (patch)
tree206b2ca44cf23af41ac27cb7b3744f2e60a3341d /Lib/test
parent1ba5b3b425e970ec3e4a19165475aa68fa5ac893 (diff)
downloadcpython-73e5a5b65d66f4fba9c4f626bcd6400f4a7215e6.zip
cpython-73e5a5b65d66f4fba9c4f626bcd6400f4a7215e6.tar.gz
cpython-73e5a5b65d66f4fba9c4f626bcd6400f4a7215e6.tar.bz2
Merge the rest of the trunk.
Merged revisions 46490-46494,46496,46498,46500,46506,46521,46538,46558,46563-46567,46570-46571,46583,46593,46595-46598,46604,46606,46609-46753 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r46610 | martin.v.loewis | 2006-06-03 09:42:26 +0200 (Sat, 03 Jun 2006) | 2 lines Updated version (win32-icons2.zip) from #1490384. ........ r46612 | andrew.kuchling | 2006-06-03 20:09:41 +0200 (Sat, 03 Jun 2006) | 1 line [Bug #1472084] Fix description of do_tag ........ r46614 | andrew.kuchling | 2006-06-03 20:33:35 +0200 (Sat, 03 Jun 2006) | 1 line [Bug #1475554] Strengthen text to say 'must' instead of 'should' ........ r46616 | andrew.kuchling | 2006-06-03 20:41:28 +0200 (Sat, 03 Jun 2006) | 1 line [Bug #1441864] Clarify description of 'data' argument ........ r46617 | andrew.kuchling | 2006-06-03 20:43:24 +0200 (Sat, 03 Jun 2006) | 1 line Minor rewording ........ r46619 | andrew.kuchling | 2006-06-03 21:02:35 +0200 (Sat, 03 Jun 2006) | 9 lines [Bug #1497414] _self is a reserved word in the WATCOM 10.6 C compiler. Fix by renaming the variable. In a different module, Neal fixed it by renaming _self to self. There's already a variable named 'self' here, so I used selfptr. (I'm committing this on a Mac without Tk, but it's a simple search-and-replace. <crosses fingers>, so I'll watch the buildbots and see what happens.) ........ r46621 | fredrik.lundh | 2006-06-03 23:56:05 +0200 (Sat, 03 Jun 2006) | 5 lines "_self" is a said to be a reserved word in Watcom C 10.6. I'm not sure that's really standard compliant behaviour, but I guess we have to fix that anyway... ........ r46622 | andrew.kuchling | 2006-06-04 00:44:42 +0200 (Sun, 04 Jun 2006) | 1 line Update readme ........ r46623 | andrew.kuchling | 2006-06-04 00:59:23 +0200 (Sun, 04 Jun 2006) | 1 line Drop 0 parameter ........ r46624 | andrew.kuchling | 2006-06-04 00:59:59 +0200 (Sun, 04 Jun 2006) | 1 line Some code tidying; use curses.wrapper ........ r46625 | andrew.kuchling | 2006-06-04 01:02:15 +0200 (Sun, 04 Jun 2006) | 1 line Use True; value returned from main is unused ........ r46626 | andrew.kuchling | 2006-06-04 01:07:21 +0200 (Sun, 04 Jun 2006) | 1 line Use true division, and the True value ........ r46627 | andrew.kuchling | 2006-06-04 01:09:58 +0200 (Sun, 04 Jun 2006) | 1 line Docstring fix; use True ........ r46628 | andrew.kuchling | 2006-06-04 01:15:56 +0200 (Sun, 04 Jun 2006) | 1 line Put code in a main() function; loosen up the spacing to match current code style ........ r46629 | andrew.kuchling | 2006-06-04 01:39:07 +0200 (Sun, 04 Jun 2006) | 1 line Use functions; modernize code ........ r46630 | andrew.kuchling | 2006-06-04 01:43:22 +0200 (Sun, 04 Jun 2006) | 1 line This demo requires Medusa (not just asyncore); remove it ........ r46631 | andrew.kuchling | 2006-06-04 01:46:36 +0200 (Sun, 04 Jun 2006) | 2 lines Remove xmlrpc demo -- it duplicates the SimpleXMLRPCServer module. ........ r46632 | andrew.kuchling | 2006-06-04 01:47:22 +0200 (Sun, 04 Jun 2006) | 1 line Remove xmlrpc/ directory ........ r46633 | andrew.kuchling | 2006-06-04 01:51:21 +0200 (Sun, 04 Jun 2006) | 1 line Remove dangling reference ........ r46634 | andrew.kuchling | 2006-06-04 01:59:36 +0200 (Sun, 04 Jun 2006) | 1 line Add more whitespace; use a better socket name ........ r46635 | tim.peters | 2006-06-04 03:22:53 +0200 (Sun, 04 Jun 2006) | 2 lines Whitespace normalization. ........ r46637 | tim.peters | 2006-06-04 05:26:02 +0200 (Sun, 04 Jun 2006) | 16 lines In a PYMALLOC_DEBUG build obmalloc adds extra debugging info to each allocated block. This was using 4 bytes for each such piece of info regardless of platform. This didn't really matter before (proof: no bug reports, and the debug-build obmalloc would have assert-failed if it was ever asked for a chunk of memory >= 2**32 bytes), since container indices were plain ints. But after the Py_ssize_t changes, it's at least theoretically possible to allocate a list or string whose guts exceed 2**32 bytes, and the PYMALLOC_DEBUG routines would fail then (having only 4 bytes to record the originally requested size). Now we use sizeof(size_t) bytes for each of a PYMALLOC_DEBUG build's extra debugging fields. This won't make any difference on 32-bit boxes, but will add 16 bytes to each allocation in a debug build on a 64-bit box. ........ r46638 | tim.peters | 2006-06-04 05:38:04 +0200 (Sun, 04 Jun 2006) | 4 lines _PyObject_DebugMalloc(): The return value should add 2*sizeof(size_t) now, not 8. This probably accounts for current disasters on the 64-bit buildbot slaves. ........ r46639 | neal.norwitz | 2006-06-04 08:19:31 +0200 (Sun, 04 Jun 2006) | 1 line SF #1499797, Fix for memory leak in WindowsError_str ........ r46640 | andrew.macintyre | 2006-06-04 14:31:09 +0200 (Sun, 04 Jun 2006) | 2 lines Patch #1454481: Make thread stack size runtime tunable. ........ r46641 | andrew.macintyre | 2006-06-04 14:59:59 +0200 (Sun, 04 Jun 2006) | 2 lines clean up function declarations to conform to PEP-7 style. ........ r46642 | martin.blais | 2006-06-04 15:49:49 +0200 (Sun, 04 Jun 2006) | 15 lines Fixes in struct and socket from merge reviews. - Following Guido's comments, renamed * pack_to -> pack_into * recv_buf -> recv_into * recvfrom_buf -> recvfrom_into - Made fixes to _struct.c according to Neal Norwitz comments on the checkins list. - Converted some ints into the appropriate -- I hope -- ssize_t and size_t. ........ r46643 | ronald.oussoren | 2006-06-04 16:05:28 +0200 (Sun, 04 Jun 2006) | 3 lines "Import" LDFLAGS in Mac/OSX/Makefile.in to ensure pythonw gets build with the right compiler flags. ........ r46644 | ronald.oussoren | 2006-06-04 16:24:59 +0200 (Sun, 04 Jun 2006) | 2 lines Drop Mac wrappers for the WASTE library. ........ r46645 | tim.peters | 2006-06-04 17:49:07 +0200 (Sun, 04 Jun 2006) | 3 lines s_methods[]: Stop compiler warnings by casting s_unpack_from to PyCFunction. ........ r46646 | george.yoshida | 2006-06-04 19:04:12 +0200 (Sun, 04 Jun 2006) | 2 lines Remove a redundant word ........ r46647 | george.yoshida | 2006-06-04 19:17:25 +0200 (Sun, 04 Jun 2006) | 2 lines Markup fix ........ r46648 | martin.v.loewis | 2006-06-04 21:36:28 +0200 (Sun, 04 Jun 2006) | 2 lines Patch #1359618: Speed-up charmap encoder. ........ r46649 | georg.brandl | 2006-06-04 23:46:16 +0200 (Sun, 04 Jun 2006) | 3 lines Repair refleaks in unicodeobject. ........ r46650 | georg.brandl | 2006-06-04 23:56:52 +0200 (Sun, 04 Jun 2006) | 4 lines Patch #1346214: correctly optimize away "if 0"-style stmts (thanks to Neal for review) ........ r46651 | georg.brandl | 2006-06-05 00:15:37 +0200 (Mon, 05 Jun 2006) | 2 lines Bug #1500293: fix memory leaks in _subprocess module. ........ r46654 | tim.peters | 2006-06-05 01:43:53 +0200 (Mon, 05 Jun 2006) | 2 lines Whitespace normalization. ........ r46655 | tim.peters | 2006-06-05 01:52:47 +0200 (Mon, 05 Jun 2006) | 16 lines Revert revisions: 46640 Patch #1454481: Make thread stack size runtime tunable. 46647 Markup fix The first is causing many buildbots to fail test runs, and there are multiple causes with seemingly no immediate prospects for repairing them. See python-dev discussion. Note that a branch can (and should) be created for resolving these problems, like svn copy svn+ssh://svn.python.org/python/trunk -r46640 svn+ssh://svn.python.org/python/branches/NEW_BRANCH followed by merging rev 46647 to the new branch. ........ r46656 | andrew.kuchling | 2006-06-05 02:08:09 +0200 (Mon, 05 Jun 2006) | 1 line Mention second encoding speedup ........ r46657 | gregory.p.smith | 2006-06-05 02:31:01 +0200 (Mon, 05 Jun 2006) | 7 lines bugfix: when log_archive was called with the DB_ARCH_REMOVE flag present in BerkeleyDB >= 4.2 it tried to construct a list out of an uninitialized char **log_list. feature: export the DB_ARCH_REMOVE flag by name in the module on BerkeleyDB >= 4.2. ........ r46658 | gregory.p.smith | 2006-06-05 02:33:35 +0200 (Mon, 05 Jun 2006) | 5 lines fix a bug in the previous commit. don't leak empty list on error return and fix the additional rare (out of memory only) bug that it was supposed to fix of not freeing log_list when the python allocator failed. ........ r46660 | tim.peters | 2006-06-05 02:55:26 +0200 (Mon, 05 Jun 2006) | 9 lines "Flat is better than nested." Move the long-winded, multiply-nested -R support out of runtest() and into some module-level helper functions. This makes runtest() and the -R code easier to follow. That in turn allowed seeing some opportunities for code simplification, and made it obvious that reglog.txt never got closed. ........ r46661 | hyeshik.chang | 2006-06-05 02:59:54 +0200 (Mon, 05 Jun 2006) | 3 lines Fix a potentially invalid memory access of CJKCodecs' shift-jis decoder. (found by Neal Norwitz) ........ r46663 | gregory.p.smith | 2006-06-05 03:39:52 +0200 (Mon, 05 Jun 2006) | 3 lines * support DBEnv.log_stat() method on BerkeleyDB >= 4.0 [patch #1494885] ........ r46664 | tim.peters | 2006-06-05 03:43:03 +0200 (Mon, 05 Jun 2006) | 3 lines Remove doctest.testmod's deprecated (in 2.4) `isprivate` argument. A lot of hair went into supporting that! ........ r46665 | tim.peters | 2006-06-05 03:47:24 +0200 (Mon, 05 Jun 2006) | 2 lines Whitespace normalization. ........ r46666 | tim.peters | 2006-06-05 03:48:21 +0200 (Mon, 05 Jun 2006) | 2 lines Make doctest news more accurate. ........ r46667 | gregory.p.smith | 2006-06-05 03:56:15 +0200 (Mon, 05 Jun 2006) | 3 lines * support DBEnv.lsn_reset() method on BerkeleyDB >= 4.4 [patch #1494902] ........ r46668 | gregory.p.smith | 2006-06-05 04:02:25 +0200 (Mon, 05 Jun 2006) | 3 lines mention the just committed bsddb changes ........ r46671 | gregory.p.smith | 2006-06-05 19:38:04 +0200 (Mon, 05 Jun 2006) | 3 lines * add support for DBSequence objects [patch #1466734] ........ r46672 | gregory.p.smith | 2006-06-05 20:20:07 +0200 (Mon, 05 Jun 2006) | 3 lines forgot to add this file in previous commit ........ r46673 | tim.peters | 2006-06-05 20:36:12 +0200 (Mon, 05 Jun 2006) | 2 lines Whitespace normalization. ........ r46674 | tim.peters | 2006-06-05 20:36:54 +0200 (Mon, 05 Jun 2006) | 2 lines Add missing svn:eol-style property to text files. ........ r46675 | gregory.p.smith | 2006-06-05 20:48:21 +0200 (Mon, 05 Jun 2006) | 4 lines * fix DBCursor.pget() bug with keyword argument names when no data= is supplied [SF pybsddb bug #1477863] ........ r46676 | andrew.kuchling | 2006-06-05 21:05:32 +0200 (Mon, 05 Jun 2006) | 1 line Remove use of Trove name, which isn't very helpful to users ........ r46677 | andrew.kuchling | 2006-06-05 21:08:25 +0200 (Mon, 05 Jun 2006) | 1 line [Bug #1470026] Include link to list of classifiers ........ r46679 | tim.peters | 2006-06-05 22:48:49 +0200 (Mon, 05 Jun 2006) | 10 lines Access _struct attributes directly instead of mucking with getattr. string_reverse(): Simplify. assertRaises(): Raise TestFailed on failure. test_unpack_from(), test_pack_into(), test_pack_into_fn(): never use `assert` to test for an expected result (it doesn't test anything when Python is run with -O). ........ r46680 | tim.peters | 2006-06-05 22:49:27 +0200 (Mon, 05 Jun 2006) | 2 lines Add missing svn:eol-style property to text files. ........ r46681 | gregory.p.smith | 2006-06-06 01:38:06 +0200 (Tue, 06 Jun 2006) | 3 lines add depends = ['md5.h'] to the _md5 module extension for correctness sake. ........ r46682 | brett.cannon | 2006-06-06 01:51:55 +0200 (Tue, 06 Jun 2006) | 4 lines Add 3 more bytes to a buffer to cover constants in string and null byte on top of 10 possible digits for an int. Closes bug #1501223. ........ r46684 | gregory.p.smith | 2006-06-06 01:59:37 +0200 (Tue, 06 Jun 2006) | 5 lines - bsddb: the __len__ method of a DB object has been fixed to return correct results. It could previously incorrectly return 0 in some cases. Fixes SF bug 1493322 (pybsddb bug 1184012). ........ r46686 | tim.peters | 2006-06-06 02:25:07 +0200 (Tue, 06 Jun 2006) | 7 lines _PySys_Init(): It's rarely a good idea to size a buffer to the exact maximum size someone guesses is needed. In this case, if we're really worried about extreme integers, then "cp%d" can actually need 14 bytes (2 for "cp" + 1 for \0 at the end + 11 for -(2**31-1)). So reserve 128 bytes instead -- nothing is actually saved by making a stack-local buffer tiny. ........ r46687 | neal.norwitz | 2006-06-06 09:22:08 +0200 (Tue, 06 Jun 2006) | 1 line Remove unused variable (and stop compiler warning) ........ r46688 | neal.norwitz | 2006-06-06 09:23:01 +0200 (Tue, 06 Jun 2006) | 1 line Fix a bunch of parameter strings ........ r46689 | thomas.heller | 2006-06-06 13:34:33 +0200 (Tue, 06 Jun 2006) | 6 lines Convert CFieldObject tp_members to tp_getset, since there is no structmember typecode for Py_ssize_t fields. This should fix some of the errors on the PPC64 debian machine (64-bit, big endian). Assigning to readonly fields now raises AttributeError instead of TypeError, so the testcase has to be changed as well. ........ r46690 | thomas.heller | 2006-06-06 13:54:32 +0200 (Tue, 06 Jun 2006) | 1 line Damn - the sentinel was missing. And fix another silly mistake. ........ r46691 | martin.blais | 2006-06-06 14:46:55 +0200 (Tue, 06 Jun 2006) | 13 lines Normalized a few cases of whitespace in function declarations. Found them using:: find . -name '*.py' | while read i ; do grep 'def[^(]*( ' $i /dev/null ; done find . -name '*.py' | while read i ; do grep ' ):' $i /dev/null ; done (I was doing this all over my own code anyway, because I'd been using spaces in all defs, so I thought I'd make a run on the Python code as well. If you need to do such fixes in your own code, you can use xx-rename or parenregu.el within emacs.) ........ r46693 | thomas.heller | 2006-06-06 17:34:18 +0200 (Tue, 06 Jun 2006) | 1 line Specify argtypes for all test functions. Maybe that helps on strange ;-) architectures ........ r46694 | tim.peters | 2006-06-06 17:50:17 +0200 (Tue, 06 Jun 2006) | 5 lines BSequence_set_range(): Rev 46688 ("Fix a bunch of parameter strings") changed this function's signature seemingly by mistake, which is causing buildbots to fail test_bsddb3. Restored the pre-46688 signature. ........ r46695 | tim.peters | 2006-06-06 17:52:35 +0200 (Tue, 06 Jun 2006) | 4 lines On python-dev Thomas Heller said these were committed by mistake in rev 46693, so reverting this part of rev 46693. ........ r46696 | andrew.kuchling | 2006-06-06 19:10:41 +0200 (Tue, 06 Jun 2006) | 1 line Fix comment typo ........ r46697 | brett.cannon | 2006-06-06 20:08:16 +0200 (Tue, 06 Jun 2006) | 2 lines Fix coding style guide bug. ........ r46698 | thomas.heller | 2006-06-06 20:50:46 +0200 (Tue, 06 Jun 2006) | 2 lines Add a hack so that foreign functions returning float now do work on 64-bit big endian platforms. ........ r46699 | thomas.heller | 2006-06-06 21:25:13 +0200 (Tue, 06 Jun 2006) | 3 lines Use the same big-endian hack as in _ctypes/callproc.c for callback functions. This fixes the callback function tests that return float. ........ r46700 | ronald.oussoren | 2006-06-06 21:50:24 +0200 (Tue, 06 Jun 2006) | 5 lines * Ensure that "make altinstall" works when the tree was configured with --enable-framework * Also for --enable-framework: allow users to use --prefix to specify the location of the compatibility symlinks (such as /usr/local/bin/python) ........ r46701 | ronald.oussoren | 2006-06-06 21:56:00 +0200 (Tue, 06 Jun 2006) | 3 lines A quick hack to ensure the right key-bindings for IDLE on osx: install patched configuration files during a framework install. ........ r46702 | tim.peters | 2006-06-07 03:04:59 +0200 (Wed, 07 Jun 2006) | 4 lines dash_R_cleanup(): Clear filecmp._cache. This accounts for different results across -R runs (at least on Windows) of test_filecmp. ........ r46705 | tim.peters | 2006-06-07 08:57:51 +0200 (Wed, 07 Jun 2006) | 17 lines SF patch 1501987: Remove randomness from test_exceptions, from ?iga Seilnacht (sorry about the name, but Firefox on my box can't display the first character of the name -- the SF "Unix name" is zseil). This appears to cure the oddball intermittent leaks across runs when running test_exceptions under -R. I'm not sure why, but I'm too sleepy to care ;-) The thrust of the SF patch was to remove randomness in the pickle protocol used. I changed the patch to use range(pickle.HIGHEST_PROTOCOL + 1), to try both pickle and cPickle, and randomly mucked with other test lines to put statements on their own lines. Not a bugfix candidate (this is fiddling new-in-2.5 code). ........ r46706 | andrew.kuchling | 2006-06-07 15:55:33 +0200 (Wed, 07 Jun 2006) | 1 line Add an SQLite introduction, taken from the 'What's New' text ........ r46708 | andrew.kuchling | 2006-06-07 19:02:52 +0200 (Wed, 07 Jun 2006) | 1 line Mention other placeholders ........ r46709 | andrew.kuchling | 2006-06-07 19:03:46 +0200 (Wed, 07 Jun 2006) | 1 line Add an item; also, escape % ........ r46710 | andrew.kuchling | 2006-06-07 19:04:01 +0200 (Wed, 07 Jun 2006) | 1 line Mention other placeholders ........ r46716 | ronald.oussoren | 2006-06-07 20:57:44 +0200 (Wed, 07 Jun 2006) | 2 lines Move Mac/OSX/Tools one level up ........ r46717 | ronald.oussoren | 2006-06-07 20:58:01 +0200 (Wed, 07 Jun 2006) | 2 lines Move Mac/OSX/PythonLauncher one level up ........ r46718 | ronald.oussoren | 2006-06-07 20:58:42 +0200 (Wed, 07 Jun 2006) | 2 lines mv Mac/OSX/BuildScript one level up ........ r46719 | ronald.oussoren | 2006-06-07 21:02:03 +0200 (Wed, 07 Jun 2006) | 2 lines Move Mac/OSX/* one level up ........ r46720 | ronald.oussoren | 2006-06-07 21:06:01 +0200 (Wed, 07 Jun 2006) | 2 lines And the last bit: move IDLE one level up and adjust makefiles ........ r46723 | ronald.oussoren | 2006-06-07 21:38:53 +0200 (Wed, 07 Jun 2006) | 4 lines - Patch the correct version of python in the Info.plists at build time, instead of relying on a maintainer to update them before releases. - Remove the now empty Mac/OSX directory ........ r46727 | ronald.oussoren | 2006-06-07 22:18:44 +0200 (Wed, 07 Jun 2006) | 7 lines * If BuildApplet.py is used as an applet it starts with a version of sys.exutable that isn't usuable on an #!-line. That results in generated applets that don't actually work. Work around this problem by resetting sys.executable. * argvemulator.py didn't work on intel macs. This patch fixes this (bug #1491468) ........ r46728 | tim.peters | 2006-06-07 22:40:06 +0200 (Wed, 07 Jun 2006) | 2 lines Whitespace normalization. ........ r46729 | tim.peters | 2006-06-07 22:40:54 +0200 (Wed, 07 Jun 2006) | 2 lines Add missing svn:eol-style property to text files. ........ r46730 | thomas.heller | 2006-06-07 22:43:06 +0200 (Wed, 07 Jun 2006) | 7 lines Fix for foreign functions returning small structures on 64-bit big endian machines. Should fix the remaininf failure in the PPC64 Debian buildbot. Thanks to Matthias Klose for providing access to a machine to debug and test this. ........ r46731 | brett.cannon | 2006-06-07 23:48:17 +0200 (Wed, 07 Jun 2006) | 2 lines Clarify documentation for bf_getcharbuffer. ........ r46735 | neal.norwitz | 2006-06-08 07:12:45 +0200 (Thu, 08 Jun 2006) | 1 line Fix a refleak in recvfrom_into ........ r46736 | gregory.p.smith | 2006-06-08 07:17:08 +0200 (Thu, 08 Jun 2006) | 9 lines - bsddb: the bsddb.dbtables Modify method now raises the proper error and aborts the db transaction safely when a modifier callback fails. Fixes SF python patch/bug #1408584. Also cleans up the bsddb.dbtables docstrings since thats the only documentation that exists for that unadvertised module. (people really should really just use sqlite3) ........ r46737 | gregory.p.smith | 2006-06-08 07:38:11 +0200 (Thu, 08 Jun 2006) | 4 lines * Turn the deadlock situation described in SF bug #775414 into a DBDeadLockError exception. * add the test case for my previous dbtables commit. ........ r46738 | gregory.p.smith | 2006-06-08 07:39:54 +0200 (Thu, 08 Jun 2006) | 2 lines pasted set_lk_detect line in wrong spot in previous commit. fixed. passes tests this time. ........ r46739 | armin.rigo | 2006-06-08 12:56:24 +0200 (Thu, 08 Jun 2006) | 6 lines (arre, arigo) SF bug #1350060 Give a consistent behavior for comparison and hashing of method objects (both user- and built-in methods). Now compares the 'self' recursively. The hash was already asking for the hash of 'self'. ........ r46740 | andrew.kuchling | 2006-06-08 13:56:44 +0200 (Thu, 08 Jun 2006) | 1 line Typo fix ........ r46741 | georg.brandl | 2006-06-08 14:45:01 +0200 (Thu, 08 Jun 2006) | 2 lines Bug #1502750: Fix getargs "i" format to use LONG_MIN and LONG_MAX for bounds checking. ........ r46743 | georg.brandl | 2006-06-08 14:54:13 +0200 (Thu, 08 Jun 2006) | 2 lines Bug #1502728: Correctly link against librt library on HP-UX. ........ r46745 | georg.brandl | 2006-06-08 14:55:47 +0200 (Thu, 08 Jun 2006) | 3 lines Add news for recent bugfix. ........ r46746 | georg.brandl | 2006-06-08 15:31:07 +0200 (Thu, 08 Jun 2006) | 4 lines Argh. "integer" is a very confusing word ;) Actually, checking for INT_MAX and INT_MIN is correct since the format code explicitly handles a C "int". ........ r46748 | nick.coghlan | 2006-06-08 15:54:49 +0200 (Thu, 08 Jun 2006) | 1 line Add functools.update_wrapper() and functools.wraps() as described in PEP 356 ........ r46751 | georg.brandl | 2006-06-08 16:50:21 +0200 (Thu, 08 Jun 2006) | 4 lines Bug #1502805: don't alias file.__exit__ to file.close since the latter can return something that's true. ........ r46752 | georg.brandl | 2006-06-08 16:50:53 +0200 (Thu, 08 Jun 2006) | 3 lines Convert test_file to unittest. ........
Diffstat (limited to 'Lib/test')
-rwxr-xr-xLib/test/regrtest.py133
-rw-r--r--Lib/test/test_bsddb3.py2
-rw-r--r--Lib/test/test_builtin.py2
-rw-r--r--Lib/test/test_class.py34
-rw-r--r--Lib/test/test_descr.py15
-rw-r--r--Lib/test/test_doctest.py57
-rw-r--r--Lib/test/test_exceptions.py49
-rw-r--r--Lib/test/test_file.py655
-rw-r--r--Lib/test/test_functools.py109
-rw-r--r--Lib/test/test_generators.py6
-rw-r--r--Lib/test/test_socket.py12
-rw-r--r--Lib/test/test_struct.py67
-rw-r--r--Lib/test/test_tempfile.py2
13 files changed, 627 insertions, 516 deletions
diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py
index 314e7e1..ca4a3b5 100755
--- a/Lib/test/regrtest.py
+++ b/Lib/test/regrtest.py
@@ -503,6 +503,7 @@ def runtest(test, generate, verbose, quiet, testdir=None, huntrleaks=False):
quiet -- if true, don't print 'skipped' messages (probably redundant)
testdir -- test directory
"""
+
test_support.unload(test)
if not testdir:
testdir = findtestdir()
@@ -512,11 +513,7 @@ def runtest(test, generate, verbose, quiet, testdir=None, huntrleaks=False):
cfp = None
else:
cfp = cStringIO.StringIO()
- if huntrleaks:
- if not hasattr(sys, 'gettotalrefcount'):
- raise Exception("Tracking reference leaks requires a debug build "
- "of Python")
- refrep = open(huntrleaks[2], "a")
+
try:
save_stdout = sys.stdout
try:
@@ -538,60 +535,7 @@ def runtest(test, generate, verbose, quiet, testdir=None, huntrleaks=False):
if indirect_test is not None:
indirect_test()
if huntrleaks:
- # This code *is* hackish and inelegant, yes.
- # But it seems to do the job.
- import copy_reg
- fs = warnings.filters[:]
- ps = copy_reg.dispatch_table.copy()
- pic = sys.path_importer_cache.copy()
- import gc
- def cleanup():
- import _strptime, linecache, warnings, dircache
- import urlparse, urllib, urllib2, mimetypes, doctest
- import struct
- from distutils.dir_util import _path_created
- _path_created.clear()
- warnings.filters[:] = fs
- gc.collect()
- re.purge()
- _strptime._regex_cache.clear()
- urlparse.clear_cache()
- urllib.urlcleanup()
- urllib2.install_opener(None)
- copy_reg.dispatch_table.clear()
- copy_reg.dispatch_table.update(ps)
- sys.path_importer_cache.clear()
- sys.path_importer_cache.update(pic)
- dircache.reset()
- linecache.clearcache()
- mimetypes._default_mime_types()
- struct._cache.clear()
- doctest.master = None
- if indirect_test:
- def run_the_test():
- indirect_test()
- else:
- def run_the_test():
- reload(the_module)
- deltas = []
- repcount = huntrleaks[0] + huntrleaks[1]
- print >> sys.stderr, "beginning", repcount, "repetitions"
- print >> sys.stderr, \
- ("1234567890"*(repcount//10 + 1))[:repcount]
- cleanup()
- for i in range(repcount):
- rc = sys.gettotalrefcount()
- run_the_test()
- sys.stderr.write('.')
- cleanup()
- deltas.append(sys.gettotalrefcount() - rc - 2)
- print >>sys.stderr
- if max(map(abs, deltas[-huntrleaks[1]:])) > 0:
- print >>sys.stderr, test, 'leaked', \
- deltas[-huntrleaks[1]:], 'references'
- print >>refrep, test, 'leaked', \
- deltas[-huntrleaks[1]:], 'references'
- # The end of the huntrleaks hackishness.
+ dash_R(the_module, test, indirect_test, huntrleaks)
finally:
sys.stdout = save_stdout
except test_support.ResourceDenied, msg:
@@ -651,6 +595,77 @@ def runtest(test, generate, verbose, quiet, testdir=None, huntrleaks=False):
sys.stdout.flush()
return 0
+def dash_R(the_module, test, indirect_test, huntrleaks):
+ # This code is hackish and inelegant, but it seems to do the job.
+ import copy_reg
+
+ if not hasattr(sys, 'gettotalrefcount'):
+ raise Exception("Tracking reference leaks requires a debug build "
+ "of Python")
+
+ # Save current values for dash_R_cleanup() to restore.
+ fs = warnings.filters[:]
+ ps = copy_reg.dispatch_table.copy()
+ pic = sys.path_importer_cache.copy()
+
+ if indirect_test:
+ def run_the_test():
+ indirect_test()
+ else:
+ def run_the_test():
+ reload(the_module)
+
+ deltas = []
+ nwarmup, ntracked, fname = huntrleaks
+ repcount = nwarmup + ntracked
+ print >> sys.stderr, "beginning", repcount, "repetitions"
+ print >> sys.stderr, ("1234567890"*(repcount//10 + 1))[:repcount]
+ dash_R_cleanup(fs, ps, pic)
+ for i in range(repcount):
+ rc = sys.gettotalrefcount()
+ run_the_test()
+ sys.stderr.write('.')
+ dash_R_cleanup(fs, ps, pic)
+ if i >= nwarmup:
+ deltas.append(sys.gettotalrefcount() - rc - 2)
+ print >> sys.stderr
+ if any(deltas):
+ print >> sys.stderr, test, 'leaked', deltas, 'references'
+ refrep = open(fname, "a")
+ print >> refrep, test, 'leaked', deltas, 'references'
+ refrep.close()
+
+def dash_R_cleanup(fs, ps, pic):
+ import gc, copy_reg
+ import _strptime, linecache, warnings, dircache
+ import urlparse, urllib, urllib2, mimetypes, doctest
+ import struct, filecmp
+ from distutils.dir_util import _path_created
+
+ # Restore some original values.
+ warnings.filters[:] = fs
+ copy_reg.dispatch_table.clear()
+ copy_reg.dispatch_table.update(ps)
+ sys.path_importer_cache.clear()
+ sys.path_importer_cache.update(pic)
+
+ # Clear assorted module caches.
+ _path_created.clear()
+ re.purge()
+ _strptime._regex_cache.clear()
+ urlparse.clear_cache()
+ urllib.urlcleanup()
+ urllib2.install_opener(None)
+ dircache.reset()
+ linecache.clearcache()
+ mimetypes._default_mime_types()
+ struct._cache.clear()
+ filecmp._cache.clear()
+ doctest.master = None
+
+ # Collect cyclic trash.
+ gc.collect()
+
def reportdiff(expected, output):
import difflib
print "*" * 70
diff --git a/Lib/test/test_bsddb3.py b/Lib/test/test_bsddb3.py
index 2d1bff7..8b0c50c 100644
--- a/Lib/test/test_bsddb3.py
+++ b/Lib/test/test_bsddb3.py
@@ -44,6 +44,8 @@ def suite():
'test_queue',
'test_recno',
'test_thread',
+ 'test_sequence',
+ 'test_cursor_pget_bug',
]
alltests = unittest.TestSuite()
diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py
index 71e2b0a..e6e4440 100644
--- a/Lib/test/test_builtin.py
+++ b/Lib/test/test_builtin.py
@@ -336,7 +336,7 @@ class BuiltinTest(unittest.TestCase):
_cells = {}
def __setitem__(self, key, formula):
self._cells[key] = formula
- def __getitem__(self, key ):
+ def __getitem__(self, key):
return eval(self._cells[key], globals(), self)
ss = SpreadSheet()
diff --git a/Lib/test/test_class.py b/Lib/test/test_class.py
index 601b8b4..d872357 100644
--- a/Lib/test/test_class.py
+++ b/Lib/test/test_class.py
@@ -363,3 +363,37 @@ except AttributeError, x:
pass
else:
print "attribute error for I.__init__ got masked"
+
+
+# Test comparison and hash of methods
+class A:
+ def __init__(self, x):
+ self.x = x
+ def f(self):
+ pass
+ def g(self):
+ pass
+ def __eq__(self, other):
+ return self.x == other.x
+ def __hash__(self):
+ return self.x
+class B(A):
+ pass
+
+a1 = A(1)
+a2 = A(2)
+assert a1.f == a1.f
+assert a1.f != a2.f
+assert a1.f != a1.g
+assert a1.f == A(1).f
+assert hash(a1.f) == hash(a1.f)
+assert hash(a1.f) == hash(A(1).f)
+
+assert A.f != a1.f
+assert A.f != A.g
+assert B.f == A.f
+assert hash(B.f) == hash(A.f)
+
+# the following triggers a SystemError in 2.4
+a = A(hash(A.f.im_func)^(-1))
+hash(a.f)
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index 89cebb0..8ee431b 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -3866,11 +3866,24 @@ def methodwrapper():
l = []
vereq(l.__add__, l.__add__)
- verify(l.__add__ != [].__add__)
+ vereq(l.__add__, [].__add__)
+ verify(l.__add__ != [5].__add__)
+ verify(l.__add__ != l.__mul__)
verify(l.__add__.__name__ == '__add__')
verify(l.__add__.__self__ is l)
verify(l.__add__.__objclass__ is list)
vereq(l.__add__.__doc__, list.__add__.__doc__)
+ try:
+ hash(l.__add__)
+ except TypeError:
+ pass
+ else:
+ raise TestFailed("no TypeError from hash([].__add__)")
+
+ t = ()
+ t += (7,)
+ vereq(t.__add__, (7,).__add__)
+ vereq(hash(t.__add__), hash((7,).__add__))
def notimplemented():
# all binary methods should be able to return a NotImplemented
diff --git a/Lib/test/test_doctest.py b/Lib/test/test_doctest.py
index 92d2d74..01f7acd 100644
--- a/Lib/test/test_doctest.py
+++ b/Lib/test/test_doctest.py
@@ -512,15 +512,11 @@ will only be generated for it once:
>>> tests[1].name.split('.')[-1] in ['f', 'g']
True
-Filter Functions
-~~~~~~~~~~~~~~~~
-A filter function can be used to restrict which objects get examined,
-but this is temporary, undocumented internal support for testmod's
-deprecated isprivate gimmick.
-
- >>> def namefilter(prefix, base):
- ... return base.startswith('a_')
- >>> tests = doctest.DocTestFinder(_namefilter=namefilter).find(SampleClass)
+Empty Tests
+~~~~~~~~~~~
+By default, an object with no doctests doesn't create any tests:
+
+ >>> tests = doctest.DocTestFinder().find(SampleClass)
>>> tests.sort()
>>> for t in tests:
... print '%2s %s' % (len(t.examples), t.name)
@@ -528,6 +524,9 @@ deprecated isprivate gimmick.
3 SampleClass.NestedClass
1 SampleClass.NestedClass.__init__
1 SampleClass.__init__
+ 2 SampleClass.a_classmethod
+ 1 SampleClass.a_property
+ 1 SampleClass.a_staticmethod
1 SampleClass.double
1 SampleClass.get
@@ -536,8 +535,7 @@ tells it to include (empty) tests for objects with no doctests. This feature
is really to support backward compatibility in what doctest.master.summarize()
displays.
- >>> tests = doctest.DocTestFinder(_namefilter=namefilter,
- ... exclude_empty=False).find(SampleClass)
+ >>> tests = doctest.DocTestFinder(exclude_empty=False).find(SampleClass)
>>> tests.sort()
>>> for t in tests:
... print '%2s %s' % (len(t.examples), t.name)
@@ -547,35 +545,12 @@ displays.
0 SampleClass.NestedClass.get
0 SampleClass.NestedClass.square
1 SampleClass.__init__
- 1 SampleClass.double
- 1 SampleClass.get
-
-If a given object is filtered out, then none of the objects that it
-contains will be added either:
-
- >>> def namefilter(prefix, base):
- ... return base == 'NestedClass'
- >>> tests = doctest.DocTestFinder(_namefilter=namefilter).find(SampleClass)
- >>> tests.sort()
- >>> for t in tests:
- ... print '%2s %s' % (len(t.examples), t.name)
- 3 SampleClass
- 1 SampleClass.__init__
2 SampleClass.a_classmethod
1 SampleClass.a_property
1 SampleClass.a_staticmethod
1 SampleClass.double
1 SampleClass.get
-The filter function apply to contained objects, and *not* to the
-object explicitly passed to DocTestFinder:
-
- >>> def namefilter(prefix, base):
- ... return base == 'SampleClass'
- >>> tests = doctest.DocTestFinder(_namefilter=namefilter).find(SampleClass)
- >>> len(tests)
- 9
-
Turning off Recursion
~~~~~~~~~~~~~~~~~~~~~
DocTestFinder can be told not to look for tests in contained objects
@@ -1913,20 +1888,6 @@ def test_DocTestSuite():
modified the test globals, which are a copy of the
sample_doctest module dictionary. The test globals are
automatically cleared for us after a test.
-
- Finally, you can provide an alternate test finder. Here we'll
- use a custom test_finder to to run just the test named bar.
- However, the test in the module docstring, and the two tests
- in the module __test__ dict, aren't filtered, so we actually
- run three tests besides bar's. The filtering mechanisms are
- poorly conceived, and will go away someday.
-
- >>> finder = doctest.DocTestFinder(
- ... _namefilter=lambda prefix, base: base!='bar')
- >>> suite = doctest.DocTestSuite('test.sample_doctest',
- ... test_finder=finder)
- >>> suite.run(unittest.TestResult())
- <unittest.TestResult run=4 errors=0 failures=1>
"""
def test_DocFileSuite():
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py
index ebab913..ebe60c1 100644
--- a/Lib/test/test_exceptions.py
+++ b/Lib/test/test_exceptions.py
@@ -1,9 +1,12 @@
# Python test set -- part 5, built-in exceptions
-from test.test_support import TESTFN, unlink, run_unittest
-import warnings
-import sys, traceback, os
+import os
+import sys
import unittest
+import warnings
+import pickle, cPickle
+
+from test.test_support import TESTFN, unlink, run_unittest
# XXX This is not really enough, each *operation* should be tested!
@@ -191,11 +194,15 @@ class ExceptionTests(unittest.TestCase):
def testAttributes(self):
# test that exception attributes are happy
- try: str(u'Hello \u00E1')
- except Exception, e: sampleUnicodeEncodeError = e
+ try:
+ str(u'Hello \u00E1')
+ except Exception, e:
+ sampleUnicodeEncodeError = e
- try: unicode('\xff')
- except Exception, e: sampleUnicodeDecodeError = e
+ try:
+ unicode('\xff')
+ except Exception, e:
+ sampleUnicodeDecodeError = e
exceptionList = [
(BaseException, (), {'message' : '', 'args' : ()}),
@@ -260,19 +267,20 @@ class ExceptionTests(unittest.TestCase):
'strerror' : 'strErrorStr', 'winerror' : 1,
'errno' : 22, 'filename' : 'filenameStr'})
)
- except NameError: pass
-
- import pickle, random
+ except NameError:
+ pass
for args in exceptionList:
expected = args[-1]
try:
exc = args[0]
- if len(args) == 2: raise exc
- else: raise exc(*args[1])
+ if len(args) == 2:
+ raise exc
+ else:
+ raise exc(*args[1])
except BaseException, e:
if (e is not exc and # needed for sampleUnicode errors
- type(e) is not exc):
+ type(e) is not exc):
raise
# Verify no ref leaks in Exc_str()
s = str(e)
@@ -283,12 +291,15 @@ class ExceptionTests(unittest.TestCase):
(repr(e), checkArgName))
# test for pickling support
- new = pickle.loads(pickle.dumps(e, random.randint(0, 2)))
- for checkArgName in expected:
- self.assertEquals(repr(getattr(e, checkArgName)),
- repr(expected[checkArgName]),
- 'pickled exception "%s", attribute "%s' %
- (repr(e), checkArgName))
+ for p in pickle, cPickle:
+ for protocol in range(p.HIGHEST_PROTOCOL + 1):
+ new = p.loads(p.dumps(e, protocol))
+ for checkArgName in expected:
+ got = repr(getattr(new, checkArgName))
+ want = repr(expected[checkArgName])
+ self.assertEquals(got, want,
+ 'pickled "%r", attribute "%s' %
+ (e, checkArgName))
def testKeywordArgs(self):
# test that builtin exception don't take keyword args,
diff --git a/Lib/test/test_file.py b/Lib/test/test_file.py
index ca1c6ba..dcfa265 100644
--- a/Lib/test/test_file.py
+++ b/Lib/test/test_file.py
@@ -1,356 +1,325 @@
import sys
import os
+import unittest
from array import array
from weakref import proxy
-from test.test_support import verify, TESTFN, TestFailed, findfile
+from test.test_support import TESTFN, findfile, run_unittest
from UserList import UserList
-# verify weak references
-f = file(TESTFN, 'w')
-p = proxy(f)
-p.write('teststring')
-verify(f.tell(), p.tell())
-f.close()
-f = None
-try:
- p.tell()
-except ReferenceError:
- pass
-else:
- raise TestFailed('file proxy still exists when the file is gone')
-
-# verify expected attributes exist
-f = file(TESTFN, 'w')
-softspace = f.softspace
-f.name # merely shouldn't blow up
-f.mode # ditto
-f.closed # ditto
-
-# verify softspace is writable
-f.softspace = softspace # merely shouldn't blow up
-
-# verify the others aren't
-for attr in 'name', 'mode', 'closed':
- try:
- setattr(f, attr, 'oops')
- except (AttributeError, TypeError):
- pass
- else:
- raise TestFailed('expected exception setting file attr %r' % attr)
-f.close()
-
-# check invalid mode strings
-for mode in ("", "aU", "wU+"):
- try:
- f = file(TESTFN, mode)
- except ValueError:
- pass
- else:
- f.close()
- raise TestFailed('%r is an invalid file mode' % mode)
-
-# verify writelines with instance sequence
-l = UserList(['1', '2'])
-f = open(TESTFN, 'wb')
-f.writelines(l)
-f.close()
-f = open(TESTFN, 'rb')
-buf = f.read()
-f.close()
-verify(buf == '12')
-
-# verify readinto
-a = array('c', 'x'*10)
-f = open(TESTFN, 'rb')
-n = f.readinto(a)
-f.close()
-verify(buf == a.tostring()[:n])
-
-# verify readinto refuses text files
-a = array('c', 'x'*10)
-f = open(TESTFN, 'r')
-try:
- f.readinto(a)
- raise TestFailed("readinto shouldn't work in text mode")
-except TypeError:
- pass
-finally:
- f.close()
-
-# verify writelines with integers
-f = open(TESTFN, 'wb')
-try:
- f.writelines([1, 2, 3])
-except TypeError:
- pass
-else:
- print "writelines accepted sequence of integers"
-f.close()
-
-# verify writelines with integers in UserList
-f = open(TESTFN, 'wb')
-l = UserList([1,2,3])
-try:
- f.writelines(l)
-except TypeError:
- pass
-else:
- print "writelines accepted sequence of integers"
-f.close()
-
-# verify writelines with non-string object
-class NonString: pass
-
-f = open(TESTFN, 'wb')
-try:
- f.writelines([NonString(), NonString()])
-except TypeError:
- pass
-else:
- print "writelines accepted sequence of non-string objects"
-f.close()
-
-# This causes the interpreter to exit on OSF1 v5.1.
-if sys.platform != 'osf1V5':
- try:
- sys.stdin.seek(-1)
- except IOError:
- pass
- else:
- print "should not be able to seek on sys.stdin"
-else:
- print >>sys.__stdout__, (
- ' Skipping sys.stdin.seek(-1), it may crash the interpreter.'
- ' Test manually.')
-
-try:
- sys.stdin.truncate()
-except IOError:
- pass
-else:
- print "should not be able to truncate on sys.stdin"
-
-# verify repr works
-f = open(TESTFN)
-if not repr(f).startswith("<open file '" + TESTFN):
- print "repr(file) failed"
-f.close()
-
-# verify repr works for unicode too
-f = open(unicode(TESTFN))
-if not repr(f).startswith("<open file u'" + TESTFN):
- print "repr(file with unicode name) failed"
-f.close()
-
-# verify that we get a sensible error message for bad mode argument
-bad_mode = "qwerty"
-try:
- open(TESTFN, bad_mode)
-except ValueError, msg:
- if msg[0] != 0:
- s = str(msg)
- if s.find(TESTFN) != -1 or s.find(bad_mode) == -1:
- print "bad error message for invalid mode: %s" % s
- # if msg[0] == 0, we're probably on Windows where there may be
- # no obvious way to discover why open() failed.
-else:
- print "no error for invalid mode: %s" % bad_mode
-
-f = open(TESTFN)
-if f.name != TESTFN:
- raise TestFailed, 'file.name should be "%s"' % TESTFN
-if f.isatty():
- raise TestFailed, 'file.isatty() should be false'
-
-if f.closed:
- raise TestFailed, 'file.closed should be false'
-
-try:
- f.readinto("")
-except TypeError:
- pass
-else:
- raise TestFailed, 'file.readinto("") should raise a TypeError'
-
-f.close()
-if not f.closed:
- raise TestFailed, 'file.closed should be true'
-
-# make sure that explicitly setting the buffer size doesn't cause
-# misbehaviour especially with repeated close() calls
-for s in (-1, 0, 1, 512):
- try:
- f = open(TESTFN, 'w', s)
- f.write(str(s))
- f.close()
- f.close()
- f = open(TESTFN, 'r', s)
- d = int(f.read())
- f.close()
- f.close()
- except IOError, msg:
- raise TestFailed, 'error setting buffer size %d: %s' % (s, str(msg))
- if d != s:
- raise TestFailed, 'readback failure using buffer size %d'
-
-methods = ['fileno', 'flush', 'isatty', 'next', 'read', 'readinto',
- 'readline', 'readlines', 'seek', 'tell', 'truncate', 'write',
- '__iter__']
-if sys.platform.startswith('atheos'):
- methods.remove('truncate')
-
-for methodname in methods:
- method = getattr(f, methodname)
- try:
- method()
- except ValueError:
- pass
- else:
- raise TestFailed, 'file.%s() on a closed file should raise a ValueError' % methodname
-
-try:
- f.writelines([])
-except ValueError:
- pass
-else:
- raise TestFailed, 'file.writelines([]) on a closed file should raise a ValueError'
-
-os.unlink(TESTFN)
-
-def bug801631():
- # SF bug <http://www.python.org/sf/801631>
- # "file.truncate fault on windows"
- f = file(TESTFN, 'wb')
- f.write('12345678901') # 11 bytes
- f.close()
-
- f = file(TESTFN,'rb+')
- data = f.read(5)
- if data != '12345':
- raise TestFailed("Read on file opened for update failed %r" % data)
- if f.tell() != 5:
- raise TestFailed("File pos after read wrong %d" % f.tell())
-
- f.truncate()
- if f.tell() != 5:
- raise TestFailed("File pos after ftruncate wrong %d" % f.tell())
-
- f.close()
- size = os.path.getsize(TESTFN)
- if size != 5:
- raise TestFailed("File size after ftruncate wrong %d" % size)
-
-try:
- bug801631()
-finally:
- os.unlink(TESTFN)
-
-# Test the complex interaction when mixing file-iteration and the various
-# read* methods. Ostensibly, the mixture could just be tested to work
-# when it should work according to the Python language, instead of fail
-# when it should fail according to the current CPython implementation.
-# People don't always program Python the way they should, though, and the
-# implemenation might change in subtle ways, so we explicitly test for
-# errors, too; the test will just have to be updated when the
-# implementation changes.
-dataoffset = 16384
-filler = "ham\n"
-assert not dataoffset % len(filler), \
- "dataoffset must be multiple of len(filler)"
-nchunks = dataoffset // len(filler)
-testlines = [
- "spam, spam and eggs\n",
- "eggs, spam, ham and spam\n",
- "saussages, spam, spam and eggs\n",
- "spam, ham, spam and eggs\n",
- "spam, spam, spam, spam, spam, ham, spam\n",
- "wonderful spaaaaaam.\n"
-]
-methods = [("readline", ()), ("read", ()), ("readlines", ()),
- ("readinto", (array("c", " "*100),))]
-
-try:
- # Prepare the testfile
- bag = open(TESTFN, "wb")
- bag.write(filler * nchunks)
- bag.writelines(testlines)
- bag.close()
- # Test for appropriate errors mixing read* and iteration
- for methodname, args in methods:
- f = open(TESTFN, 'rb')
- if f.next() != filler:
- raise TestFailed, "Broken testfile"
- meth = getattr(f, methodname)
+class AutoFileTests(unittest.TestCase):
+ # file tests for which a test file is automatically set up
+
+ def setUp(self):
+ self.f = file(TESTFN, 'wb')
+
+ def tearDown(self):
try:
- meth(*args)
- except ValueError:
+ if self.f:
+ self.f.close()
+ except IOError:
pass
+
+ def testWeakRefs(self):
+ # verify weak references
+ p = proxy(self.f)
+ p.write('teststring')
+ self.assertEquals(self.f.tell(), p.tell())
+ self.f.close()
+ self.f = None
+ self.assertRaises(ReferenceError, getattr, p, 'tell')
+
+ def testAttributes(self):
+ # verify expected attributes exist
+ f = self.f
+ softspace = f.softspace
+ f.name # merely shouldn't blow up
+ f.mode # ditto
+ f.closed # ditto
+
+ # verify softspace is writable
+ f.softspace = softspace # merely shouldn't blow up
+
+ # verify the others aren't
+ for attr in 'name', 'mode', 'closed':
+ self.assertRaises((AttributeError, TypeError), setattr, f, attr, 'oops')
+
+ def testReadinto(self):
+ # verify readinto
+ self.f.write('12')
+ self.f.close()
+ a = array('c', 'x'*10)
+ self.f = open(TESTFN, 'rb')
+ n = self.f.readinto(a)
+ self.assertEquals('12', a.tostring()[:n])
+
+ def testReadinto_text(self):
+ # verify readinto refuses text files
+ a = array('c', 'x'*10)
+ self.f.close()
+ self.f = open(TESTFN, 'r')
+ self.assertRaises(TypeError, self.f.readinto, a)
+
+ def testWritelinesUserList(self):
+ # verify writelines with instance sequence
+ l = UserList(['1', '2'])
+ self.f.writelines(l)
+ self.f.close()
+ self.f = open(TESTFN, 'rb')
+ buf = self.f.read()
+ self.assertEquals(buf, '12')
+
+ def testWritelinesIntegers(self):
+ # verify writelines with integers
+ self.assertRaises(TypeError, self.f.writelines, [1, 2, 3])
+
+ def testWritelinesIntegersUserList(self):
+ # verify writelines with integers in UserList
+ l = UserList([1,2,3])
+ self.assertRaises(TypeError, self.f.writelines, l)
+
+ def testWritelinesNonString(self):
+ # verify writelines with non-string object
+ class NonString: pass
+
+ self.assertRaises(TypeError, self.f.writelines, [NonString(), NonString()])
+
+ def testRepr(self):
+ # verify repr works
+ self.assert_(repr(self.f).startswith("<open file '" + TESTFN))
+
+ def testErrors(self):
+ f = self.f
+ self.assertEquals(f.name, TESTFN)
+ self.assert_(not f.isatty())
+ self.assert_(not f.closed)
+
+ self.assertRaises(TypeError, f.readinto, "")
+ f.close()
+ self.assert_(f.closed)
+
+ def testMethods(self):
+ methods = ['fileno', 'flush', 'isatty', 'next', 'read', 'readinto',
+ 'readline', 'readlines', 'seek', 'tell', 'truncate', 'write',
+ '__iter__']
+ if sys.platform.startswith('atheos'):
+ methods.remove('truncate')
+
+ self.f.close()
+
+ for methodname in methods:
+ method = getattr(self.f, methodname)
+ # should raise on closed file
+ self.assertRaises(ValueError, method)
+ self.assertRaises(ValueError, self.f.writelines, [])
+
+
+class OtherFileTests(unittest.TestCase):
+
+ def testModeStrings(self):
+ # check invalid mode strings
+ for mode in ("", "aU", "wU+"):
+ try:
+ f = file(TESTFN, mode)
+ except ValueError:
+ pass
+ else:
+ f.close()
+ self.fail('%r is an invalid file mode' % mode)
+
+ def testStdin(self):
+ # This causes the interpreter to exit on OSF1 v5.1.
+ if sys.platform != 'osf1V5':
+ self.assertRaises(IOError, sys.stdin.seek, -1)
else:
- raise TestFailed("%s%r after next() didn't raise ValueError" %
- (methodname, args))
+ print >>sys.__stdout__, (
+ ' Skipping sys.stdin.seek(-1), it may crash the interpreter.'
+ ' Test manually.')
+ self.assertRaises(IOError, sys.stdin.truncate)
+
+ def testUnicodeOpen(self):
+ # verify repr works for unicode too
+ f = open(unicode(TESTFN), "w")
+ self.assert_(repr(f).startswith("<open file u'" + TESTFN))
f.close()
- # Test to see if harmless (by accident) mixing of read* and iteration
- # still works. This depends on the size of the internal iteration
- # buffer (currently 8192,) but we can test it in a flexible manner.
- # Each line in the bag o' ham is 4 bytes ("h", "a", "m", "\n"), so
- # 4096 lines of that should get us exactly on the buffer boundary for
- # any power-of-2 buffersize between 4 and 16384 (inclusive).
- f = open(TESTFN, 'rb')
- for i in range(nchunks):
- f.next()
- testline = testlines.pop(0)
- try:
- line = f.readline()
- except ValueError:
- raise TestFailed("readline() after next() with supposedly empty "
- "iteration-buffer failed anyway")
- if line != testline:
- raise TestFailed("readline() after next() with empty buffer "
- "failed. Got %r, expected %r" % (line, testline))
- testline = testlines.pop(0)
- buf = array("c", "\x00" * len(testline))
- try:
- f.readinto(buf)
- except ValueError:
- raise TestFailed("readinto() after next() with supposedly empty "
- "iteration-buffer failed anyway")
- line = buf.tostring()
- if line != testline:
- raise TestFailed("readinto() after next() with empty buffer "
- "failed. Got %r, expected %r" % (line, testline))
-
- testline = testlines.pop(0)
- try:
- line = f.read(len(testline))
- except ValueError:
- raise TestFailed("read() after next() with supposedly empty "
- "iteration-buffer failed anyway")
- if line != testline:
- raise TestFailed("read() after next() with empty buffer "
- "failed. Got %r, expected %r" % (line, testline))
- try:
- lines = f.readlines()
- except ValueError:
- raise TestFailed("readlines() after next() with supposedly empty "
- "iteration-buffer failed anyway")
- if lines != testlines:
- raise TestFailed("readlines() after next() with empty buffer "
- "failed. Got %r, expected %r" % (line, testline))
- # Reading after iteration hit EOF shouldn't hurt either
- f = open(TESTFN, 'rb')
- try:
- for line in f:
- pass
+ def testBadModeArgument(self):
+ # verify that we get a sensible error message for bad mode argument
+ bad_mode = "qwerty"
try:
- f.readline()
- f.readinto(buf)
- f.read()
- f.readlines()
- except ValueError:
- raise TestFailed("read* failed after next() consumed file")
- finally:
- f.close()
-finally:
- os.unlink(TESTFN)
+ f = open(TESTFN, bad_mode)
+ except ValueError, msg:
+ if msg[0] != 0:
+ s = str(msg)
+ if s.find(TESTFN) != -1 or s.find(bad_mode) == -1:
+ self.fail("bad error message for invalid mode: %s" % s)
+ # if msg[0] == 0, we're probably on Windows where there may be
+ # no obvious way to discover why open() failed.
+ else:
+ f.close()
+ self.fail("no error for invalid mode: %s" % bad_mode)
+
+ def testSetBufferSize(self):
+ # make sure that explicitly setting the buffer size doesn't cause
+ # misbehaviour especially with repeated close() calls
+ for s in (-1, 0, 1, 512):
+ try:
+ f = open(TESTFN, 'w', s)
+ f.write(str(s))
+ f.close()
+ f.close()
+ f = open(TESTFN, 'r', s)
+ d = int(f.read())
+ f.close()
+ f.close()
+ except IOError, msg:
+ self.fail('error setting buffer size %d: %s' % (s, str(msg)))
+ self.assertEquals(d, s)
+
+ def testTruncateOnWindows(self):
+ os.unlink(TESTFN)
+
+ def bug801631():
+ # SF bug <http://www.python.org/sf/801631>
+ # "file.truncate fault on windows"
+ f = file(TESTFN, 'wb')
+ f.write('12345678901') # 11 bytes
+ f.close()
+
+ f = file(TESTFN,'rb+')
+ data = f.read(5)
+ if data != '12345':
+ self.fail("Read on file opened for update failed %r" % data)
+ if f.tell() != 5:
+ self.fail("File pos after read wrong %d" % f.tell())
+
+ f.truncate()
+ if f.tell() != 5:
+ self.fail("File pos after ftruncate wrong %d" % f.tell())
+
+ f.close()
+ size = os.path.getsize(TESTFN)
+ if size != 5:
+ self.fail("File size after ftruncate wrong %d" % size)
+
+ try:
+ bug801631()
+ finally:
+ os.unlink(TESTFN)
+
+ def testIteration(self):
+ # Test the complex interaction when mixing file-iteration and the various
+ # read* methods. Ostensibly, the mixture could just be tested to work
+ # when it should work according to the Python language, instead of fail
+ # when it should fail according to the current CPython implementation.
+ # People don't always program Python the way they should, though, and the
+ # implemenation might change in subtle ways, so we explicitly test for
+ # errors, too; the test will just have to be updated when the
+ # implementation changes.
+ dataoffset = 16384
+ filler = "ham\n"
+ assert not dataoffset % len(filler), \
+ "dataoffset must be multiple of len(filler)"
+ nchunks = dataoffset // len(filler)
+ testlines = [
+ "spam, spam and eggs\n",
+ "eggs, spam, ham and spam\n",
+ "saussages, spam, spam and eggs\n",
+ "spam, ham, spam and eggs\n",
+ "spam, spam, spam, spam, spam, ham, spam\n",
+ "wonderful spaaaaaam.\n"
+ ]
+ methods = [("readline", ()), ("read", ()), ("readlines", ()),
+ ("readinto", (array("c", " "*100),))]
+
+ try:
+ # Prepare the testfile
+ bag = open(TESTFN, "wb")
+ bag.write(filler * nchunks)
+ bag.writelines(testlines)
+ bag.close()
+ # Test for appropriate errors mixing read* and iteration
+ for methodname, args in methods:
+ f = open(TESTFN, 'rb')
+ if f.next() != filler:
+ self.fail, "Broken testfile"
+ meth = getattr(f, methodname)
+ try:
+ meth(*args)
+ except ValueError:
+ pass
+ else:
+ self.fail("%s%r after next() didn't raise ValueError" %
+ (methodname, args))
+ f.close()
+
+ # Test to see if harmless (by accident) mixing of read* and iteration
+ # still works. This depends on the size of the internal iteration
+ # buffer (currently 8192,) but we can test it in a flexible manner.
+ # Each line in the bag o' ham is 4 bytes ("h", "a", "m", "\n"), so
+ # 4096 lines of that should get us exactly on the buffer boundary for
+ # any power-of-2 buffersize between 4 and 16384 (inclusive).
+ f = open(TESTFN, 'rb')
+ for i in range(nchunks):
+ f.next()
+ testline = testlines.pop(0)
+ try:
+ line = f.readline()
+ except ValueError:
+ self.fail("readline() after next() with supposedly empty "
+ "iteration-buffer failed anyway")
+ if line != testline:
+ self.fail("readline() after next() with empty buffer "
+ "failed. Got %r, expected %r" % (line, testline))
+ testline = testlines.pop(0)
+ buf = array("c", "\x00" * len(testline))
+ try:
+ f.readinto(buf)
+ except ValueError:
+ self.fail("readinto() after next() with supposedly empty "
+ "iteration-buffer failed anyway")
+ line = buf.tostring()
+ if line != testline:
+ self.fail("readinto() after next() with empty buffer "
+ "failed. Got %r, expected %r" % (line, testline))
+
+ testline = testlines.pop(0)
+ try:
+ line = f.read(len(testline))
+ except ValueError:
+ self.fail("read() after next() with supposedly empty "
+ "iteration-buffer failed anyway")
+ if line != testline:
+ self.fail("read() after next() with empty buffer "
+ "failed. Got %r, expected %r" % (line, testline))
+ try:
+ lines = f.readlines()
+ except ValueError:
+ self.fail("readlines() after next() with supposedly empty "
+ "iteration-buffer failed anyway")
+ if lines != testlines:
+ self.fail("readlines() after next() with empty buffer "
+ "failed. Got %r, expected %r" % (line, testline))
+ # Reading after iteration hit EOF shouldn't hurt either
+ f = open(TESTFN, 'rb')
+ try:
+ for line in f:
+ pass
+ try:
+ f.readline()
+ f.readinto(buf)
+ f.read()
+ f.readlines()
+ except ValueError:
+ self.fail("read* failed after next() consumed file")
+ finally:
+ f.close()
+ finally:
+ os.unlink(TESTFN)
+
+
+def test_main():
+ run_unittest(AutoFileTests, OtherFileTests)
+
+if __name__ == '__main__':
+ test_main()
diff --git a/Lib/test/test_functools.py b/Lib/test/test_functools.py
index 609e8f4..8dc185b 100644
--- a/Lib/test/test_functools.py
+++ b/Lib/test/test_functools.py
@@ -152,6 +152,113 @@ class TestPythonPartial(TestPartial):
thetype = PythonPartial
+class TestUpdateWrapper(unittest.TestCase):
+
+ def check_wrapper(self, wrapper, wrapped,
+ assigned=functools.WRAPPER_ASSIGNMENTS,
+ updated=functools.WRAPPER_UPDATES):
+ # Check attributes were assigned
+ for name in assigned:
+ self.failUnless(getattr(wrapper, name) is getattr(wrapped, name))
+ # Check attributes were updated
+ for name in updated:
+ wrapper_attr = getattr(wrapper, name)
+ wrapped_attr = getattr(wrapped, name)
+ for key in wrapped_attr:
+ self.failUnless(wrapped_attr[key] is wrapper_attr[key])
+
+ def test_default_update(self):
+ def f():
+ """This is a test"""
+ pass
+ f.attr = 'This is also a test'
+ def wrapper():
+ pass
+ functools.update_wrapper(wrapper, f)
+ self.check_wrapper(wrapper, f)
+ self.assertEqual(wrapper.__name__, 'f')
+ self.assertEqual(wrapper.__doc__, 'This is a test')
+ self.assertEqual(wrapper.attr, 'This is also a test')
+
+ def test_no_update(self):
+ def f():
+ """This is a test"""
+ pass
+ f.attr = 'This is also a test'
+ def wrapper():
+ pass
+ functools.update_wrapper(wrapper, f, (), ())
+ self.check_wrapper(wrapper, f, (), ())
+ self.assertEqual(wrapper.__name__, 'wrapper')
+ self.assertEqual(wrapper.__doc__, None)
+ self.failIf(hasattr(wrapper, 'attr'))
+
+ def test_selective_update(self):
+ def f():
+ pass
+ f.attr = 'This is a different test'
+ f.dict_attr = dict(a=1, b=2, c=3)
+ def wrapper():
+ pass
+ wrapper.dict_attr = {}
+ assign = ('attr',)
+ update = ('dict_attr',)
+ functools.update_wrapper(wrapper, f, assign, update)
+ self.check_wrapper(wrapper, f, assign, update)
+ self.assertEqual(wrapper.__name__, 'wrapper')
+ self.assertEqual(wrapper.__doc__, None)
+ self.assertEqual(wrapper.attr, 'This is a different test')
+ self.assertEqual(wrapper.dict_attr, f.dict_attr)
+
+
+class TestWraps(TestUpdateWrapper):
+
+ def test_default_update(self):
+ def f():
+ """This is a test"""
+ pass
+ f.attr = 'This is also a test'
+ @functools.wraps(f)
+ def wrapper():
+ pass
+ self.check_wrapper(wrapper, f)
+ self.assertEqual(wrapper.__name__, 'f')
+ self.assertEqual(wrapper.__doc__, 'This is a test')
+ self.assertEqual(wrapper.attr, 'This is also a test')
+
+ def test_no_update(self):
+ def f():
+ """This is a test"""
+ pass
+ f.attr = 'This is also a test'
+ @functools.wraps(f, (), ())
+ def wrapper():
+ pass
+ self.check_wrapper(wrapper, f, (), ())
+ self.assertEqual(wrapper.__name__, 'wrapper')
+ self.assertEqual(wrapper.__doc__, None)
+ self.failIf(hasattr(wrapper, 'attr'))
+
+ def test_selective_update(self):
+ def f():
+ pass
+ f.attr = 'This is a different test'
+ f.dict_attr = dict(a=1, b=2, c=3)
+ def add_dict_attr(f):
+ f.dict_attr = {}
+ return f
+ assign = ('attr',)
+ update = ('dict_attr',)
+ @functools.wraps(f, assign, update)
+ @add_dict_attr
+ def wrapper():
+ pass
+ self.check_wrapper(wrapper, f, assign, update)
+ self.assertEqual(wrapper.__name__, 'wrapper')
+ self.assertEqual(wrapper.__doc__, None)
+ self.assertEqual(wrapper.attr, 'This is a different test')
+ self.assertEqual(wrapper.dict_attr, f.dict_attr)
+
def test_main(verbose=None):
@@ -160,6 +267,8 @@ def test_main(verbose=None):
TestPartial,
TestPartialSubclass,
TestPythonPartial,
+ TestUpdateWrapper,
+ TestWraps
)
test_support.run_unittest(*test_classes)
diff --git a/Lib/test/test_generators.py b/Lib/test/test_generators.py
index a60a768..a184a8b 100644
--- a/Lib/test/test_generators.py
+++ b/Lib/test/test_generators.py
@@ -733,7 +733,7 @@ syntax_tests = """
... yield 1
Traceback (most recent call last):
..
-SyntaxError: 'return' with argument inside generator (<doctest test.test_generators.__test__.syntax[0]>, line 2)
+SyntaxError: 'return' with argument inside generator (<doctest test.test_generators.__test__.syntax[0]>, line 3)
>>> def f():
... yield 1
@@ -876,9 +876,9 @@ These are fine:
... if 0:
... return 3 # but *this* sucks (line 8)
... if 0:
-... yield 2 # because it's a generator
+... yield 2 # because it's a generator (line 10)
Traceback (most recent call last):
-SyntaxError: 'return' with argument inside generator (<doctest test.test_generators.__test__.syntax[24]>, line 8)
+SyntaxError: 'return' with argument inside generator (<doctest test.test_generators.__test__.syntax[24]>, line 10)
This one caused a crash (see SF bug 567538):
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index 2246fb6..01b9b5b 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -860,25 +860,25 @@ class BufferIOTest(SocketConnectedTest):
def __init__(self, methodName='runTest'):
SocketConnectedTest.__init__(self, methodName=methodName)
- def testRecvBuf(self):
+ def testRecvInto(self):
buf = array.array('c', ' '*1024)
- nbytes = self.cli_conn.recv_buf(buf)
+ nbytes = self.cli_conn.recv_into(buf)
self.assertEqual(nbytes, len(MSG))
msg = buf.tostring()[:len(MSG)]
self.assertEqual(msg, MSG)
- def _testRecvBuf(self):
+ def _testRecvInto(self):
buf = buffer(MSG)
self.serv_conn.send(buf)
- def testRecvFromBuf(self):
+ def testRecvFromInto(self):
buf = array.array('c', ' '*1024)
- nbytes, addr = self.cli_conn.recvfrom_buf(buf)
+ nbytes, addr = self.cli_conn.recvfrom_into(buf)
self.assertEqual(nbytes, len(MSG))
msg = buf.tostring()[:len(MSG)]
self.assertEqual(msg, MSG)
- def _testRecvFromBuf(self):
+ def _testRecvFromInto(self):
buf = buffer(MSG)
self.serv_conn.send(buf)
diff --git a/Lib/test/test_struct.py b/Lib/test/test_struct.py
index af835f7..aa458e6 100644
--- a/Lib/test/test_struct.py
+++ b/Lib/test/test_struct.py
@@ -1,4 +1,4 @@
-from test.test_support import TestFailed, verbose, verify
+from test.test_support import TestFailed, verbose, verify, vereq
import test.test_support
import struct
import array
@@ -16,13 +16,11 @@ except ImportError:
PY_STRUCT_RANGE_CHECKING = 0
PY_STRUCT_OVERFLOW_MASKING = 1
else:
- PY_STRUCT_RANGE_CHECKING = getattr(_struct, '_PY_STRUCT_RANGE_CHECKING', 0)
- PY_STRUCT_OVERFLOW_MASKING = getattr(_struct, '_PY_STRUCT_OVERFLOW_MASKING', 0)
+ PY_STRUCT_RANGE_CHECKING = _struct._PY_STRUCT_RANGE_CHECKING
+ PY_STRUCT_OVERFLOW_MASKING = _struct._PY_STRUCT_OVERFLOW_MASKING
def string_reverse(s):
- chars = list(s)
- chars.reverse()
- return "".join(chars)
+ return "".join(reversed(s))
def bigendian_to_native(value):
if ISBIGENDIAN:
@@ -504,7 +502,7 @@ def assertRaises(excClass, callableObj, *args, **kwargs):
except excClass:
return
else:
- raise RuntimeError("%s not raised." % excClass)
+ raise TestFailed("%s not raised." % excClass)
def test_unpack_from():
test_string = 'abcd01234'
@@ -512,68 +510,67 @@ def test_unpack_from():
s = struct.Struct(fmt)
for cls in (str, buffer):
data = cls(test_string)
- assert s.unpack_from(data) == ('abcd',)
- assert s.unpack_from(data, 2) == ('cd01',)
- assert s.unpack_from(data, 4) == ('0123',)
+ vereq(s.unpack_from(data), ('abcd',))
+ vereq(s.unpack_from(data, 2), ('cd01',))
+ vereq(s.unpack_from(data, 4), ('0123',))
for i in xrange(6):
- assert s.unpack_from(data, i) == (data[i:i+4],)
+ vereq(s.unpack_from(data, i), (data[i:i+4],))
for i in xrange(6, len(test_string) + 1):
simple_err(s.unpack_from, data, i)
for cls in (str, buffer):
data = cls(test_string)
- assert struct.unpack_from(fmt, data) == ('abcd',)
- assert struct.unpack_from(fmt, data, 2) == ('cd01',)
- assert struct.unpack_from(fmt, data, 4) == ('0123',)
+ vereq(struct.unpack_from(fmt, data), ('abcd',))
+ vereq(struct.unpack_from(fmt, data, 2), ('cd01',))
+ vereq(struct.unpack_from(fmt, data, 4), ('0123',))
for i in xrange(6):
- assert (struct.unpack_from(fmt, data, i) == (data[i:i+4],))
+ vereq(struct.unpack_from(fmt, data, i), (data[i:i+4],))
for i in xrange(6, len(test_string) + 1):
simple_err(struct.unpack_from, fmt, data, i)
-def test_pack_to():
+def test_pack_into():
test_string = 'Reykjavik rocks, eow!'
writable_buf = array.array('c', ' '*100)
fmt = '21s'
s = struct.Struct(fmt)
# Test without offset
- s.pack_to(writable_buf, 0, test_string)
+ s.pack_into(writable_buf, 0, test_string)
from_buf = writable_buf.tostring()[:len(test_string)]
- assert from_buf == test_string
+ vereq(from_buf, test_string)
# Test with offset.
- s.pack_to(writable_buf, 10, test_string)
+ s.pack_into(writable_buf, 10, test_string)
from_buf = writable_buf.tostring()[:len(test_string)+10]
- assert from_buf == (test_string[:10] + test_string)
+ vereq(from_buf, test_string[:10] + test_string)
# Go beyond boundaries.
small_buf = array.array('c', ' '*10)
- assertRaises(struct.error, s.pack_to, small_buf, 0, test_string)
- assertRaises(struct.error, s.pack_to, small_buf, 2, test_string)
+ assertRaises(struct.error, s.pack_into, small_buf, 0, test_string)
+ assertRaises(struct.error, s.pack_into, small_buf, 2, test_string)
-def test_pack_to_fn():
+def test_pack_into_fn():
test_string = 'Reykjavik rocks, eow!'
writable_buf = array.array('c', ' '*100)
fmt = '21s'
- pack_to = lambda *args: struct.pack_to(fmt, *args)
+ pack_into = lambda *args: struct.pack_into(fmt, *args)
- # Test without offset
- pack_to(writable_buf, 0, test_string)
+ # Test without offset.
+ pack_into(writable_buf, 0, test_string)
from_buf = writable_buf.tostring()[:len(test_string)]
- assert from_buf == test_string
+ vereq(from_buf, test_string)
# Test with offset.
- pack_to(writable_buf, 10, test_string)
+ pack_into(writable_buf, 10, test_string)
from_buf = writable_buf.tostring()[:len(test_string)+10]
- assert from_buf == (test_string[:10] + test_string)
+ vereq(from_buf, test_string[:10] + test_string)
# Go beyond boundaries.
small_buf = array.array('c', ' '*10)
- assertRaises(struct.error, pack_to, small_buf, 0, test_string)
- assertRaises(struct.error, pack_to, small_buf, 2, test_string)
+ assertRaises(struct.error, pack_into, small_buf, 0, test_string)
+ assertRaises(struct.error, pack_into, small_buf, 2, test_string)
+
-
# Test methods to pack and unpack from buffers rather than strings.
test_unpack_from()
-test_pack_to()
-test_pack_to_fn()
-
+test_pack_into()
+test_pack_into_fn()
diff --git a/Lib/test/test_tempfile.py b/Lib/test/test_tempfile.py
index e274c5b..aeaa77e 100644
--- a/Lib/test/test_tempfile.py
+++ b/Lib/test/test_tempfile.py
@@ -390,7 +390,7 @@ test_classes.append(test_gettempdir)
class test_mkstemp(TC):
"""Test mkstemp()."""
- def do_create(self, dir=None, pre="", suf="", ):
+ def do_create(self, dir=None, pre="", suf=""):
if dir is None:
dir = tempfile.gettempdir()
try: