Author: Amaury Forgeot d'Arc <amaur...@gmail.com> Branch: py3k Changeset: r48216:72a97784aaf3 Date: 2011-10-18 20:35 +0200 http://bitbucket.org/pypy/pypy/changeset/72a97784aaf3/
Log: Fix two test files. diff --git a/pypy/interpreter/astcompiler/test/test_compiler.py b/pypy/interpreter/astcompiler/test/test_compiler.py --- a/pypy/interpreter/astcompiler/test/test_compiler.py +++ b/pypy/interpreter/astcompiler/test/test_compiler.py @@ -456,16 +456,6 @@ yield self.st, decl, 'A,A1,A2,B2,C,C1,C2,D1,E,G,G1,G2,N1', \ (6,6 ,4 ,1 ,5,5 ,5 ,3 ,8,2,2 ,2 ,7 ) - decl = py.code.Source(""" - def f((a, b)): - def g((c, d)): - return (a, b, c, d) - return g - x = f((1, 2))((3, 4)) - """) - decl = str(decl) + "\n" - yield self.st, decl, 'x', (1, 2, 3, 4) - source = """if 1: def f(a): del a @@ -673,7 +663,7 @@ if not d: self.fail("Full mapping must compare to True") # keys(), items(), iterkeys() ... def check_iterandlist(iter, lst, ref): - self.assert_(hasattr(iter, 'next')) + self.assert_(hasattr(iter, '__next__')) self.assert_(hasattr(iter, '__iter__')) x = list(iter) self.assert_(set(x)==set(lst)==set(ref)) @@ -682,8 +672,8 @@ check_iterandlist(d.itervalues(), d.values(), self.reference.values()) check_iterandlist(d.iteritems(), d.items(), self.reference.items()) #get - key, value = d.iteritems().next() - knownkey, knownvalue = self.other.iteritems().next() + key, value = next(d.iteritems()) + knownkey, knownvalue = next(self.other.iteritems()) self.assertEqual(d.get(key, knownvalue), value) self.assertEqual(d.get(knownkey, knownvalue), knownvalue) self.failIf(knownkey in d) @@ -817,7 +807,7 @@ exec("def f():\n 'hi'", ns) f = ns["f"] save = sys.stdout - sys.stdout = output = io.BytesIO() + sys.stdout = output = io.StringIO() try: dis.dis(f) finally: diff --git a/pypy/interpreter/test/test_code.py b/pypy/interpreter/test/test_code.py --- a/pypy/interpreter/test/test_code.py +++ b/pypy/interpreter/test/test_code.py @@ -42,7 +42,7 @@ 'co_flags': 0, 'co_consts': ("abs(number) -> number\n\nReturn the absolute value of the argument.",), }), - (object.__init__.im_func.func_code, + (object.__init__.func_code, {#'co_name': '__init__', XXX getting descr__init__ 'co_varnames': ('obj', 'args', 'keywords'), 'co_argcount': 1, @@ -70,7 +70,7 @@ foo(g) ''' d = {} - exec src in d + exec(src, d) assert list(sorted(d['f'].func_code.co_names)) == ['foo', 'g'] @@ -97,7 +97,7 @@ ccode.co_freevars, ccode.co_cellvars) d = {} - exec co in d + exec(co, d) assert d['c'] == 3 # test backwards-compatibility version with no freevars or cellvars co = new.code(ccode.co_argcount, @@ -113,7 +113,7 @@ ccode.co_firstlineno, ccode.co_lnotab) d = {} - exec co in d + exec(co, d) assert d['c'] == 3 def f(x): y = 1 @@ -147,9 +147,9 @@ def test_hash(self): d1 = {} - exec "def f(): pass" in d1 + exec("def f(): pass", d1) d2 = {} - exec "def f(): pass" in d2 + exec("def f(): pass", d2) assert d1['f'].func_code == d2['f'].func_code assert hash(d1['f'].func_code) == hash(d2['f'].func_code) @@ -164,47 +164,48 @@ assert i in res def test_code_extra(self): - exec """if 1: + d = {} + exec("""if 1: def f(): "docstring" 'stuff' 56 -""" +""", d) # check for new flag, CO_NOFREE - assert f.func_code.co_flags & 0x40 + assert d['f'].func_code.co_flags & 0x40 - exec """if 1: + exec("""if 1: def f(x): def g(y): return x+y return g -""" +""", d) # CO_NESTED - assert f(4).func_code.co_flags & 0x10 - assert f.func_code.co_flags & 0x10 == 0 + assert d['f'](4).func_code.co_flags & 0x10 + assert d['f'].func_code.co_flags & 0x10 == 0 # check for CO_CONTAINSGLOBALS - assert not f.func_code.co_flags & 0x0800 + assert not d['f'].func_code.co_flags & 0x0800 - exec """if 1: + exec("""if 1: r = range def f(): return [l for l in r(100)] def g(): return [l for l in [1, 2, 3, 4]] -""" +""", d) # check for CO_CONTAINSGLOBALS - assert f.func_code.co_flags & 0x0800 - assert not g.func_code.co_flags & 0x0800 + assert d['f'].func_code.co_flags & 0x0800 + assert not d['g'].func_code.co_flags & 0x0800 - exec """if 1: + exec("""if 1: b = 2 def f(x): - exec "a = 1"; + exec("a = 1") return a + b + x -""" +""", d) # check for CO_CONTAINSGLOBALS - assert f.func_code.co_flags & 0x0800 + assert d['f'].func_code.co_flags & 0x0800 diff --git a/pypy/interpreter/typedef.py b/pypy/interpreter/typedef.py --- a/pypy/interpreter/typedef.py +++ b/pypy/interpreter/typedef.py @@ -472,6 +472,12 @@ return space.wrap(getattr(obj, name)) return GetSetProperty(fget, cls=cls, doc=doc) +def interp_attrproperty_bytes(name, cls, doc=None): + "NOT_RPYTHON: initialization-time only" + def fget(space, obj): + return space.wrapbytes(getattr(obj, name)) + return GetSetProperty(fget, cls=cls, doc=doc) + def interp_attrproperty_w(name, cls, doc=None): "NOT_RPYTHON: initialization-time only" def fget(space, obj): @@ -686,7 +692,7 @@ co_nlocals = interp_attrproperty('co_nlocals', cls=PyCode), co_stacksize = interp_attrproperty('co_stacksize', cls=PyCode), co_flags = interp_attrproperty('co_flags', cls=PyCode), - co_code = interp_attrproperty('co_code', cls=PyCode), + co_code = interp_attrproperty_bytes('co_code', cls=PyCode), co_consts = GetSetProperty(PyCode.fget_co_consts), co_names = GetSetProperty(PyCode.fget_co_names), co_varnames = GetSetProperty(PyCode.fget_co_varnames), @@ -695,7 +701,7 @@ co_filename = interp_attrproperty('co_filename', cls=PyCode), co_name = interp_attrproperty('co_name', cls=PyCode), co_firstlineno = interp_attrproperty('co_firstlineno', cls=PyCode), - co_lnotab = interp_attrproperty('co_lnotab', cls=PyCode), + co_lnotab = interp_attrproperty_bytes('co_lnotab', cls=PyCode), __weakref__ = make_weakref_descr(PyCode), ) PyCode.typedef.acceptable_as_base_class = False diff --git a/pypy/module/__builtin__/app_functional.py b/pypy/module/__builtin__/app_functional.py --- a/pypy/module/__builtin__/app_functional.py +++ b/pypy/module/__builtin__/app_functional.py @@ -41,8 +41,8 @@ Returns the sum of a sequence of numbers (NOT strings) plus the value of parameter 'start' (which defaults to 0). When the sequence is empty, returns start.""" - if isinstance(start, basestring): - raise TypeError("sum() can't sum strings") + if isinstance(start, str): + raise TypeError("sum() can't sum strings [use ''.join(seq) instead]") last = start for x in sequence: # Very intentionally *not* +=, that would have different semantics if @@ -162,4 +162,4 @@ item = seq[i] if func(item): result.append(item) - return tuple(result) \ No newline at end of file + return tuple(result) diff --git a/pypy/module/__builtin__/app_io.py b/pypy/module/__builtin__/app_io.py --- a/pypy/module/__builtin__/app_io.py +++ b/pypy/module/__builtin__/app_io.py @@ -78,6 +78,8 @@ def write(data): if not isinstance(data, str): data = str(data) + if getattr(fp, 'encoding', None): + data = data.encode(fp.encoding) fp.write(data) sep = kwargs.pop("sep", None) if sep is not None: _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit