[pypy-svn] r58723 - in pypy/branch/2.5-merge/lib-python/modified-2.5.1: . test
iko at codespeak.net
iko at codespeak.net
Tue Oct 7 13:29:13 CEST 2008
Author: iko
Date: Tue Oct 7 13:29:12 2008
New Revision: 58723
Modified:
pypy/branch/2.5-merge/lib-python/modified-2.5.1/doctest.py
pypy/branch/2.5-merge/lib-python/modified-2.5.1/sre_compile.py
pypy/branch/2.5-merge/lib-python/modified-2.5.1/test/test_codecs.py
pypy/branch/2.5-merge/lib-python/modified-2.5.1/test/test_compile.py
pypy/branch/2.5-merge/lib-python/modified-2.5.1/test/test_format.py
pypy/branch/2.5-merge/lib-python/modified-2.5.1/test/test_funcattrs.py
pypy/branch/2.5-merge/lib-python/modified-2.5.1/test/test_itertools.py
pypy/branch/2.5-merge/lib-python/modified-2.5.1/test/test_marshal.py
pypy/branch/2.5-merge/lib-python/modified-2.5.1/test/test_os.py
pypy/branch/2.5-merge/lib-python/modified-2.5.1/test/test_re.py
pypy/branch/2.5-merge/lib-python/modified-2.5.1/test/test_repr.py
pypy/branch/2.5-merge/lib-python/modified-2.5.1/test/test_set.py
pypy/branch/2.5-merge/lib-python/modified-2.5.1/test/test_tempfile.py
pypy/branch/2.5-merge/lib-python/modified-2.5.1/test/test_trace.py
pypy/branch/2.5-merge/lib-python/modified-2.5.1/test/test_unicodedata.py
pypy/branch/2.5-merge/lib-python/modified-2.5.1/test/test_urllib2.py
Log:
(iko,cfbolz)
Apply 2.5.2 diff to modified std lib files
Modified: pypy/branch/2.5-merge/lib-python/modified-2.5.1/doctest.py
==============================================================================
--- pypy/branch/2.5-merge/lib-python/modified-2.5.1/doctest.py (original)
+++ pypy/branch/2.5-merge/lib-python/modified-2.5.1/doctest.py Tue Oct 7 13:29:12 2008
@@ -209,7 +209,10 @@
filename = _module_relative_path(package, filename)
if hasattr(package, '__loader__'):
if hasattr(package.__loader__, 'get_data'):
- return package.__loader__.get_data(filename), filename
+ file_contents = package.__loader__.get_data(filename)
+ # get_data() opens files as 'rb', so one must do the equivalent
+ # conversion as universal newlines would do.
+ return file_contents.replace(os.linesep, '\n'), filename
return open(filename).read(), filename
def _indent(s, indent=4):
@@ -317,8 +320,21 @@
"""
def __init__(self, out):
self.__out = out
+ self.__debugger_used = False
pdb.Pdb.__init__(self, stdout=out)
+ def set_trace(self, frame=None):
+ self.__debugger_used = True
+ if frame is None:
+ frame = sys._getframe().f_back
+ pdb.Pdb.set_trace(self, frame)
+
+ def set_continue(self):
+ # Calling set_continue unconditionally would break unit test
+ # coverage reporting, as Bdb.set_continue calls sys.settrace(None).
+ if self.__debugger_used:
+ pdb.Pdb.set_continue(self)
+
def trace_dispatch(self, *args):
# Redirect stdout to the given stream.
save_stdout = sys.stdout
Modified: pypy/branch/2.5-merge/lib-python/modified-2.5.1/sre_compile.py
==============================================================================
--- pypy/branch/2.5-merge/lib-python/modified-2.5.1/sre_compile.py (original)
+++ pypy/branch/2.5-merge/lib-python/modified-2.5.1/sre_compile.py Tue Oct 7 13:29:12 2008
@@ -281,7 +281,7 @@
# To represent a big charset, first a bitmap of all characters in the
# set is constructed. Then, this bitmap is sliced into chunks of 256
-# characters, duplicate chunks are eliminitated, and each chunk is
+# characters, duplicate chunks are eliminated, and each chunk is
# given a number. In the compiled expression, the charset is
# represented by a 16-bit word sequence, consisting of one word for
# the number of different chunks, a sequence of 256 bytes (128 words)
@@ -526,7 +526,7 @@
indexgroup[i] = k
return _sre.compile(
- pattern, flags, code,
+ pattern, flags | p.pattern.flags, code,
p.pattern.groups-1,
groupindex, indexgroup
)
Modified: pypy/branch/2.5-merge/lib-python/modified-2.5.1/test/test_codecs.py
==============================================================================
--- pypy/branch/2.5-merge/lib-python/modified-2.5.1/test/test_codecs.py (original)
+++ pypy/branch/2.5-merge/lib-python/modified-2.5.1/test/test_codecs.py Tue Oct 7 13:29:12 2008
@@ -27,7 +27,7 @@
class ReadTest(unittest.TestCase):
def check_partial(self, input, partialresults):
# get a StreamReader for the encoding and feed the bytestring version
- # of input to the reader byte by byte. Read every available from
+ # of input to the reader byte by byte. Read everything available from
# the StreamReader and check that the results equal the appropriate
# entries from partialresults.
q = Queue()
@@ -430,6 +430,55 @@
# SF bug #1601501: check that the codec works with a buffer
unicode("\xef\xbb\xbf", "utf-8-sig")
+ def test_bom(self):
+ d = codecs.getincrementaldecoder("utf-8-sig")()
+ s = u"spam"
+ self.assertEqual(d.decode(s.encode("utf-8-sig")), s)
+
+ def test_stream_bom(self):
+ unistring = u"ABC\u00A1\u2200XYZ"
+ bytestring = codecs.BOM_UTF8 + "ABC\xC2\xA1\xE2\x88\x80XYZ"
+
+ reader = codecs.getreader("utf-8-sig")
+ for sizehint in [None] + range(1, 11) + \
+ [64, 128, 256, 512, 1024]:
+ istream = reader(StringIO.StringIO(bytestring))
+ ostream = StringIO.StringIO()
+ while 1:
+ if sizehint is not None:
+ data = istream.read(sizehint)
+ else:
+ data = istream.read()
+
+ if not data:
+ break
+ ostream.write(data)
+
+ got = ostream.getvalue()
+ self.assertEqual(got, unistring)
+
+ def test_stream_bare(self):
+ unistring = u"ABC\u00A1\u2200XYZ"
+ bytestring = "ABC\xC2\xA1\xE2\x88\x80XYZ"
+
+ reader = codecs.getreader("utf-8-sig")
+ for sizehint in [None] + range(1, 11) + \
+ [64, 128, 256, 512, 1024]:
+ istream = reader(StringIO.StringIO(bytestring))
+ ostream = StringIO.StringIO()
+ while 1:
+ if sizehint is not None:
+ data = istream.read(sizehint)
+ else:
+ data = istream.read()
+
+ if not data:
+ break
+ ostream.write(data)
+
+ got = ostream.getvalue()
+ self.assertEqual(got, unistring)
+
class EscapeDecodeTest(unittest.TestCase):
def test_empty(self):
self.assertEquals(codecs.escape_decode(""), ("", 0))
@@ -916,7 +965,7 @@
self.assertEquals(f.readlines(), [u'\ud55c\n', u'\uae00'])
class EncodedFileTest(unittest.TestCase):
-
+
def test_basic(self):
f = StringIO.StringIO('\xed\x95\x9c\n\xea\xb8\x80')
ef = codecs.EncodedFile(f, 'utf-16-le', 'utf-8')
Modified: pypy/branch/2.5-merge/lib-python/modified-2.5.1/test/test_compile.py
==============================================================================
--- pypy/branch/2.5-merge/lib-python/modified-2.5.1/test/test_compile.py (original)
+++ pypy/branch/2.5-merge/lib-python/modified-2.5.1/test/test_compile.py Tue Oct 7 13:29:12 2008
@@ -37,6 +37,9 @@
def test_syntax_error(self):
self.assertRaises(SyntaxError, compile, "1+*3", "filename", "exec")
+ def test_none_keyword_arg(self):
+ self.assertRaises(SyntaxError, compile, "f(None=1)", "<string>", "exec")
+
def test_duplicate_global_local(self):
try:
exec 'def f(a): global a; a = 1'
Modified: pypy/branch/2.5-merge/lib-python/modified-2.5.1/test/test_format.py
==============================================================================
--- pypy/branch/2.5-merge/lib-python/modified-2.5.1/test/test_format.py (original)
+++ pypy/branch/2.5-merge/lib-python/modified-2.5.1/test/test_format.py Tue Oct 7 13:29:12 2008
@@ -1,5 +1,7 @@
from test.test_support import verbose, have_unicode, TestFailed
import sys
+from test.test_support import MAX_Py_ssize_t
+maxsize = MAX_Py_ssize_t
# test string formatting operator (I am not sure if this is being tested
# elsewhere but, surely, some of the given cases are *not* tested because
@@ -7,6 +9,7 @@
# test on unicode strings as well
overflowok = 1
+overflowrequired = 0
def testformat(formatstr, args, output=None):
if verbose:
@@ -23,11 +26,16 @@
if verbose:
print 'overflow (this is fine)'
else:
- if output and result != output:
+ if overflowrequired:
if verbose:
print 'no'
- print "%s %% %s == %s != %s" %\
- (repr(formatstr), repr(args), repr(result), repr(output))
+ print "overflow expected on %s %% %s" % \
+ (repr(formatstr), repr(args))
+ elif output and result != output:
+ if verbose:
+ print 'no'
+ print "%s %% %s == %s != %s" % \
+ (repr(formatstr), repr(args), repr(result), repr(output))
else:
if verbose:
print 'yes'
@@ -55,6 +63,14 @@
# test some ridiculously large precision, expect overflow
testboth('%12.*f', (123456, 1.0))
+# check for internal overflow validation on length of precision
+overflowrequired = 1
+testboth("%#.*g", (110, -1.e+100/3.))
+testboth("%#.*G", (110, -1.e+100/3.))
+testboth("%#.*f", (110, -1.e+100/3.))
+testboth("%#.*F", (110, -1.e+100/3.))
+overflowrequired = 0
+
# Formatting of long integers. Overflow is not ok
overflowok = 0
testboth("%x", 10L, "a")
@@ -238,12 +254,12 @@
test_exc('%o', Foobar(), TypeError,
"expected string or Unicode object, long found")
-if sys.maxint == 2**31-1:
+if maxsize == 2**31-1:
# crashes 2.2.1 and earlier:
try:
- "%*d"%(sys.maxint, -127)
+ "%*d"%(maxsize, -127)
except (MemoryError, OverflowError):
pass # CPython raises MemoryError, but both CPython and PyPy raise
# OverflowError for string concatenation
else:
- raise TestFailed, '"%*d"%(sys.maxint, -127) should fail'
+ raise TestFailed, '"%*d"%(maxsize, -127) should fail'
Modified: pypy/branch/2.5-merge/lib-python/modified-2.5.1/test/test_funcattrs.py
==============================================================================
--- pypy/branch/2.5-merge/lib-python/modified-2.5.1/test/test_funcattrs.py (original)
+++ pypy/branch/2.5-merge/lib-python/modified-2.5.1/test/test_funcattrs.py Tue Oct 7 13:29:12 2008
@@ -242,6 +242,17 @@
verify(c[0].__class__.__name__ == "cell") # don't have a type object handy
cantset(f, "func_closure", c)
+def test_empty_cell():
+ def f(): print a
+ try:
+ f.func_closure[0].cell_contents
+ except ValueError:
+ pass
+ else:
+ raise TestFailed, "shouldn't be able to read an empty cell"
+
+ a = 12
+
def test_func_doc():
def f(): pass
verify(f.__doc__ is None)
@@ -385,6 +396,7 @@
def testmore():
test_func_closure()
+ test_empty_cell()
test_func_doc()
test_func_globals()
test_func_name()
Modified: pypy/branch/2.5-merge/lib-python/modified-2.5.1/test/test_itertools.py
==============================================================================
--- pypy/branch/2.5-merge/lib-python/modified-2.5.1/test/test_itertools.py (original)
+++ pypy/branch/2.5-merge/lib-python/modified-2.5.1/test/test_itertools.py Tue Oct 7 13:29:12 2008
@@ -5,6 +5,8 @@
import sys
import operator
import random
+maxsize = test_support.MAX_Py_ssize_t
+minsize = -maxsize-1
def onearg(x):
'Test function of one argument'
@@ -52,7 +54,7 @@
self.assertEqual(take(2, zip('abc',count(3))), [('a', 3), ('b', 4)])
self.assertRaises(TypeError, count, 2, 3)
self.assertRaises(TypeError, count, 'a')
- self.assertRaises(OverflowError, list, islice(count(sys.maxint-5), 10))
+ self.assertRaises(OverflowError, list, islice(count(maxsize-5), 10))
c = count(3)
self.assertEqual(repr(c), 'count(3)')
c.next()
@@ -288,7 +290,7 @@
self.assertRaises((TypeError, ValueError), islice, xrange(10), 1, 'a')
self.assertRaises((TypeError, ValueError), islice, xrange(10), 'a', 1, 1)
self.assertRaises((TypeError, ValueError), islice, xrange(10), 1, 'a', 1)
- self.assertEqual(len(list(islice(count(), 1, 10, sys.maxint))), 1)
+ self.assertEqual(len(list(islice(count(), 1, 10, maxsize))), 1)
def test_takewhile(self):
data = [1, 3, 5, 20, 2, 4, 6, 8]
Modified: pypy/branch/2.5-merge/lib-python/modified-2.5.1/test/test_marshal.py
==============================================================================
--- pypy/branch/2.5-merge/lib-python/modified-2.5.1/test/test_marshal.py (original)
+++ pypy/branch/2.5-merge/lib-python/modified-2.5.1/test/test_marshal.py Tue Oct 7 13:29:12 2008
@@ -208,6 +208,30 @@
except Exception:
pass
+ def test_loads_recursion(self):
+ s = 'c' + ('X' * 4*4) + '{' * 2**20
+ self.assertRaises(ValueError, marshal.loads, s)
+
+ def test_recursion_limit(self):
+ # Create a deeply nested structure.
+ head = last = []
+ # The max stack depth should match the value in Python/marshal.c.
+ MAX_MARSHAL_STACK_DEPTH = 2000
+ for i in range(MAX_MARSHAL_STACK_DEPTH - 2):
+ last.append([0])
+ last = last[-1]
+
+ # Verify we don't blow out the stack with dumps/load.
+ data = marshal.dumps(head)
+ new_head = marshal.loads(data)
+ # Don't use == to compare objects, it can exceed the recursion limit.
+ self.assertEqual(len(new_head), len(head))
+ self.assertEqual(len(new_head[0]), len(head[0]))
+ self.assertEqual(len(new_head[-1]), len(head[-1]))
+
+ last.append([0])
+ self.assertRaises(ValueError, marshal.dumps, head)
+
def test_main():
test_support.run_unittest(IntTestCase,
FloatTestCase,
Modified: pypy/branch/2.5-merge/lib-python/modified-2.5.1/test/test_os.py
==============================================================================
--- pypy/branch/2.5-merge/lib-python/modified-2.5.1/test/test_os.py (original)
+++ pypy/branch/2.5-merge/lib-python/modified-2.5.1/test/test_os.py Tue Oct 7 13:29:12 2008
@@ -226,10 +226,20 @@
# Restrict test to Win32, since there is no guarantee other
# systems support centiseconds
if sys.platform == 'win32':
- def test_1565150(self):
- t1 = 1159195039.25
- os.utime(self.fname, (t1, t1))
- self.assertEquals(os.stat(self.fname).st_mtime, t1)
+ def get_file_system(path):
+ import os
+ root = os.path.splitdrive(os.path.realpath("."))[0] + '\\'
+ import ctypes
+ kernel32 = ctypes.windll.kernel32
+ buf = ctypes.create_string_buffer("", 100)
+ if kernel32.GetVolumeInformationA(root, None, 0, None, None, None, buf, len(buf)):
+ return buf.value
+
+ if get_file_system(test_support.TESTFN) == "NTFS":
+ def test_1565150(self):
+ t1 = 1159195039.25
+ os.utime(self.fname, (t1, t1))
+ self.assertEquals(os.stat(self.fname).st_mtime, t1)
def test_1686475(self):
# Verify that an open file can be stat'ed
Modified: pypy/branch/2.5-merge/lib-python/modified-2.5.1/test/test_re.py
==============================================================================
--- pypy/branch/2.5-merge/lib-python/modified-2.5.1/test/test_re.py (original)
+++ pypy/branch/2.5-merge/lib-python/modified-2.5.1/test/test_re.py Tue Oct 7 13:29:12 2008
@@ -83,6 +83,31 @@
self.assertEqual(re.sub('\r\n', '\n', 'abc\r\ndef\r\n'),
'abc\ndef\n')
+ def test_bug_1140(self):
+ # re.sub(x, y, u'') should return u'', not '', and
+ # re.sub(x, y, '') should return '', not u''.
+ # Also:
+ # re.sub(x, y, unicode(x)) should return unicode(y), and
+ # re.sub(x, y, str(x)) should return
+ # str(y) if isinstance(y, str) else unicode(y).
+ for x in 'x', u'x':
+ for y in 'y', u'y':
+ z = re.sub(x, y, u'')
+ self.assertEqual(z, u'')
+ self.assertEqual(type(z), unicode)
+ #
+ z = re.sub(x, y, '')
+ self.assertEqual(z, '')
+ self.assertEqual(type(z), str)
+ #
+ z = re.sub(x, y, unicode(x))
+ self.assertEqual(z, y)
+ self.assertEqual(type(z), unicode)
+ #
+ z = re.sub(x, y, str(x))
+ self.assertEqual(z, y)
+ self.assertEqual(type(z), type(y))
+
def test_sub_template_numeric_escape(self):
# bug 776311 and friends
self.assertEqual(re.sub('x', r'\0', 'x'), '\0')
@@ -618,7 +643,37 @@
for typecode in 'cbBuhHiIlLfd':
a = array.array(typecode)
self.assertEqual(re.compile("bla").match(a), None)
- self.assertEqual(re.compile("").match(a).groups(), ())
+ self.assertEqual(re.compile("").match(a).groups(), ())
+
+ def test_inline_flags(self):
+ # Bug #1700
+ upper_char = unichr(0x1ea0) # Latin Capital Letter A with Dot Bellow
+ lower_char = unichr(0x1ea1) # Latin Small Letter A with Dot Bellow
+
+ p = re.compile(upper_char, re.I | re.U)
+ q = p.match(lower_char)
+ self.assertNotEqual(q, None)
+
+ p = re.compile(lower_char, re.I | re.U)
+ q = p.match(upper_char)
+ self.assertNotEqual(q, None)
+
+ p = re.compile('(?i)' + upper_char, re.U)
+ q = p.match(lower_char)
+ self.assertNotEqual(q, None)
+
+ p = re.compile('(?i)' + lower_char, re.U)
+ q = p.match(upper_char)
+ self.assertNotEqual(q, None)
+
+ p = re.compile('(?iu)' + upper_char)
+ q = p.match(lower_char)
+ self.assertNotEqual(q, None)
+
+ p = re.compile('(?iu)' + lower_char)
+ q = p.match(upper_char)
+ self.assertNotEqual(q, None)
+
def run_re_tests():
from test.re_tests import benchmarks, tests, SUCCEED, FAIL, SYNTAX_ERROR
Modified: pypy/branch/2.5-merge/lib-python/modified-2.5.1/test/test_repr.py
==============================================================================
--- pypy/branch/2.5-merge/lib-python/modified-2.5.1/test/test_repr.py (original)
+++ pypy/branch/2.5-merge/lib-python/modified-2.5.1/test/test_repr.py Tue Oct 7 13:29:12 2008
@@ -10,6 +10,7 @@
from test.test_support import run_unittest
from repr import repr as r # Don't shadow builtin repr
+from repr import Repr
def nestedTuple(nesting):
@@ -34,6 +35,18 @@
expected = repr(s)[:13] + "..." + repr(s)[-14:]
eq(r(s), expected)
+ def test_tuple(self):
+ eq = self.assertEquals
+ eq(r((1,)), "(1,)")
+
+ t3 = (1, 2, 3)
+ eq(r(t3), "(1, 2, 3)")
+
+ r2 = Repr()
+ r2.maxtuple = 2
+ expected = repr(t3)[:-2] + "...)"
+ eq(r2.repr(t3), expected)
+
def test_container(self):
from array import array
from collections import deque
@@ -187,6 +200,16 @@
x = classmethod(C.foo)
self.failUnless(repr(x).startswith('<classmethod object at 0x'))
+ def test_unsortable(self):
+ # Repr.repr() used to call sorted() on sets, frozensets and dicts
+ # without taking into account that not all objects are comparable
+ x = set([1j, 2j, 3j])
+ y = frozenset(x)
+ z = {1j: 1, 2j: 2}
+ r(x)
+ r(y)
+ r(z)
+
def touch(path, text=''):
fp = open(path, 'w')
fp.write(text)
Modified: pypy/branch/2.5-merge/lib-python/modified-2.5.1/test/test_set.py
==============================================================================
--- pypy/branch/2.5-merge/lib-python/modified-2.5.1/test/test_set.py (original)
+++ pypy/branch/2.5-merge/lib-python/modified-2.5.1/test/test_set.py Tue Oct 7 13:29:12 2008
@@ -288,7 +288,7 @@
self.assertEqual(sum(elem.hash_count for elem in d), n)
if hasattr(s, 'symmetric_difference_update'):
s.symmetric_difference_update(d)
- self.assertEqual(sum(elem.hash_count for elem in d), n)
+ self.assertEqual(sum(elem.hash_count for elem in d), n)
d2 = dict.fromkeys(set(d))
self.assertEqual(sum(elem.hash_count for elem in d), n)
d3 = dict.fromkeys(frozenset(d))
@@ -501,7 +501,7 @@
set.__init__(self, iterable)
class TestSetSubclassWithKeywordArgs(TestSet):
-
+
def test_keywords_in_subclass(self):
'SF bug #1486663 -- this used to erroneously raise a TypeError'
SetSubclassWithKeywordArgs(newarg=1)
@@ -1489,7 +1489,7 @@
test_classes = (
TestSet,
TestSetSubclass,
- TestSetSubclassWithKeywordArgs,
+ TestSetSubclassWithKeywordArgs,
TestFrozenSet,
TestFrozenSetSubclass,
TestSetOfSets,
Modified: pypy/branch/2.5-merge/lib-python/modified-2.5.1/test/test_tempfile.py
==============================================================================
--- pypy/branch/2.5-merge/lib-python/modified-2.5.1/test/test_tempfile.py (original)
+++ pypy/branch/2.5-merge/lib-python/modified-2.5.1/test/test_tempfile.py Tue Oct 7 13:29:12 2008
@@ -1,5 +1,5 @@
# tempfile.py unit tests.
-
+from __future__ import with_statement
import tempfile
import os
import sys
@@ -309,7 +309,7 @@
# On Windows a spawn* /path/ with embedded spaces shouldn't be quoted,
# but an arg with embedded spaces should be decorated with double
# quotes on each end
- if sys.platform in ('win32'):
+ if sys.platform in ('win32',):
decorated = '"%s"' % sys.executable
tester = '"%s"' % tester
else:
@@ -619,7 +619,6 @@
def test_multiple_close(self):
# A NamedTemporaryFile can be closed many times without error
-
f = tempfile.NamedTemporaryFile()
f.write('abc\n')
f.close()
@@ -629,6 +628,16 @@
except:
self.failOnException("close")
+ def test_context_manager(self):
+ # A NamedTemporaryFile can be used as a context manager
+ with tempfile.NamedTemporaryFile() as f:
+ self.failUnless(os.path.exists(f.name))
+ self.failIf(os.path.exists(f.name))
+ def use_closed():
+ with f:
+ pass
+ self.failUnlessRaises(ValueError, use_closed)
+
# How to test the mode and bufsize parameters?
test_classes.append(test_NamedTemporaryFile)
Modified: pypy/branch/2.5-merge/lib-python/modified-2.5.1/test/test_trace.py
==============================================================================
--- pypy/branch/2.5-merge/lib-python/modified-2.5.1/test/test_trace.py (original)
+++ pypy/branch/2.5-merge/lib-python/modified-2.5.1/test/test_trace.py Tue Oct 7 13:29:12 2008
@@ -204,12 +204,44 @@
(6, 'line'),
(6, 'return')]
+def generator_function():
+ try:
+ yield True
+ "continued"
+ finally:
+ "finally"
+def generator_example():
+ # any() will leave the generator before its end
+ x = any(generator_function())
+
+ # the following lines were not traced
+ for x in range(10):
+ y = x
+
+generator_example.events = ([(0, 'call'),
+ (2, 'line'),
+ (-6, 'call'),
+ (-5, 'line'),
+ (-4, 'line'),
+ (-4, 'return'),
+ (-4, 'call'),
+ (-4, 'exception'),
+ (-1, 'line'),
+ (-1, 'return')] +
+ [(5, 'line'), (6, 'line')] * 10 +
+ [(5, 'line'), (5, 'return')])
+
+
class Tracer:
def __init__(self):
self.events = []
def trace(self, frame, event, arg):
self.events.append((frame.f_lineno, event))
return self.trace
+ def traceWithGenexp(self, frame, event, arg):
+ (o for o in [1])
+ self.events.append((frame.f_lineno, event))
+ return self.trace
class TraceTestCase(unittest.TestCase):
def compare_events(self, line_offset, events, expected_events):
@@ -217,17 +249,19 @@
if events != expected_events:
self.fail(
"events did not match expectation:\n" +
- "\n".join(difflib.ndiff(map(str, expected_events),
- map(str, events))))
+ "\n".join(difflib.ndiff([str(x) for x in expected_events],
+ [str(x) for x in events])))
-
- def run_test(self, func):
+ def run_and_compare(self, func, events):
tracer = Tracer()
sys.settrace(tracer.trace)
func()
sys.settrace(None)
self.compare_events(func.func_code.co_firstlineno,
- tracer.events, func.events)
+ tracer.events, events)
+
+ def run_test(self, func):
+ self.run_and_compare(func, func.events)
def run_test2(self, func):
tracer = Tracer()
@@ -262,6 +296,71 @@
def test_12_tighterloop(self):
self.run_test(tighterloop_example)
+ def test_13_genexp(self):
+ self.run_test(generator_example)
+ # issue1265: if the trace function contains a generator,
+ # and if the traced function contains another generator
+ # that is not completely exhausted, the trace stopped.
+ # Worse: the 'finally' clause was not invoked.
+ tracer = Tracer()
+ sys.settrace(tracer.traceWithGenexp)
+ generator_example()
+ sys.settrace(None)
+ self.compare_events(generator_example.func_code.co_firstlineno,
+ tracer.events, generator_example.events)
+
+ def test_14_onliner_if(self):
+ def onliners():
+ if True: False
+ else: True
+ return 0
+ self.run_and_compare(
+ onliners,
+ [(0, 'call'),
+ (1, 'line'),
+ (3, 'line'),
+ (3, 'return')])
+
+ def test_15_loops(self):
+ # issue1750076: "while" expression is skipped by debugger
+ def for_example():
+ for x in range(2):
+ pass
+ self.run_and_compare(
+ for_example,
+ [(0, 'call'),
+ (1, 'line'),
+ (2, 'line'),
+ (1, 'line'),
+ (2, 'line'),
+ (1, 'line'),
+ (1, 'return')])
+
+ def while_example():
+ # While expression should be traced on every loop
+ x = 2
+ while x > 0:
+ x -= 1
+ self.run_and_compare(
+ while_example,
+ [(0, 'call'),
+ (2, 'line'),
+ (3, 'line'),
+ (4, 'line'),
+ (3, 'line'),
+ (4, 'line'),
+ (3, 'line'),
+ (3, 'return')])
+
+ def test_16_blank_lines(self):
+ exec("def f():\n" + "\n" * 256 + " pass")
+ self.run_and_compare(
+ f,
+ [(0, 'call'),
+ (257, 'line'),
+ (257, 'return')])
+
+
class RaisingTraceFuncTestCase(unittest.TestCase):
def trace(self, frame, event, arg):
"""A trace function that raises an exception in response to a
Modified: pypy/branch/2.5-merge/lib-python/modified-2.5.1/test/test_unicodedata.py
==============================================================================
--- pypy/branch/2.5-merge/lib-python/modified-2.5.1/test/test_unicodedata.py (original)
+++ pypy/branch/2.5-merge/lib-python/modified-2.5.1/test/test_unicodedata.py Tue Oct 7 13:29:12 2008
@@ -214,6 +214,10 @@
count += 1
self.assert_(count >= 10) # should have tested at least the ASCII digits
+ def test_bug_1704793(self):
+ if sys.maxunicode == 65535:
+ self.assertRaises(KeyError, self.db.lookup, "GOTHIC LETTER FAIHU")
+
def test_main():
test.test_support.run_unittest(
UnicodeMiscTest,
Modified: pypy/branch/2.5-merge/lib-python/modified-2.5.1/test/test_urllib2.py
==============================================================================
--- pypy/branch/2.5-merge/lib-python/modified-2.5.1/test/test_urllib2.py (original)
+++ pypy/branch/2.5-merge/lib-python/modified-2.5.1/test/test_urllib2.py Tue Oct 7 13:29:12 2008
@@ -381,6 +381,12 @@
class OpenerDirectorTests(unittest.TestCase):
+ def test_add_non_handler(self):
+ class NonHandler(object):
+ pass
+ self.assertRaises(TypeError,
+ OpenerDirector().add_handler, NonHandler())
+
def test_badly_named_methods(self):
# test work-around for three methods that accidentally follow the
# naming conventions for handler methods
More information about the Pypy-commit
mailing list