[pypy-commit] pypy py3k: Fix many tests for execution with -A.
amauryfa
noreply at buildbot.pypy.org
Thu Oct 11 00:59:23 CEST 2012
Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: py3k
Changeset: r57999:77f2578283bd
Date: 2012-10-10 22:26 +0200
http://bitbucket.org/pypy/pypy/changeset/77f2578283bd/
Log: Fix many tests for execution with -A.
diff --git a/pypy/module/__builtin__/test/test_builtin.py b/pypy/module/__builtin__/test/test_builtin.py
--- a/pypy/module/__builtin__/test/test_builtin.py
+++ b/pypy/module/__builtin__/test/test_builtin.py
@@ -298,7 +298,7 @@
raises(TypeError, enumerate, 1)
raises(TypeError, enumerate, None)
enum = enumerate(range(5), 2)
- assert list(enum) == zip(range(2, 7), range(5))
+ assert list(enum) == list(zip(range(2, 7), range(5)))
def test_next(self):
x = iter(['a', 'b', 'c'])
@@ -340,7 +340,7 @@
raises(ValueError, range, 0, 1, 0)
def test_range_repr(self):
- assert repr(range(1)) == 'range(1)'
+ assert repr(range(1)) == 'range(0, 1)'
assert repr(range(1,2)) == 'range(1, 2)'
assert repr(range(1,2,3)) == 'range(1, 2, 3)'
@@ -506,7 +506,7 @@
def test_unicode_encoding_compile(self):
code = "# -*- coding: utf-8 -*-\npass\n"
- raises(SyntaxError, compile, code, "tmp", "exec")
+ compile(code, "tmp", "exec")
def test_bytes_compile(self):
code = b"# -*- coding: utf-8 -*-\npass\n"
@@ -641,9 +641,11 @@
raises(TypeError, pr, sep=42)
def test_round(self):
- assert round(11.234) == 11.0
- assert round(11.234, -1) == 10.0
- assert round(11.234, 0) == 11.0
+ assert round(11.234) == 11
+ assert type(round(11.234)) is int
+ assert round(11.234, -1) == 10
+ assert type(round(11.234, -1)) is float
+ assert round(11.234, 0) == 11
assert round(11.234, 1) == 11.2
#
assert round(5e15-1) == 5e15-1
@@ -652,11 +654,10 @@
assert round(-5e15) == -5e15
#
inf = 1e200 * 1e200
- assert round(inf) == inf
- assert round(-inf) == -inf
+ raises(OverflowError, round, inf)
+ raises(OverflowError, round, -inf)
nan = inf / inf
- assert repr(round(nan)) == repr(nan)
- #
+ raises(ValueError, round, nan)
raises(OverflowError, round, 1.6e308, -308)
#
assert round(562949953421312.5, 1) == 562949953421312.5
diff --git a/pypy/module/__builtin__/test/test_descriptor.py b/pypy/module/__builtin__/test/test_descriptor.py
--- a/pypy/module/__builtin__/test/test_descriptor.py
+++ b/pypy/module/__builtin__/test/test_descriptor.py
@@ -323,7 +323,7 @@
for attr in "__doc__", "fget", "fset", "fdel":
try:
setattr(raw, attr, 42)
- except TypeError as msg:
+ except AttributeError as msg:
if str(msg).find('readonly') < 0:
raise Exception("when setting readonly attr %r on a "
"property, got unexpected TypeError "
diff --git a/pypy/module/__builtin__/test/test_functional.py b/pypy/module/__builtin__/test/test_functional.py
--- a/pypy/module/__builtin__/test/test_functional.py
+++ b/pypy/module/__builtin__/test/test_functional.py
@@ -4,18 +4,19 @@
class AppTestMap:
def test_trivial_map_one_seq(self):
- assert map(lambda x: x+2, [1, 2, 3, 4]) == [3, 4, 5, 6]
+ assert list(map(lambda x: x+2, [1, 2, 3, 4])) == [3, 4, 5, 6]
def test_trivial_map_one_seq_2(self):
- assert map(str, [1, 2, 3, 4]) == ['1', '2', '3', '4']
+ assert list(map(str, [1, 2, 3, 4])) == ['1', '2', '3', '4']
def test_trivial_map_two_seq(self):
- assert map(lambda x,y: x+y,
- [1, 2, 3, 4],[1, 2, 3, 4]) == (
+ assert list(map(lambda x,y: x+y,
+ [1, 2, 3, 4],[1, 2, 3, 4])) == (
[2, 4, 6, 8])
- def test_trivial_map_sizes_dont_match_and_should(self):
- raises(TypeError, map, lambda x,y: x+y, [1, 2, 3, 4], [1, 2, 3])
+ def test_trivial_map_sizes_dont_match(self):
+ assert list(map(lambda x,y: x+y, [1, 2, 3, 4], [1, 2, 3])) == (
+ [2, 4, 6])
def test_trivial_map_no_arguments(self):
raises(TypeError, map)
@@ -23,43 +24,29 @@
def test_trivial_map_no_function_no_seq(self):
raises(TypeError, map, None)
- def test_trivial_map_no_fuction_one_seq(self):
- assert map(None, [1, 2, 3]) == [1, 2, 3]
-
- def test_trivial_map_no_function(self):
- assert map(None, [1,2,3], [4,5,6], [7,8], [1]) == (
- [(1, 4, 7, 1), (2, 5, 8, None), (3, 6, None, None)])
+ def test_trivial_map_no_fuction(self):
+ m = map(None, [1, 2, 3]) # Don't crash here...
+ raises(TypeError, next, m) # ...but only on first item.
def test_map_identity1(self):
a = ['1', 2, 3, 'b', None]
b = a[:]
- assert map(lambda x: x, a) == a
- assert a == b
-
- def test_map_None(self):
- a = ['1', 2, 3, 'b', None]
- b = a[:]
- assert map(None, a) == a
+ assert list(map(lambda x: x, a)) == a
assert a == b
def test_map_badoperation(self):
a = ['1', 2, 3, 'b', None]
- raises(TypeError, map, lambda x: x+1, a)
-
- def test_map_multiply_identity(self):
- a = ['1', 2, 3, 'b', None]
- b = [ 2, 3, 4, 5, 6]
- assert map(None, a, b) == [('1', 2), (2, 3), (3, 4), ('b', 5), (None, 6)]
+ raises(TypeError, list, map, lambda x: x+1, a)
def test_map_add(self):
a = [1, 2, 3, 4]
b = [0, 1, 1, 1]
- assert map(lambda x, y: x+y, a, b) == [1, 3, 4, 5]
+ assert list(map(lambda x, y: x+y, a, b)) == [1, 3, 4, 5]
def test_map_first_item(self):
a = [1, 2, 3, 4, 5]
- b = []
- assert map(lambda x, y: x, a, b) == a
+ b = [6, 7, 8, 9, 10]
+ assert list(map(lambda x, y: x, a, b)) == a
def test_map_iterables(self):
class A(object):
@@ -74,18 +61,23 @@
self.n -= 1
if self.n == 0: raise StopIteration
return self.n
- result = map(None, A(3), A(8))
+ result = map(lambda *x:x, A(3), A(8))
# this also checks that B.next() is not called any more after it
# raised StopIteration once
- assert result == [(2, 7), (1, 6), (None, 5), (None, 4),
- (None, 3), (None, 2), (None, 1)]
+ assert list(result) == [(2, 7), (1, 6)]
+
+ def test_repr(self):
+ assert repr(map(1, [2])).startswith('<map object ')
class AppTestZip:
def test_one_list(self):
- assert zip([1,2,3]) == [(1,), (2,), (3,)]
+ assert list(zip([1,2,3])) == [(1,), (2,), (3,)]
def test_three_lists(self):
- assert zip([1,2,3], [1,2], [1,2,3]) == [(1,1,1), (2,2,2)]
+ assert list(zip([1,2,3], [1,2], [1,2,3])) == [(1,1,1), (2,2,2)]
+
+ def test_repr(self):
+ assert repr(zip([1,2,3], [1,2], [1,2,3])).startswith('<zip object ')
class AppTestFilter:
def test_None(self):
More information about the pypy-commit
mailing list