[pypy-commit] pypy SpecialisedTuples: (mwp) refactor test for correct hashes and extend create and eq tests

mwp noreply at buildbot.pypy.org
Thu Nov 10 10:47:43 CET 2011


Author: Mark Pearse <mark.pearse at skynet.be>
Branch: SpecialisedTuples
Changeset: r49097:68b32cfbccbd
Date: 2011-11-06 11:22 +0100
http://bitbucket.org/pypy/pypy/changeset/68b32cfbccbd/

Log:	(mwp) refactor test for correct hashes and extend create and eq
	tests

diff --git a/pypy/objspace/std/test/test_specialisedtupleobject.py b/pypy/objspace/std/test/test_specialisedtupleobject.py
--- a/pypy/objspace/std/test/test_specialisedtupleobject.py
+++ b/pypy/objspace/std/test/test_specialisedtupleobject.py
@@ -22,17 +22,23 @@
         
     def test_hash_against_normal_tuple(self):
         normalspace = gettestobjspace(**{"objspace.std.withspecialisedtuple": False})
-        w_tuple = normalspace.newtuple([self.space.wrap(1), self.space.wrap(2)])
+        specialisedspace = gettestobjspace(**{"objspace.std.withspecialisedtuple": True})
 
-        specialisedspace = gettestobjspace(**{"objspace.std.withspecialisedtuple": True})
-        w_specialisedtuple = specialisedspace.newtuple([self.space.wrap(1), self.space.wrap(2)])
+        def hash_test(values):
+            values_w = [self.space.wrap(value) for value in values]
+            w_tuple =                 normalspace.newtuple(values_w)
+            w_specialisedtuple = specialisedspace.newtuple(values_w)
+    
+            assert isinstance(w_specialisedtuple, W_SpecialisedTupleObject)
+            assert isinstance(w_tuple, W_TupleObject)
+            assert not normalspace.is_true(normalspace.eq(w_tuple, w_specialisedtuple))
+            assert specialisedspace.is_true(specialisedspace.eq(w_tuple, w_specialisedtuple))
+            assert specialisedspace.is_true(specialisedspace.eq(normalspace.hash(w_tuple), specialisedspace.hash(w_specialisedtuple)))
 
-        assert isinstance(w_specialisedtuple, W_SpecialisedTupleObject)
-        assert isinstance(w_tuple, W_TupleObject)
-        assert not normalspace.is_true(normalspace.eq(w_tuple, w_specialisedtuple))
-        assert specialisedspace.is_true(specialisedspace.eq(w_tuple, w_specialisedtuple))
-        assert specialisedspace.is_true(specialisedspace.eq(normalspace.hash(w_tuple), specialisedspace.hash(w_specialisedtuple)))
-
+        hash_test([1,2])
+        hash_test([1.5,2.8])
+        hash_test(['arbitrary','strings'])
+        
     def test_setitem(self):
         py.test.skip('skip for now, only needed for cpyext')
         w_specialisedtuple = self.space.newtuple([self.space.wrap(1)])
@@ -61,6 +67,7 @@
         assert self.isspecialised((42,43))
         assert self.isspecialised((4.2,4.3))
         assert self.isspecialised((1.0,2.0))
+        assert self.isspecialised(('a','b'))
         
     def test_len(self):
         t = self.forbid_delegation((42,43))
@@ -92,6 +99,12 @@
         c = (2,1)
         assert not a == c
         
+        d = (1.0,2.0)
+        assert a == d
+        
+        e = ('r','s')
+        assert not a == e
+        
     def test_eq_can_delegate(self):        
         a = (1,2)
         b = (1,3,2)


More information about the pypy-commit mailing list