Author: Ronan Lamy <[email protected]>
Branch: assert-rewrite
Changeset: r92947:b994fd06043b
Date: 2017-11-05 14:43 +0000
http://bitbucket.org/pypy/pypy/changeset/b994fd06043b/

Log:    Fix asserts in rpython/rtyper/

diff --git a/rpython/rtyper/lltypesystem/test/test_llarena.py 
b/rpython/rtyper/lltypesystem/test/test_llarena.py
--- a/rpython/rtyper/lltypesystem/test/test_llarena.py
+++ b/rpython/rtyper/lltypesystem/test/test_llarena.py
@@ -1,5 +1,6 @@
 import py, os
 
+from rpython.rlib.objectmodel import assert_
 from rpython.rtyper.lltypesystem import lltype, llmemory, rffi, llarena
 from rpython.rtyper.lltypesystem.llarena import (arena_malloc, arena_reset,
     arena_reserve, arena_free, round_up_for_allocation, ArenaError,
@@ -143,12 +144,12 @@
     b = a + round_up_for_allocation(llmemory.sizeof(lltype.Char))
     arena_reserve(b, precomputed_size)
     (b + llmemory.offsetof(SX, 'x')).signed[0] = 123
-    assert llmemory.cast_adr_to_ptr(b, SPTR).x == 123
+    assert_(llmemory.cast_adr_to_ptr(b, SPTR).x == 123)
     llmemory.cast_adr_to_ptr(b, SPTR).x += 1
-    assert (b + llmemory.offsetof(SX, 'x')).signed[0] == 124
+    assert_((b + llmemory.offsetof(SX, 'x')).signed[0] == 124)
     arena_reset(a, myarenasize, True)
     arena_reserve(b, round_up_for_allocation(llmemory.sizeof(SX)))
-    assert llmemory.cast_adr_to_ptr(b, SPTR).x == 0
+    assert_(llmemory.cast_adr_to_ptr(b, SPTR).x == 0)
     arena_free(a)
     return 42
 
@@ -334,7 +335,7 @@
             arena_reserve(a, llmemory.sizeof(S))
             p = llmemory.cast_adr_to_ptr(a + 23432, lltype.Ptr(S))
             p.x = 123
-            assert p.x == 123
+            assert_(p.x == 123)
             arena_protect(a, 65536, True)
             result = 0
             if testrun == 1:
diff --git a/rpython/rtyper/lltypesystem/test/test_llgroup.py 
b/rpython/rtyper/lltypesystem/test/test_llgroup.py
--- a/rpython/rtyper/lltypesystem/test/test_llgroup.py
+++ b/rpython/rtyper/lltypesystem/test/test_llgroup.py
@@ -1,3 +1,4 @@
+from rpython.rlib.objectmodel import assert_
 from rpython.rtyper.lltypesystem.llgroup import *
 from rpython.rtyper.lltypesystem.lloperation import llop
 from rpython.rtyper.test.test_llinterp import interpret
@@ -76,37 +77,37 @@
     #
     def f():
         p = llop.get_group_member(lltype.Ptr(test.S1), grpptr, test.g1a)
-        assert p == test.p1a
+        assert_(p == test.p1a)
         p = llop.get_group_member(lltype.Ptr(test.S1), grpptr, test.g1b)
-        assert p == test.p1b
+        assert_(p == test.p1b)
         p = llop.get_group_member(lltype.Ptr(test.S2), grpptr, test.g2a)
-        assert p == test.p2a
+        assert_(p == test.p2a)
         p = llop.get_group_member(lltype.Ptr(test.S2), grpptr, test.g2b)
-        assert p == test.p2b
+        assert_(p == test.p2b)
         #
         p = llop.get_next_group_member(lltype.Ptr(test.S2), grpptr,
                                        test.g1a, llmemory.sizeof(test.S1))
-        assert p == test.p2a
+        assert_(p == test.p2a)
         p = llop.get_next_group_member(lltype.Ptr(test.S2), grpptr,
                                        test.g2a, llmemory.sizeof(test.S2))
-        assert p == test.p2b
+        assert_(p == test.p2b)
         p = llop.get_next_group_member(lltype.Ptr(test.S1), grpptr,
                                        test.g2b, llmemory.sizeof(test.S2))
-        assert p == test.p1b
+        assert_(p == test.p1b)
         #
         expected = [123, 456]
         for i in range(2):
             p = llop.get_group_member(lltype.Ptr(test.S1), grpptr, g1x[i])
-            assert p.x == expected[i]
+            assert_(p.x == expected[i])
         #
         for i in range(2):
             s = llop.extract_ushort(HALFWORD, cslist[i])
             p = llop.get_group_member(lltype.Ptr(test.S1), grpptr, s)
-            assert p == test.p1b
-        assert cslist[0] & ~MASK == 0x45 << HALFSHIFT
-        assert cslist[1] & ~MASK == 0x41 << HALFSHIFT
-        assert cslist[0] >> HALFSHIFT == 0x45
-        assert cslist[1] >> (HALFSHIFT+1) == 0x41 >> 1
+            assert_(p == test.p1b)
+        assert_(cslist[0] & ~MASK == 0x45 << HALFSHIFT)
+        assert_(cslist[1] & ~MASK == 0x41 << HALFSHIFT)
+        assert_(cslist[0] >> HALFSHIFT == 0x45)
+        assert_(cslist[1] >> (HALFSHIFT+1) == 0x41 >> 1)
         #
         return 42
     return f
diff --git a/rpython/rtyper/lltypesystem/test/test_llmemory.py 
b/rpython/rtyper/lltypesystem/test/test_llmemory.py
--- a/rpython/rtyper/lltypesystem/test/test_llmemory.py
+++ b/rpython/rtyper/lltypesystem/test/test_llmemory.py
@@ -1,3 +1,4 @@
+from rpython.rlib.objectmodel import assert_
 from rpython.rtyper.lltypesystem.llmemory import *
 from rpython.rtyper.lltypesystem import lltype
 from rpython.rtyper.test.test_llinterp import interpret
@@ -40,7 +41,7 @@
     assert b.signed[0] == 123
     b.signed[0] = 234
     assert s2.s.x == 234
-    
+
 def test_array():
     A = lltype.GcArray(lltype.Signed)
     x = lltype.malloc(A, 5)
@@ -85,7 +86,7 @@
     o = AddressOffset()
     py.test.raises(TypeError, "1 + o")
     py.test.raises(TypeError, "o + 1")
-    
+
 def test_sizeof():
     # this is mostly an "assert not raises" sort of test
     array = lltype.Array(lltype.Signed)
@@ -421,7 +422,7 @@
     py.test.raises(RuntimeError, "p_s.x = 2")
     repr(adr)
     str(p_s)
-    
+
     T = lltype.GcStruct('T', ('s', S))
     adr = raw_malloc(sizeof(T))
     p_s = cast_adr_to_ptr(adr, lltype.Ptr(S))
@@ -431,7 +432,7 @@
     py.test.raises(RuntimeError, "p_s.x = 2")
     repr(adr)
     str(p_s)
-    
+
     U = lltype.Struct('U', ('y', lltype.Signed))
     T = lltype.GcStruct('T', ('x', lltype.Signed), ('u', U))
     adr = raw_malloc(sizeof(T))
@@ -446,10 +447,10 @@
 
 def test_raw_free_with_hdr():
     from rpython.memory.gcheader import GCHeaderBuilder
-    
+
     HDR = lltype.Struct('h', ('t', lltype.Signed))
     gh = GCHeaderBuilder(HDR).size_gc_header
-    
+
     A = lltype.GcArray(lltype.Signed)
     adr = raw_malloc(gh+sizeof(A, 10))
     p_a = cast_adr_to_ptr(adr+gh, lltype.Ptr(A))
@@ -471,7 +472,7 @@
     py.test.raises(RuntimeError, "p_s.x = 2")
     repr(adr)
     str(p_s)
-    
+
     T = lltype.GcStruct('T', ('s', S))
     adr = raw_malloc(gh+sizeof(T))
     p_s = cast_adr_to_ptr(adr+gh, lltype.Ptr(S))
@@ -482,7 +483,7 @@
     py.test.raises(RuntimeError, "p_s.x = 2")
     repr(adr)
     str(p_s)
-    
+
     U = lltype.Struct('U', ('y', lltype.Signed))
     T = lltype.GcStruct('T', ('x', lltype.Signed), ('u', U))
     adr = raw_malloc(gh+sizeof(T))
@@ -656,6 +657,6 @@
         ptr = lltype.malloc(A, 10)
         gcref = lltype.cast_opaque_ptr(GCREF, ptr)
         adr = lltype.cast_ptr_to_int(gcref)
-        assert adr == lltype.cast_ptr_to_int(ptr)
+        assert_(adr == lltype.cast_ptr_to_int(ptr))
     f()
     interpret(f, [])
diff --git a/rpython/rtyper/lltypesystem/test/test_rffi.py 
b/rpython/rtyper/lltypesystem/test/test_rffi.py
--- a/rpython/rtyper/lltypesystem/test/test_rffi.py
+++ b/rpython/rtyper/lltypesystem/test/test_rffi.py
@@ -1,6 +1,7 @@
 
 import py
 import sys
+from rpython.rlib.objectmodel import assert_
 from rpython.rtyper.lltypesystem.rffi import *
 from rpython.rtyper.lltypesystem.rffi import _keeper_for_type # crap
 from rpython.rlib.rposix import get_saved_errno, set_saved_errno
@@ -611,9 +612,9 @@
             p1bis = make(X1)
             p2bis = make(X2)
             structcopy(p1bis, p1)
-            assert p1bis.a == 5
-            assert p1bis.x2.x == 456
-            assert p1bis.p == p2
+            assert_(p1bis.a == 5)
+            assert_(p1bis.x2.x == 456)
+            assert_(p1bis.p == p2)
             structcopy(p2bis, p2)
             res = p2bis.x
             lltype.free(p2bis, flavor='raw')
@@ -697,11 +698,11 @@
         def f():
             raw = str2charp("XxxZy")
             n = str2chararray("abcdef", raw, 4)
-            assert raw[0] == 'a'
-            assert raw[1] == 'b'
-            assert raw[2] == 'c'
-            assert raw[3] == 'd'
-            assert raw[4] == 'y'
+            assert_(raw[0] == 'a')
+            assert_(raw[1] == 'b')
+            assert_(raw[2] == 'c')
+            assert_(raw[3] == 'd')
+            assert_(raw[4] == 'y')
             lltype.free(raw, flavor='raw')
             return n
 
@@ -796,9 +797,9 @@
     for i in xrange(len(data)):
         a[i] = data[i]
     a2 = ptradd(a, 2)
-    assert lltype.typeOf(a2) == lltype.typeOf(a) == lltype.Ptr(ARRAY_OF_CHAR)
+    assert_(lltype.typeOf(a2) == lltype.typeOf(a) == lltype.Ptr(ARRAY_OF_CHAR))
     for i in xrange(len(data) - 2):
-        assert a2[i] == a[i + 2]
+        assert_(a2[i] == a[i + 2])
     lltype.free(a, flavor='raw')
 
 def test_ptradd_interpret():
diff --git a/rpython/rtyper/lltypesystem/test/test_ztranslated.py 
b/rpython/rtyper/lltypesystem/test/test_ztranslated.py
--- a/rpython/rtyper/lltypesystem/test/test_ztranslated.py
+++ b/rpython/rtyper/lltypesystem/test/test_ztranslated.py
@@ -1,4 +1,5 @@
 import gc
+from rpython.rlib.objectmodel import assert_
 from rpython.translator.c.test.test_genc import compile
 from rpython.rtyper.lltypesystem import rffi
 from rpython.rtyper.lltypesystem import lltype
@@ -8,7 +9,7 @@
 def debug_assert(boolresult, msg):
     if not boolresult:
         llop.debug_print(lltype.Void, "\n\nassert failed: %s\n\n" % msg)
-        assert boolresult
+        assert_(boolresult)
 
 def use_str():
     mystr = b'abc'
diff --git a/rpython/rtyper/test/test_exception.py 
b/rpython/rtyper/test/test_exception.py
--- a/rpython/rtyper/test/test_exception.py
+++ b/rpython/rtyper/test/test_exception.py
@@ -1,5 +1,6 @@
 import py
 
+from rpython.rlib.objectmodel import assert_
 from rpython.translator.translator import TranslationContext
 from rpython.rtyper.test.tool import BaseRtypingTest
 from rpython.rtyper.llinterp import LLException
diff --git a/rpython/rtyper/test/test_llann.py 
b/rpython/rtyper/test/test_llann.py
--- a/rpython/rtyper/test/test_llann.py
+++ b/rpython/rtyper/test/test_llann.py
@@ -1,6 +1,7 @@
 import py
 
 from rpython.annotator import model as annmodel
+from rpython.rlib.objectmodel import assert_
 from rpython.rtyper.llannotation import SomePtr, lltype_to_annotation
 from rpython.conftest import option
 from rpython.rtyper.annlowlevel import (annotate_lowlevel_helper,
@@ -456,7 +457,7 @@
         s.y = y
         fptr = llhelper(F, f)
         gptr = llhelper(G, g)
-        assert typeOf(fptr) == F
+        assert_(typeOf(fptr) == F)
         return fptr(s, z)+fptr(s, z*2)+gptr(s)
 
     res = interpret(h, [8, 5, 2])
@@ -478,7 +479,7 @@
         s.x = x
         s.y = y
         fptr = llhelper(F, myfuncs[z])
-        assert typeOf(fptr) == F
+        assert_(typeOf(fptr) == F)
         return fptr(s)
 
     res = interpret(h, [80, 5, 0])
diff --git a/rpython/rtyper/test/test_llinterp.py 
b/rpython/rtyper/test/test_llinterp.py
--- a/rpython/rtyper/test/test_llinterp.py
+++ b/rpython/rtyper/test/test_llinterp.py
@@ -1,6 +1,7 @@
-from __future__ import with_statement
 import py
 import sys
+
+from rpython.rlib.objectmodel import assert_
 from rpython.rtyper.lltypesystem.lltype import typeOf, Void, malloc, free
 from rpython.rtyper.llinterp import LLInterpreter, LLException, log
 from rpython.rtyper.rmodel import inputconst
@@ -571,7 +572,7 @@
         with scoped_alloc(T, 1) as array:
             array[0] = -42
             x = array[0]
-        assert x == -42
+        assert_(x == -42)
 
     res = interpret(f, [])
 
diff --git a/rpython/rtyper/test/test_nongc.py 
b/rpython/rtyper/test/test_nongc.py
--- a/rpython/rtyper/test/test_nongc.py
+++ b/rpython/rtyper/test/test_nongc.py
@@ -1,10 +1,10 @@
 import py
 
+from rpython.rlib.objectmodel import assert_, free_non_gc_object
 from rpython.annotator import model as annmodel
+from rpython.annotator.annrpython import RPythonAnnotator
 from rpython.rtyper.llannotation import SomeAddress
-from rpython.annotator.annrpython import RPythonAnnotator
 from rpython.rtyper.rtyper import RPythonTyper
-from rpython.rlib.objectmodel import free_non_gc_object
 from rpython.rtyper.test.test_llinterp import interpret as llinterpret
 
 def interpret(f, args):
@@ -100,13 +100,13 @@
         if i == 0:
             pass
         elif i == 1:
-            assert isinstance(o, A)
+            assert_(isinstance(o, A))
             free_non_gc_object(o)
         elif i == 2:
-            assert isinstance(o, B)
+            assert_(isinstance(o, B))
             free_non_gc_object(o)
         else:
-            assert isinstance(o, C)
+            assert_(isinstance(o, C))
             free_non_gc_object(o)
         return res
 
diff --git a/rpython/rtyper/test/test_rclass.py 
b/rpython/rtyper/test/test_rclass.py
--- a/rpython/rtyper/test/test_rclass.py
+++ b/rpython/rtyper/test/test_rclass.py
@@ -4,6 +4,7 @@
 
 from rpython.flowspace.model import summary
 from rpython.rlib.rarithmetic import r_longlong
+from rpython.rlib.objectmodel import assert_
 from rpython.rtyper.lltypesystem.lltype import (typeOf, Signed, 
getRuntimeTypeInfo,
     identityhash)
 from rpython.rtyper.error import TyperError
@@ -1248,13 +1249,13 @@
                 self.data[i] = v
 
             def __getslice__(self, start, stop):
-                assert start >= 0
-                assert stop >= 0
+                assert_(start >= 0)
+                assert_(stop >= 0)
                 return self.data[start:stop]
 
             def __setslice__(self, start, stop, v):
-                assert start >= 0
-                assert stop >= 0
+                assert_(start >= 0)
+                assert_(stop >= 0)
                 i = 0
                 for n in range(start, stop):
                     self.data[n] = v[i]
diff --git a/rpython/rtyper/test/test_rdict.py 
b/rpython/rtyper/test/test_rdict.py
--- a/rpython/rtyper/test/test_rdict.py
+++ b/rpython/rtyper/test/test_rdict.py
@@ -2,22 +2,24 @@
 from contextlib import contextmanager
 import signal
 
-from rpython.translator.translator import TranslationContext
-from rpython.annotator.model import (
-    SomeInteger, SomeString, SomeChar, SomeUnicodeString, SomeUnicodeCodePoint)
-from rpython.annotator.dictdef import DictKey, DictValue
-from rpython.rtyper.lltypesystem import lltype, rffi
-from rpython.rtyper.lltypesystem import rdict
-from rpython.rtyper.test.tool import BaseRtypingTest
-from rpython.rlib.objectmodel import r_dict
-from rpython.rlib.rarithmetic import r_int, r_uint, r_longlong, r_ulonglong
-
 import py
 from hypothesis import settings
 from hypothesis.strategies import (
     builds, sampled_from, binary, just, integers, text, characters, tuples)
 from hypothesis.stateful import GenericStateMachine, run_state_machine_as_test
 
+from rpython.translator.translator import TranslationContext
+from rpython.annotator.model import (
+    SomeInteger, SomeString, SomeChar, SomeUnicodeString, SomeUnicodeCodePoint)
+from rpython.annotator.dictdef import DictKey, DictValue
+from rpython.rlib.rarithmetic import r_int, r_uint, r_longlong, r_ulonglong
+from rpython.rlib.objectmodel import assert_
+from rpython.rtyper.lltypesystem import lltype, rffi
+from rpython.rtyper.lltypesystem import rdict
+from rpython.rtyper.test.tool import BaseRtypingTest
+from rpython.rlib.objectmodel import r_dict
+
+
 def ann2strategy(s_value):
     if isinstance(s_value, SomeChar):
         return builds(chr, integers(min_value=0, max_value=255))
@@ -192,7 +194,7 @@
             for value in d.itervalues():
                 k2 = k2 * value
             for key, value in d.iteritems():
-                assert d[key] == value
+                assert_(d[key] == value)
                 k3 = k3 * value
             return k1 + k2 + k3
         res = self.interpret(func, [])
@@ -702,15 +704,15 @@
             d[5] = 2
             d[6] = 3
             k1, v1 = d.popitem()
-            assert len(d) == 1
+            assert_(len(d) == 1)
             k2, v2 = d.popitem()
             try:
                 d.popitem()
             except KeyError:
                 pass
             else:
-                assert 0, "should have raised KeyError"
-            assert len(d) == 0
+                assert_(0, "should have raised KeyError")
+            assert_(len(d) == 0)
             return k1*1000 + v1*100 + k2*10 + v2
 
         res = self.interpret(func, [])
@@ -960,15 +962,15 @@
             d[5] = 2
             d[6] = 3
             k1, v1 = d.popitem()
-            assert len(d) == 1
+            assert_(len(d) == 1)
             k2, v2 = d.popitem()
             try:
                 d.popitem()
             except KeyError:
                 pass
             else:
-                assert 0, "should have raised KeyError"
-            assert len(d) == 0
+                assert_(0, "should have raised KeyError")
+            assert_(len(d) == 0)
             return k1*1000 + v1*100 + k2*10 + v2
 
         res = self.interpret(func, [])
diff --git a/rpython/rtyper/test/test_rint.py b/rpython/rtyper/test/test_rint.py
--- a/rpython/rtyper/test/test_rint.py
+++ b/rpython/rtyper/test/test_rint.py
@@ -1,10 +1,12 @@
 import py
-import sys, operator
+import sys
+import operator
+
 from rpython.translator.translator import TranslationContext
+from rpython.rlib.objectmodel import assert_, compute_hash
 from rpython.rtyper.test import snippet
 from rpython.rlib.rarithmetic import r_int, r_uint, r_longlong, r_ulonglong
 from rpython.rlib.rarithmetic import ovfcheck, r_int64, intmask, int_between
-from rpython.rlib import objectmodel
 from rpython.rtyper.test.tool import BaseRtypingTest
 from rpython.flowspace.model import summary
 
@@ -392,16 +394,16 @@
 
     def test_int_py_div_nonnegargs(self):
         def f(x, y):
-            assert x >= 0
-            assert y >= 0
+            assert_(x >= 0)
+            assert_(y >= 0)
             return x // y
         res = self.interpret(f, [1234567, 123])
         assert res == 1234567 // 123
 
     def test_int_py_mod_nonnegargs(self):
         def f(x, y):
-            assert x >= 0
-            assert y >= 0
+            assert_(x >= 0)
+            assert_(y >= 0)
             return x % y
         res = self.interpret(f, [1234567, 123])
         assert res == 1234567 % 123
@@ -418,7 +420,7 @@
 
     def test_hash(self):
         def f(x):
-            return objectmodel.compute_hash(x)
+            return compute_hash(x)
         res = self.interpret(f, [123456789])
         assert res == 123456789
         res = self.interpret(f, [r_int64(123456789012345678)])
diff --git a/rpython/rtyper/test/test_rlist.py 
b/rpython/rtyper/test/test_rlist.py
--- a/rpython/rtyper/test/test_rlist.py
+++ b/rpython/rtyper/test/test_rlist.py
@@ -3,11 +3,13 @@
 
 import py
 
+from rpython.rlib.objectmodel import assert_, newlist_hint, resizelist_hint
 from rpython.rtyper.debug import ll_assert
 from rpython.rtyper.error import TyperError
 from rpython.rtyper.llinterp import LLException, LLAssertFailure
 from rpython.rtyper.lltypesystem import rlist as ll_rlist
-from rpython.rtyper.lltypesystem.rlist import ListRepr, FixedSizeListRepr, 
ll_newlist, ll_fixed_newlist
+from rpython.rtyper.lltypesystem.rlist import (
+    ListRepr, FixedSizeListRepr, ll_newlist, ll_fixed_newlist)
 from rpython.rtyper.rint import signed_repr
 from rpython.rtyper.rlist import *
 from rpython.rtyper.test.tool import BaseRtypingTest
@@ -959,7 +961,7 @@
             x = l.pop()
             x = l.pop()
             x = l2.pop()
-            return str(x)+";"+str(l)
+            return str(x) + ";" + str(l)
         res = self.ll_to_string(self.interpret(fn, []))
         res = res.replace('rpython.rtyper.test.test_rlist.', '')
         res = re.sub(' at 0x[a-z0-9]+', '', res)
@@ -1167,7 +1169,7 @@
             lst = [fr, fr]
             lst.append(fr)
             del lst[1]
-            assert lst[0] is fr
+            assert_(lst[0] is fr)
             return len(lst)
         res = self.interpret(f, [])
         assert res == 2
@@ -1202,9 +1204,9 @@
     def test_list_equality(self):
         def dummyfn(n):
             lst = [12] * n
-            assert lst == [12, 12, 12]
+            assert_(lst == [12, 12, 12])
             lst2 = [[12, 34], [5], [], [12, 12, 12], [5]]
-            assert lst in lst2
+            assert_(lst in lst2)
         self.interpret(dummyfn, [3])
 
     def test_list_remove(self):
@@ -1215,7 +1217,6 @@
         res = self.interpret(dummyfn, [1, 0])
         assert res == 0
 
-
     def test_getitem_exc_1(self):
         def f(x):
             l = [1]
@@ -1339,7 +1340,7 @@
     def test_charlist_extension_2(self):
         def f(n, i):
             s = 'hello%d' % n
-            assert 0 <= i <= len(s)
+            assert_(0 <= i <= len(s))
             l = ['a', 'b']
             l += s[i:]
             return ''.join(l)
@@ -1349,7 +1350,7 @@
     def test_unicharlist_extension_2(self):
         def f(n, i):
             s = 'hello%d' % n
-            assert 0 <= i <= len(s)
+            assert_(0 <= i <= len(s))
             l = [u'a', u'b']
             l += s[i:]
             return ''.join([chr(ord(c)) for c in l])
@@ -1359,7 +1360,7 @@
     def test_extend_a_non_char_list_2(self):
         def f(n, i):
             s = 'hello%d' % n
-            assert 0 <= i <= len(s)
+            assert_(0 <= i <= len(s))
             l = ['foo', 'bar']
             l += s[i:]      # NOT SUPPORTED for now if l is not a list of chars
             return ''.join(l)
@@ -1368,7 +1369,7 @@
     def test_charlist_extension_3(self):
         def f(n, i, j):
             s = 'hello%d' % n
-            assert 0 <= i <= j <= len(s)
+            assert_(0 <= i <= j <= len(s))
             l = ['a', 'b']
             l += s[i:j]
             return ''.join(l)
@@ -1378,7 +1379,7 @@
     def test_unicharlist_extension_3(self):
         def f(n, i, j):
             s = 'hello%d' % n
-            assert 0 <= i <= j <= len(s)
+            assert_(0 <= i <= j <= len(s))
             l = [u'a', u'b']
             l += s[i:j]
             return ''.join([chr(ord(c)) for c in l])
@@ -1491,8 +1492,6 @@
                    ("y[*]" in immutable_fields)
 
     def test_hints(self):
-        from rpython.rlib.objectmodel import newlist_hint
-
         strings = ['abc', 'def']
         def f(i):
             z = strings[i]
@@ -1569,8 +1568,8 @@
     def test_no_unneeded_refs(self):
         def fndel(p, q):
             lis = ["5", "3", "99"]
-            assert q >= 0
-            assert p >= 0
+            assert_(q >= 0)
+            assert_(p >= 0)
             del lis[p:q]
             return lis
         def fnpop(n):
@@ -1677,7 +1676,6 @@
 
     def test_extend_was_not_overallocating(self):
         from rpython.rlib import rgc
-        from rpython.rlib.objectmodel import resizelist_hint
         from rpython.rtyper.lltypesystem import lltype
         old_arraycopy = rgc.ll_arraycopy
         try:
diff --git a/rpython/rtyper/test/test_rordereddict.py 
b/rpython/rtyper/test/test_rordereddict.py
--- a/rpython/rtyper/test/test_rordereddict.py
+++ b/rpython/rtyper/test/test_rordereddict.py
@@ -1,10 +1,10 @@
 import py
-import random
 from collections import OrderedDict
 
 from hypothesis import settings, given, strategies
 from hypothesis.stateful import run_state_machine_as_test
 
+from rpython.rlib.objectmodel import assert_, r_ordereddict
 from rpython.rtyper.lltypesystem import lltype, rffi
 from rpython.rtyper.lltypesystem import rordereddict, rstr
 from rpython.rlib.rarithmetic import intmask
@@ -387,7 +387,7 @@
 
     @staticmethod
     def new_r_dict(myeq, myhash):
-        return objectmodel.r_ordereddict(myeq, myhash)
+        return r_ordereddict(myeq, myhash)
 
     def test_two_dicts_with_different_value_types(self):
         def func(i):
@@ -406,14 +406,14 @@
             d1['key2'] = 'value2'
             for i in range(20):
                 objectmodel.move_to_end(d1, 'key1')
-                assert d1.keys() == ['key2', 'key1']
+                assert_(d1.keys() == ['key2', 'key1'])
                 objectmodel.move_to_end(d1, 'key2')
-                assert d1.keys() == ['key1', 'key2']
+                assert_(d1.keys() == ['key1', 'key2'])
             for i in range(20):
                 objectmodel.move_to_end(d1, 'key2', last=False)
-                assert d1.keys() == ['key2', 'key1']
+                assert_(d1.keys() == ['key2', 'key1'])
                 objectmodel.move_to_end(d1, 'key1', last=False)
-                assert d1.keys() == ['key1', 'key2']
+                assert_(d1.keys() == ['key1', 'key2'])
         func()
         self.interpret(func, [])
 
diff --git a/rpython/rtyper/test/test_rpbc.py b/rpython/rtyper/test/test_rpbc.py
--- a/rpython/rtyper/test/test_rpbc.py
+++ b/rpython/rtyper/test/test_rpbc.py
@@ -2,6 +2,7 @@
 
 from rpython.annotator import model as annmodel
 from rpython.annotator import specialize
+from rpython.rlib.objectmodel import assert_
 from rpython.rtyper.lltypesystem.lltype import typeOf
 from rpython.rtyper.test.tool import BaseRtypingTest
 from rpython.rtyper.llannotation import SomePtr, lltype_to_annotation
@@ -1604,7 +1605,7 @@
             try:
                 o.m()
             except KeyError:
-                assert 0
+                raise ValueError
             return B().m()
 
         self.interpret_raises(KeyError, f, [7])
@@ -1717,7 +1718,7 @@
         def cb2():
             pass
         def g(cb, result):
-            assert (cb is None) == (result == 0)
+            assert_((cb is None) == (result == 0))
         def h(cb):
             cb()
         def f():
diff --git a/rpython/rtyper/test/test_rptr.py b/rpython/rtyper/test/test_rptr.py
--- a/rpython/rtyper/test/test_rptr.py
+++ b/rpython/rtyper/test/test_rptr.py
@@ -6,9 +6,11 @@
 from rpython.rtyper.llannotation import SomePtr
 from rpython.annotator.annrpython import RPythonAnnotator
 from rpython.rlib.rarithmetic import is_valid_int
+from rpython.rlib.objectmodel import assert_
 from rpython.rtyper.annlowlevel import annotate_lowlevel_helper, 
LowLevelAnnotatorPolicy
 from rpython.rtyper.lltypesystem import llmemory, lltype
 from rpython.rtyper.rtyper import RPythonTyper
+from rpython.rtyper.test.test_llinterp import interpret
 
 
 # ____________________________________________________________
@@ -50,7 +52,6 @@
     assert s == 
annmodel.SomeTuple([SomePtr(lltype.Ptr(lltype.RuntimeTypeInfo)),
                                     annmodel.SomeBool()])
 
-from rpython.rtyper.test.test_llinterp import interpret, gengraph
 
 def test_adtmeths():
     policy = LowLevelAnnotatorPolicy()
@@ -86,7 +87,6 @@
     assert lltype.typeOf(a) == lltype.Ptr(A)
     assert len(a) == 10
 
-
     def f():
         a = A.h_alloc(10)
         return a.h_length()
@@ -104,15 +104,15 @@
     S = lltype.GcStruct('S', ('t', T))
     PT = lltype.Ptr(T)
     PS = lltype.Ptr(S)
+
     def fn(n):
         s = lltype.cast_int_to_ptr(PS, n)
-        assert lltype.typeOf(s) == PS
-        assert lltype.cast_ptr_to_int(s) == n
+        assert_(lltype.typeOf(s) == PS)
+        assert_(lltype.cast_ptr_to_int(s) == n)
         t = lltype.cast_pointer(PT, s)
-        assert lltype.typeOf(t) == PT
-        assert lltype.cast_ptr_to_int(t) == n
-        assert s == lltype.cast_pointer(PS, t)
-
+        assert_(lltype.typeOf(t) == PT)
+        assert_(lltype.cast_ptr_to_int(t) == n)
+        assert_(s == lltype.cast_pointer(PS, t))
     interpret(fn, [11521])
 
 def test_odd_ints_opaque():
@@ -120,12 +120,13 @@
     Q = lltype.GcOpaqueType('Q')
     PT = lltype.Ptr(T)
     PQ = lltype.Ptr(Q)
+
     def fn(n):
         t = lltype.cast_int_to_ptr(PT, n)
-        assert lltype.typeOf(t) == PT
-        assert lltype.cast_ptr_to_int(t) == n
+        assert_(lltype.typeOf(t) == PT)
+        assert_(lltype.cast_ptr_to_int(t) == n)
         o = lltype.cast_opaque_ptr(PQ, t)
-        assert lltype.cast_ptr_to_int(o) == n
+        assert_(lltype.cast_ptr_to_int(o) == n)
 
     fn(13)
     interpret(fn, [11521])
@@ -384,6 +385,7 @@
 
 def test_interior_ptr_with_setitem():
     T = lltype.GcStruct("T", ('s', lltype.Array(lltype.Signed)))
+
     def f():
         t = lltype.malloc(T, 1)
         t.s[0] = 1
@@ -393,18 +395,21 @@
 
 def test_isinstance_ptr():
     S = lltype.GcStruct("S", ('x', lltype.Signed))
+
     def f(n):
         x = isinstance(lltype.Signed, lltype.Ptr)
         return x + (lltype.typeOf(x) is lltype.Ptr(S)) + len(n)
+
     def lltest():
         f([])
         return f([1])
     s, t = ll_rtype(lltest, [])
-    assert s.is_constant() == False
+    assert s.is_constant() is False
 
 def test_staticadtmeths():
     ll_func = lltype.staticAdtMethod(lambda x: x + 42)
     S = lltype.GcStruct('S', adtmeths={'ll_func': ll_func})
+
     def f():
         return lltype.malloc(S).ll_func(5)
     s, t = ll_rtype(f, [])
diff --git a/rpython/rtyper/test/test_rstr.py b/rpython/rtyper/test/test_rstr.py
--- a/rpython/rtyper/test/test_rstr.py
+++ b/rpython/rtyper/test/test_rstr.py
@@ -4,6 +4,7 @@
 
 from rpython.flowspace.model import summary
 from rpython.annotator.model import AnnotatorError
+from rpython.rlib.objectmodel import assert_
 from rpython.rtyper.lltypesystem.lltype import typeOf, Signed, malloc
 from rpython.rtyper.lltypesystem.rstr import LLHelpers, STR
 from rpython.rtyper.rstr import AbstractLLHelpers
@@ -357,20 +358,24 @@
 
     def test_find_with_start(self):
         const = self.const
+
         def fn(i):
-            assert i >= 0
+            assert_(i >= 0)
             return const('ababcabc').find(const('abc'), i)
+
         for i in range(9):
             res = self.interpret(fn, [i])
             assert res == fn(i)
 
     def test_find_with_start_end(self):
         const = self.const
+
         def fn(i, j):
-            assert i >= 0
-            assert j >= 0
+            assert_(i >= 0)
+            assert_(j >= 0)
             return (const('ababcabc').find(const('abc'), i, j) +
                     const('ababcabc').find(const('b'), i, j) * 100)
+
         for (i, j) in [(1,7), (2,6), (3,7), (3,8), (4,99), (7, 99)]:
             res = self.interpret(fn, [i, j])
             assert res == fn(i, j)
@@ -388,14 +393,16 @@
 
     def test_find_empty_string(self):
         const = self.const
+
         def f(i):
-            assert i >= 0
+            assert_(i >= 0)
             s = const("abc")
             x = s.find(const(''))
             x+= s.find(const(''), i)*10
             x+= s.find(const(''), i, i)*100
             x+= s.find(const(''), i, i+1)*1000
             return x
+
         for i, expected in enumerate([0, 1110, 2220, 3330, -1110, -1110]):
             res = self.interpret(f, [i])
             assert res == expected
@@ -418,14 +425,16 @@
 
     def test_rfind_empty_string(self):
         const = self.const
+
         def f(i):
-            assert i >= 0
+            assert_(i >= 0)
             s = const("abc")
             x = s.rfind(const(''))
             x+= s.rfind(const(''), i)*10
             x+= s.rfind(const(''), i, i)*100
             x+= s.rfind(const(''), i, i+1)*1000
             return x
+
         for i, expected in enumerate([1033, 2133, 3233, 3333, 3-1110, 3-1110]):
             res = self.interpret(f, [i])
             assert res == expected
@@ -557,7 +566,7 @@
 
         def fn(i):
             c = ["a", "b", "c"]
-            assert i >= 0
+            assert_(i >= 0)
             return const('').join(c[i:])
         res = self.interpret(fn, [0])
         assert self.ll_to_string(res) == const("abc")
diff --git a/rpython/rtyper/test/test_rtuple.py 
b/rpython/rtyper/test/test_rtuple.py
--- a/rpython/rtyper/test/test_rtuple.py
+++ b/rpython/rtyper/test/test_rtuple.py
@@ -1,11 +1,11 @@
 import py
+from rpython.rlib.objectmodel import assert_, compute_hash
 from rpython.rtyper.rtuple import TUPLE_TYPE, TupleRepr
 from rpython.rtyper.lltypesystem.lltype import Signed, Bool
 from rpython.rtyper.rbool import bool_repr
 from rpython.rtyper.rint import signed_repr
 from rpython.rtyper.test.tool import BaseRtypingTest
 from rpython.rtyper.error import TyperError
-from rpython.rlib.objectmodel import compute_hash
 from rpython.translator.translator import TranslationContext
 
 
@@ -290,7 +290,7 @@
             res = []
             for x in lst:
                 res.append(list(x))
-            assert res[0] == res[1] == res[2] == []
+            assert_(res[0] == res[1] == res[2] == [])
         self.interpret(f, [])
 
     def test_slice(self):
@@ -299,14 +299,14 @@
             return t[1:] + t[:-1] + t[12:] + t[0:2]
         def f(n):
             res = g(n)
-            assert len(res) == 6
-            assert res[0] == "hello"
-            assert res[1] == n
-            assert res[2] == 1.5
-            assert res[3] == "hello"
-            assert res[4] == 1.5
-            assert res[5] == "hello"
-        self.interpret(f, [9])
+            assert_(len(res) == 6)
+            assert_(res[0] == "hello")
+            assert_(res[1] == n)
+            assert_(res[2] == 1.5)
+            assert_(res[3] == "hello")
+            assert_(res[4] == 1.5)
+            assert_(res[5] == "hello")
+        res = self.interpret(f, [9])
 
     def test_tuple_eq(self):
         def f(n):
@@ -350,8 +350,8 @@
 
     def test_tuple_str(self):
         def f(n):
-            assert str(()) == "()"
-            assert str((n,)) == "(%d,)" % n
-            assert str((n, 6)) == "(%d, 6)" % n
-            assert str(((n,),)) == "((%d,),)" % n
+            assert_(str(()) == "()")
+            assert_(str((n,)) == "(%d,)" % n)
+            assert_(str((n, 6)) == "(%d, 6)" % n)
+            assert_(str(((n,),)) == "((%d,),)" % n)
         self.interpret(f, [3])
diff --git a/rpython/rtyper/test/test_rweakref.py 
b/rpython/rtyper/test/test_rweakref.py
--- a/rpython/rtyper/test/test_rweakref.py
+++ b/rpython/rtyper/test/test_rweakref.py
@@ -1,5 +1,7 @@
-import py, weakref
+import weakref
+
 from rpython.rlib import rgc
+from rpython.rlib.objectmodel import assert_
 from rpython.rtyper.lltypesystem import lltype, llmemory
 from rpython.rtyper.test.tool import BaseRtypingTest
 
@@ -68,9 +70,9 @@
                 r = w2
             return r() is not None
         res = self.interpret(f, [1])
-        assert res == False
+        assert res is False
         res = self.interpret(f, [0])
-        assert res == True
+        assert res is True
 
     def test_multiple_prebuilt_dead_weakrefs(self):
         class A:
@@ -95,22 +97,22 @@
                     r = w1
                 else:
                     r = w3
-                assert r() is None
+                assert_(r() is None)
             else:
                 if n < -5:
                     r = w2
                 else:
                     r = w4
-                assert r() is not None
+                assert_(r() is not None)
             return r() is not None
         res = self.interpret(f, [1])
-        assert res == False
+        assert res is False
         res = self.interpret(f, [0])
-        assert res == True
+        assert res is True
         res = self.interpret(f, [100])
-        assert res == False
+        assert res is False
         res = self.interpret(f, [-100])
-        assert res == True
+        assert res is True
 
     def test_pbc_null_weakref(self):
         class A:
@@ -124,12 +126,12 @@
         assert self.interpret(fn, [1]) is True
 
     def test_ll_weakref(self):
-        S = lltype.GcStruct('S', ('x',lltype.Signed))
+        S = lltype.GcStruct('S', ('x', lltype.Signed))
         def g():
             s = lltype.malloc(S)
             w = llmemory.weakref_create(s)
-            assert llmemory.weakref_deref(lltype.Ptr(S), w) == s
-            assert llmemory.weakref_deref(lltype.Ptr(S), w) == s
+            assert_(llmemory.weakref_deref(lltype.Ptr(S), w) == s)
+            assert_(llmemory.weakref_deref(lltype.Ptr(S), w) == s)
             return w   # 's' is forgotten here
         def f():
             w = g()
@@ -152,7 +154,7 @@
         def fn(i):
             w = g()
             rgc.collect()
-            assert w() is not None
+            assert_(w() is not None)
             return mylist[i] is None
 
         assert self.interpret(fn, [0], rweakref=False) is False
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to