1. Pypy
  2. Untitled project
  3. pypy

Commits

Philip Jenvey  committed 51a3db8 Merge

merge default

  • Participants
  • Parent commits e552c19, a26b875
  • Branches py3k

Comments (0)

Files changed (3)

File pypy/module/test_lib_pypy/test_collections.py

View file
  • Ignore whitespace
 Extra tests for the pure Python PyPy _collections module
 (not used in normal PyPy's)
 """
+from pypy.module.test_lib_pypy.support import import_lib_pypy
 
-from __future__ import absolute_import
-from lib_pypy import _collections as collections
-import py
 
-class TestDeque:
+class AppTestDeque:
+
+    def setup_class(cls):
+        cls.w_collections = import_lib_pypy(cls.space, '_collections')
+
     def setup_method(self, method):
-        self.n = 10
-        self.d = collections.deque(range(self.n))
+        space = self.space
+        n = 10
+        self.w_n = space.wrap(n)
+        w_deque = space.getattr(self.w_collections, space.wrap('deque'))
+        self.w_d = space.call_function(w_deque, space.wrap(range(n)))
 
     def test_deque(self):
         assert len(self.d) == self.n
 
     def test_deque_iter(self):
         it = iter(self.d)
-        py.test.raises(TypeError, len, it)
+        raises(TypeError, len, it)
         assert it.next() == 0
         self.d.pop()
-        py.test.raises(RuntimeError, it.next)
+        raises(RuntimeError, it.next)
 
     def test_deque_reversed(self):
         it = reversed(self.d)
-        py.test.raises(TypeError, len, it)
+        raises(TypeError, len, it)
         assert it.next() == self.n-1
         assert it.next() == self.n-2
         self.d.pop()
-        py.test.raises(RuntimeError, it.next)
+        raises(RuntimeError, it.next)
 
     def test_deque_remove(self):
         d = self.d
-        py.test.raises(ValueError, d.remove, "foobar")
+        raises(ValueError, d.remove, "foobar")
 
     def test_mutate_during_remove(self):
+        collections = self.collections
         # Handle evil mutator
         class MutateCmp:
             def __init__(self, deque, result):
         for match in (True, False):
             d = collections.deque(['ab'])
             d.extend([MutateCmp(d, match), 'c'])
-            py.test.raises(IndexError, d.remove, 'c')
+            raises(IndexError, d.remove, 'c')
             assert len(d) == 0
 
-class TestDequeExtra:
+class AppTestDequeExtra:
+
+    spaceconfig = dict(usemodules=('binascii', 'struct',))
+
+    def setup_class(cls):
+        cls.w_collections = import_lib_pypy(cls.space, '_collections')
+
     def test_remove_empty(self):
+        collections = self.collections
         d = collections.deque([])
-        py.test.raises(ValueError, d.remove, 1)
+        raises(ValueError, d.remove, 1)
 
     def test_remove_mutating(self):
+        collections = self.collections
         class MutatingCmp(object):
             def __eq__(self, other):
                 d.clear()
                 return True
 
         d = collections.deque([MutatingCmp()])
-        py.test.raises(IndexError, d.remove, 1)
+        raises(IndexError, d.remove, 1)
 
     def test_remove_failing(self):
+        collections = self.collections
         class FailingCmp(object):
             def __eq__(self, other):
                 assert False
         f = FailingCmp()
         d = collections.deque([1, 2, 3, f, 4, 5])
         d.remove(3)
-        py.test.raises(AssertionError, d.remove, 4)
+        raises(AssertionError, d.remove, 4)
         assert d == collections.deque([1, 2, f, 4, 5])
 
     def test_maxlen(self):
+        collections = self.collections
         d = collections.deque([], 3)
         d.append(1); d.append(2); d.append(3); d.append(4)
         assert list(d) == [2, 3, 4]
         assert repr(d3) == "deque([2, 3, 4], maxlen=3)"
 
     def test_count(self):
+        collections = self.collections
         d = collections.deque([1, 2, 2, 3, 2])
         assert d.count(2) == 3
         assert d.count(4) == 0
 
     def test_reverse(self):
+        collections = self.collections
         d = collections.deque([1, 2, 2, 3, 2])
         d.reverse()
         assert list(d) == [2, 3, 2, 2, 1]
         assert list(d) == range(99, -1, -1)
 
     def test_subclass_with_kwargs(self):
+        collections = self.collections
         class SubclassWithKwargs(collections.deque):
             def __init__(self, newarg=1):
                 collections.deque.__init__(self)
         # SF bug #1486663 -- this used to erroneously raise a TypeError
         SubclassWithKwargs(newarg=1)
 
-def foobar():
-    return list
+class AppTestDefaultDict:
 
-class TestDefaultDict:
+    def setup_class(cls):
+        cls.w_collections = import_lib_pypy(cls.space, '_collections')
+
     def test_basic(self):
+        collections = self.collections
         d1 = collections.defaultdict()
         assert d1.default_factory is None
         d1.default_factory = list
         assert 12 not in d2.keys()
         d2.default_factory = None
         assert d2.default_factory == None
-        py.test.raises(KeyError, d2.__getitem__, 15)
-        py.test.raises(TypeError, collections.defaultdict, 1)
+        raises(KeyError, d2.__getitem__, 15)
+        raises(TypeError, collections.defaultdict, 1)
 
     def test_constructor(self):
+        collections = self.collections
         assert collections.defaultdict(None) == {}
         assert collections.defaultdict(None, {1: 2}) == {1: 2}
 
     def test_missing(self):
+        collections = self.collections
         d1 = collections.defaultdict()
-        py.test.raises(KeyError, d1.__missing__, 42)
+        raises(KeyError, d1.__missing__, 42)
         d1.default_factory = list
         assert d1.__missing__(42) == []
 
     def test_repr(self):
+        collections = self.collections
         d1 = collections.defaultdict()
         assert d1.default_factory == None
         assert repr(d1) == "defaultdict(None, {})"
         assert repr(d4) == "defaultdict(%s, {14: defaultdict(None, {})})" % repr(int)
 
     def test_recursive_repr(self):
+        collections = self.collections
         # Issue2045: stack overflow when default_factory is a bound method
         class sub(collections.defaultdict):
             def __init__(self):
             "defaultdict(<bound method sub._factory of defaultdict(...")
 
     def test_copy(self):
+        collections = self.collections
         d1 = collections.defaultdict()
         d2 = d1.copy()
         assert type(d2) == collections.defaultdict
 
     def test_shallow_copy(self):
         import copy
+        collections = self.collections
+        def foobar():
+            return list
         d1 = collections.defaultdict(foobar, {1: 1})
         d2 = copy.copy(d1)
         assert d2.default_factory == foobar
 
     def test_deep_copy(self):
         import copy
+        collections = self.collections
+        def foobar():
+            return list
         d1 = collections.defaultdict(foobar, {1: [1]})
         d2 = copy.deepcopy(d1)
         assert d2.default_factory == foobar
         d2 = copy.deepcopy(d1)
         assert d2.default_factory == list
         assert d2 == d1
-

File pypy/tool/pytest/appsupport.py

View file
  • Ignore whitespace
     except py.test.raises.Exception, e:
         e.tbindex = getattr(e, 'tbindex', -1) - 1
         raise
-
-def eq_w(space, w_obj1, w_obj2): 
-    """ return interp-level boolean of eq(w_obj1, w_obj2). """ 
-    return space.is_true(space.eq(w_obj1, w_obj2))

File pypy/tool/pytest/objspace.py

View file
  • Ignore whitespace
     space.setitem(space.builtin.w_dict, space.wrap('py3k_skip'),
                   space.wrap(appsupport.app_py3k_skip))
     space.raises_w = appsupport.raises_w.__get__(space)
-    space.eq_w = appsupport.eq_w.__get__(space)
     return space