diff --git a/rpython/annotator/test/test_annrpython.py b/rpython/annotator/test/test_annrpython.py index ebf4d12271d60dfcce67eee1197ecc069e93ed72..c16f8370555a4e4b9fd8e3a566f2af373d3f863a 100644 --- a/rpython/annotator/test/test_annrpython.py +++ b/rpython/annotator/test/test_annrpython.py @@ -18,6 +18,7 @@ from rpython.flowspace.model import * from rpython.rlib.rarithmetic import r_uint, base_int, r_longlong, r_ulonglong from rpython.rlib.rarithmetic import r_singlefloat from rpython.rlib import objectmodel +from rpython.rlib.objectmodel import assert_ from rpython.flowspace.flowcontext import FlowingError from rpython.flowspace.operation import op @@ -868,7 +869,7 @@ class TestAnnotateTestCase: class C(B): pass def f(x): - assert type(x) is C + assert_(type(x) is C) return x a = self.RPythonAnnotator() s = a.build_types(f, [B]) @@ -904,10 +905,10 @@ class TestAnnotateTestCase: assert isinstance(s, annmodel.SomeString) def test_ann_assert(self): - def assert_(x): - assert x,"XXX" + def my_assert(x): + assert_(x, "XXX") a = self.RPythonAnnotator() - s = a.build_types(assert_, [int]) + s = a.build_types(my_assert, [int]) assert s.const is None def test_string_and_none(self): @@ -1069,7 +1070,7 @@ class TestAnnotateTestCase: if a: c = a else: - assert b >= 0 + assert_(b >= 0) c = b return c a = self.RPythonAnnotator() @@ -1224,7 +1225,7 @@ class TestAnnotateTestCase: def alloc(cls): i = inst(cls) - assert isinstance(i, cls) + assert_(isinstance(i, cls)) return i alloc._annspecialcase_ = "specialize:arg(0)" @@ -1260,9 +1261,9 @@ class TestAnnotateTestCase: def alloc(cls, cls2): i = cls() - assert isinstance(i, cls) + assert_(isinstance(i, cls)) j = cls2() - assert isinstance(j, cls2) + assert_(isinstance(j, cls2)) return i def f(): @@ -1370,7 +1371,7 @@ class TestAnnotateTestCase: class T(object): pass def g(l): - assert isinstance(l, list) + assert_(isinstance(l, list)) return l def f(): l = [T()] @@ -1658,7 +1659,7 @@ class TestAnnotateTestCase: def test_more_nonneg_cleverness(self): def f(start, stop): - assert 0 <= start <= stop + assert_(0 <= start <= stop) return start, stop a = self.RPythonAnnotator() s = a.build_types(f, [int, int]) @@ -1666,7 +1667,7 @@ class TestAnnotateTestCase: def test_more_general_nonneg_cleverness(self): def f(start, stop): - assert 0 <= start <= stop + assert_(0 <= start <= stop) return start, stop a = self.RPythonAnnotator() s = a.build_types(f, [r_longlong, r_longlong]) @@ -1838,7 +1839,7 @@ class TestAnnotateTestCase: def test_int_nonneg(self): def f(x, y): - assert x >= 0 + assert_(x >= 0) return int(x) + int(y == 3) a = self.RPythonAnnotator() s = a.build_types(f, [int, int]) @@ -3362,7 +3363,7 @@ class TestAnnotateTestCase: def g(): should_not_see_this def f(n): - assert n >= 0 + assert_(n >= 0) if n < 0: g() if not (n >= 0): @@ -4215,7 +4216,7 @@ class TestAnnotateTestCase: class B(A): def __init__(self, x): - assert x >= 0 + assert_(x >= 0) self.x = x def fn(i): diff --git a/rpython/flowspace/flowcontext.py b/rpython/flowspace/flowcontext.py index d960089a0569e50f67f6663c4e67703b011e4bb2..e9f1ea395119ac359bc6ac53b840202043ec3b37 100644 --- a/rpython/flowspace/flowcontext.py +++ b/rpython/flowspace/flowcontext.py @@ -768,7 +768,6 @@ class FlowContext(object): w_value = self.peekvalue() if self.guessbool(op.bool(w_value).eval(self)): return target - return target self.popvalue() def JUMP_IF_NOT_DEBUG(self, target): diff --git a/rpython/flowspace/specialcase.py b/rpython/flowspace/specialcase.py index 69d9caa3f7ea978b22ce64d208e7fb4bde1224df..144c220aa5f0e7a6270d77fd2c35d62e01a74d13 100644 --- a/rpython/flowspace/specialcase.py +++ b/rpython/flowspace/specialcase.py @@ -32,13 +32,12 @@ def sc_import(ctx, *args_w): @register_flow_sc(locals) def sc_locals(_, *args): - raise Exception( - "A function calling locals() is not RPython. " - "Note that if you're translating code outside the PyPy " - "repository, a likely cause is that py.test's --assert=rewrite " - "mode is getting in the way. You should copy the file " - "pytest.ini from the root of the PyPy repository into your " - "own project.") + from rpython.flowspace.flowcontext import FlowingError + raise FlowingError( + "A function calling locals() is not RPython. A likely cause is that " + "py.test's assert rewriting is getting in the way. If so, you " + "should use `rpython.rlib.objectmodel.assert_()` instead of an " + "assert statement here.") @register_flow_sc(getattr) def sc_getattr(ctx, w_obj, w_index, w_default=None): diff --git a/rpython/jit/metainterp/test/test_ajit.py b/rpython/jit/metainterp/test/test_ajit.py index 0dafd207dc161203ffc838de6831ee1291bd682e..2c414ff21cd2991820e4f331ebc2fc928adc1c87 100644 --- a/rpython/jit/metainterp/test/test_ajit.py +++ b/rpython/jit/metainterp/test/test_ajit.py @@ -4,6 +4,7 @@ import sys import py import weakref +from rpython.rlib.objectmodel import assert_ from rpython.rlib import rgc from rpython.jit.codewriter.policy import StopAtXPolicy from rpython.jit.metainterp import history @@ -152,7 +153,7 @@ class BasicTests: res += ovfcheck(x * x) y -= 1 except OverflowError: - assert 0 + assert_(0) return res res = self.meta_interp(f, [6, 7]) assert res == 1323 @@ -188,7 +189,7 @@ class BasicTests: try: res += ovfcheck(x * x) + b except OverflowError: - assert 0 + assert_(0) y -= 1 return res res = self.meta_interp(f, [6, 7]) @@ -824,7 +825,7 @@ class BasicTests: return llop.int_between(lltype.Bool, arg1, arg2, arg3) """ % locals()).compile(), loc) res = self.interp_operations(loc['f'], [5, 6, 7]) - assert res == expect_result + assert_(res == expect_result) self.check_operations_history(expect_operations) # check('n', 'm', 'p', True, int_sub=2, uint_lt=1) @@ -1028,7 +1029,7 @@ class BasicTests: while i < 10: myjitdriver.can_enter_jit(i=i, t=t) myjitdriver.jit_merge_point(i=i, t=t) - assert i > 0 + assert_(i > 0) t += int_c_div(100, i) - int_c_mod(100, i) i += 1 return t @@ -1251,7 +1252,7 @@ class BasicTests: # to the backend at all: ZeroDivisionError # def f(n): - assert n >= 0 + assert_(n >= 0) try: return ovfcheck(5 % n) except ZeroDivisionError: @@ -1262,7 +1263,7 @@ class BasicTests: assert res == -666 # def f(n): - assert n >= 0 + assert_(n >= 0) try: return ovfcheck(6 // n) except ZeroDivisionError: @@ -1381,7 +1382,7 @@ class BasicTests: else: obj = A() obj.a = 17 - assert isinstance(obj, B) + assert_(isinstance(obj, B)) return obj.a res = self.interp_operations(fn, [1]) assert res == 1 @@ -1953,8 +1954,8 @@ class BasicTests: a2 = f(A(x), y) b1 = f(B(x), y) b2 = f(B(x), y) - assert a1.val == a2.val - assert b1.val == b2.val + assert_(a1.val == a2.val) + assert_(b1.val == b2.val) return a1.val + b1.val res = self.meta_interp(g, [6, 7]) assert res == 6*8 + 6**8 @@ -1997,8 +1998,8 @@ class BasicTests: a2 = f(A(x), y) b1 = f(B(x), y) b2 = f(B(x), y) - assert a1.val == a2.val - assert b1.val == b2.val + assert_(a1.val == a2.val) + assert_(b1.val == b2.val) return a1.val + b1.val res = self.meta_interp(g, [6, 20]) assert res == g(6, 20) @@ -2032,16 +2033,16 @@ class BasicTests: def g(x, y): a1 = f(A(x), y, A(x)) a2 = f(A(x), y, A(x)) - assert a1.val == a2.val + assert_(a1.val == a2.val) b1 = f(B(x), y, B(x)) b2 = f(B(x), y, B(x)) - assert b1.val == b2.val + assert_(b1.val == b2.val) c1 = f(B(x), y, A(x)) c2 = f(B(x), y, A(x)) - assert c1.val == c2.val + assert_(c1.val == c2.val) d1 = f(A(x), y, B(x)) d2 = f(A(x), y, B(x)) - assert d1.val == d2.val + assert_(d1.val == d2.val) return a1.val + b1.val + c1.val + d1.val res = self.meta_interp(g, [3, 14]) assert res == g(3, 14) @@ -2072,7 +2073,7 @@ class BasicTests: def g(x, y): c1 = f(A(x), y, B(x)) c2 = f(A(x), y, B(x)) - assert c1.val == c2.val + assert_(c1.val == c2.val) return c1.val res = self.meta_interp(g, [3, 16]) assert res == g(3, 16) @@ -2099,7 +2100,7 @@ class BasicTests: def g(x, y): a1 = f(A(x), y, A(x)) a2 = f(A(x), y, A(x)) - assert a1.val == a2.val + assert_(a1.val == a2.val) return a1.val res = self.meta_interp(g, [3, 14]) assert res == g(3, 14) @@ -2124,7 +2125,7 @@ class BasicTests: def g(x, y): a1 = f(A(x), y) a2 = f(A(x), y) - assert a1.val == a2.val + assert_(a1.val == a2.val) return a1.val res = self.meta_interp(g, [6, 14]) assert res == g(6, 14) @@ -2151,7 +2152,7 @@ class BasicTests: def g(x, y): a1 = f(A(x), y) a2 = f(A(x), y) - assert a1.val == a2.val + assert_(a1.val == a2.val) return a1.val res = self.meta_interp(g, [6, 14]) assert res == g(6, 14) @@ -2187,8 +2188,8 @@ class BasicTests: a2 = f(A(x), y) b1 = f(B(x), y) b2 = f(B(x), y) - assert a1.val == a2.val - assert b1.val == b2.val + assert_(a1.val == a2.val) + assert_(b1.val == b2.val) return a1.val + b1.val res = self.meta_interp(g, [3, 23]) assert res == 7068153 @@ -2769,7 +2770,7 @@ class BasicTests: try: sa += ovfcheck(i + i) except OverflowError: - assert 0 + assert_(0) node1 = A(i) i += 1 assert self.meta_interp(f, [20, 7]) == f(20, 7) @@ -2801,7 +2802,7 @@ class BasicTests: sa += 1 else: sa += 2 - assert -100 < i < 100 + assert_(-100 < i < 100) i += 1 return sa assert self.meta_interp(f, [20]) == f(20) @@ -2822,7 +2823,7 @@ class BasicTests: sa += 1 else: sa += 2 - assert -100 <= node.val <= 100 + assert_(-100 <= node.val <= 100) i += 1 return sa assert self.meta_interp(f, [20]) == f(20) @@ -3902,13 +3903,13 @@ class BaseLLtypeTests(BasicTests): def f(x): a = make(x) if x > 0: - assert isinstance(a, A) + assert_(isinstance(a, A)) z = a.f() elif x < 0: - assert isinstance(a, B) + assert_(isinstance(a, B)) z = a.f() else: - assert isinstance(a, C) + assert_(isinstance(a, C)) z = a.f() return z + a.g() res1 = f(6) @@ -4265,7 +4266,7 @@ class TestLLtype(BaseLLtypeTests, LLJitMixin): return x > x or x > x if cmp == 'ge': return x >= x and x >= x - assert 0 + assert_(0) return f def make_str(cmp): @@ -4275,7 +4276,7 @@ class TestLLtype(BaseLLtypeTests, LLJitMixin): return x is x or x is x if cmp == 'ne': return x is not x and x is not x - assert 0 + assert_(0) return f def make_object(cmp): @@ -4287,7 +4288,7 @@ class TestLLtype(BaseLLtypeTests, LLJitMixin): return x is x if cmp == 'ne': return x is not x - assert 0 + assert_(0) return f for cmp in 'eq ne lt le gt ge'.split(): diff --git a/rpython/jit/metainterp/test/test_bytearray.py b/rpython/jit/metainterp/test/test_bytearray.py index 1c3ea2273509fcdf5847621ef551c86264756c7a..40804b17af43f28e5d05684ea5a22ec414ebdb15 100644 --- a/rpython/jit/metainterp/test/test_bytearray.py +++ b/rpython/jit/metainterp/test/test_bytearray.py @@ -1,13 +1,14 @@ import py +from rpython.rlib.objectmodel import assert_ from rpython.jit.metainterp.test.support import LLJitMixin -from rpython.rlib.jit import JitDriver, dont_look_inside +from rpython.rlib.jit import dont_look_inside class TestByteArray(LLJitMixin): def test_getitem(self): x = bytearray("foobar") def fn(n): - assert n >= 0 + assert_(n >= 0) return x[n] res = self.interp_operations(fn, [3]) assert res == ord('b') @@ -31,7 +32,7 @@ class TestByteArray(LLJitMixin): def make_me(): return bytearray("foobar") def fn(n): - assert n >= 0 + assert_(n >= 0) x = make_me() x[n] = 3 return x[3] + 1000 * x[4] diff --git a/rpython/jit/metainterp/test/test_call.py b/rpython/jit/metainterp/test/test_call.py index 422333f82e1b344fa83b7608a736132dd0109309..2f2e9d4940974f1db602ab137a8558c675b18c53 100644 --- a/rpython/jit/metainterp/test/test_call.py +++ b/rpython/jit/metainterp/test/test_call.py @@ -1,4 +1,4 @@ - +from rpython.rlib.objectmodel import assert_ from rpython.jit.metainterp.test.support import LLJitMixin, noConst from rpython.rlib import jit @@ -146,8 +146,8 @@ class CallTest(object): while n > 0: myjitdriver.can_enter_jit(n=n, p=p, m=m) myjitdriver.jit_merge_point(n=n, p=p, m=m) - assert p > -1 - assert p < 1 + assert_(p > -1) + assert_(p < 1) n -= jit.conditional_call_elidable(p, externfn, n) return n res = self.meta_interp(f, [21, 5, 0]) @@ -165,8 +165,8 @@ class CallTest(object): while n > 0: myjitdriver.can_enter_jit(n=n, p=p, m=m) myjitdriver.jit_merge_point(n=n, p=p, m=m) - assert p > -1 - assert p < 1 + assert_(p > -1) + assert_(p < 1) n0 = n n -= jit.conditional_call_elidable(p, externfn, n0) n -= jit.conditional_call_elidable(p, externfn, n0) diff --git a/rpython/jit/metainterp/test/test_del.py b/rpython/jit/metainterp/test/test_del.py index 5466ca6fe74c7ca4fcfbc1d8b6ccf538ac026ed1..41db025bcc19e7c99261993254bbf75b0ebe7cfc 100644 --- a/rpython/jit/metainterp/test/test_del.py +++ b/rpython/jit/metainterp/test/test_del.py @@ -1,6 +1,6 @@ import py from rpython.rlib.jit import JitDriver, dont_look_inside -from rpython.rlib.objectmodel import keepalive_until_here +from rpython.rlib.objectmodel import keepalive_until_here, assert_ from rpython.rlib import rgc from rpython.jit.metainterp.test.support import LLJitMixin @@ -30,7 +30,7 @@ class DelTests: 'jump': 1}) def test_class_of_allocated(self): - myjitdriver = JitDriver(greens = [], reds = ['n', 'x']) + myjitdriver = JitDriver(greens=[], reds=['n', 'x']) class Foo: def __del__(self): pass @@ -49,16 +49,15 @@ class DelTests: myjitdriver.jit_merge_point(x=x, n=n) x = X() y = Y() - assert x.f() == 456 - assert y.f() == 123 + assert_(x.f() == 456) + assert_(y.f() == 123) n -= 1 return 42 res = self.meta_interp(f, [20]) assert res == 42 def test_instantiate_with_or_without_del(self): - import gc - mydriver = JitDriver(reds = ['n', 'x'], greens = []) + mydriver = JitDriver(reds=['n', 'x'], greens=[]) class Base: pass class A(Base): foo = 72 class B(Base): diff --git a/rpython/jit/metainterp/test/test_dict.py b/rpython/jit/metainterp/test/test_dict.py index 77b5567fde7d85197009fd13bf7fe472cde687f4..f58764b0cdab29fba5696793af389a9820b2980b 100644 --- a/rpython/jit/metainterp/test/test_dict.py +++ b/rpython/jit/metainterp/test/test_dict.py @@ -1,8 +1,8 @@ +from collections import OrderedDict import py +from rpython.rlib.objectmodel import assert_, r_dict, compute_hash from rpython.jit.metainterp.test.support import LLJitMixin from rpython.rlib.jit import JitDriver -from rpython.rlib import objectmodel -from collections import OrderedDict class DictTests: @staticmethod @@ -104,7 +104,7 @@ class DictTests: return (x & 1) == (y & 1) def f(n): - dct = objectmodel.r_dict(eq, key) + dct = r_dict(eq, key) total = n while total: myjitdriver.jit_merge_point(total=total, dct=dct) @@ -145,7 +145,7 @@ class DictTests: return (x & 1) == (y & 1) def f(n): - dct = objectmodel.r_dict(eq, key) + dct = r_dict(eq, key) total = n while total: myjitdriver.jit_merge_point(total=total, dct=dct) @@ -169,13 +169,13 @@ class DictTests: def eq_func(a, b): return a.value == b.value def hash_func(x): - return objectmodel.compute_hash(x.value) + return compute_hash(x.value) def f(n): d = None while n > 0: myjitdriver.jit_merge_point(n=n, d=d) - d = objectmodel.r_dict(eq_func, hash_func) + d = r_dict(eq_func, hash_func) y = Wrapper(str(n)) d[y] = n - 1 n = d[y] @@ -331,7 +331,7 @@ class DictTests: return (x % 2) == (y % 2) def f(n): - dct = objectmodel.r_dict(eq, key) + dct = r_dict(eq, key) total = n x = 44444 y = 55555 @@ -398,7 +398,7 @@ class TestLLOrderedDict(DictTests, LLJitMixin): d[2] = 6 d[1] = 4 lst = d.items() - assert len(lst) == 4 + assert_(len(lst) == 4) return ( lst[0][0] + 10*lst[0][1] + 100*lst[1][0] + 1000*lst[1][1] + 10000*lst[3][0] + 100000*lst[2][1] + diff --git a/rpython/jit/metainterp/test/test_exception.py b/rpython/jit/metainterp/test/test_exception.py index 30ad14d3fd40356d2210e6b716df0434d0b8f043..1ec53b251680b87ab0c8f15f9d5e1fd40e59d40c 100644 --- a/rpython/jit/metainterp/test/test_exception.py +++ b/rpython/jit/metainterp/test/test_exception.py @@ -2,7 +2,7 @@ import py, sys from rpython.jit.metainterp.test.support import LLJitMixin from rpython.rlib.jit import JitDriver, dont_look_inside from rpython.rlib.rarithmetic import ovfcheck, LONG_BIT, intmask -from rpython.rlib.objectmodel import keepalive_until_here +from rpython.rlib.objectmodel import keepalive_until_here, assert_ from rpython.jit.codewriter.policy import StopAtXPolicy from rpython.rtyper.lltypesystem import lltype, rffi @@ -633,11 +633,11 @@ class ExceptionTests: try: rescall(i) except KeyError: - assert i < 10 + assert_(i < 10) except ValueError: - assert i >= 20 + assert_(i >= 20) else: - assert 10 <= i < 20 + assert_(10 <= i < 20) i += 1 return i res = self.meta_interp(f, [0], inline=True) diff --git a/rpython/jit/metainterp/test/test_fficall.py b/rpython/jit/metainterp/test/test_fficall.py index 01c44df61676ed9997ba934d0b23d5435250a811..78a65e0386f99772ecb5c916ffe08ad8792e0019 100644 --- a/rpython/jit/metainterp/test/test_fficall.py +++ b/rpython/jit/metainterp/test/test_fficall.py @@ -6,6 +6,7 @@ from rpython.rtyper.lltypesystem import lltype, rffi from rpython.rtyper.annlowlevel import llhelper from rpython.jit.metainterp.test.support import LLJitMixin from rpython.jit.codewriter.longlong import is_longlong, is_64_bit +from rpython.rlib.objectmodel import assert_ from rpython.rlib import jit from rpython.rlib import jit_libffi from rpython.rlib.jit_libffi import (types, CIF_DESCRIPTION, FFI_TYPE_PP, @@ -31,11 +32,11 @@ class FakeFFI(object): Context manager to monkey patch jit_libffi with our custom "libffi-like" function """ - + def __init__(self, fake_call_impl_any): self.fake_call_impl_any = fake_call_impl_any self.monkey = monkeypatch() - + def __enter__(self, *args): self.monkey.setattr(jit_libffi, 'jit_ffi_call_impl_any', self.fake_call_impl_any) @@ -61,7 +62,7 @@ class FfiCallTests(object): if (lltype.typeOf(exp_a) == rffi.ULONG and lltype.typeOf(a) == lltype.Signed): a = rffi.cast(rffi.ULONG, a) - assert a == exp_a + assert_(a == exp_a) return rvalue FUNC = lltype.FuncType([lltype.typeOf(avalue) for avalue in avalues], lltype.typeOf(rvalue)) @@ -88,7 +89,7 @@ class FfiCallTests(object): lltype.typeOf(avalue) is rffi.UCHAR): got = intmask(got) avalue = intmask(avalue) - assert got == avalue + assert_(got == avalue) ofs += 16 write_to_ofs = 0 if rvalue is not None: @@ -312,7 +313,7 @@ class FfiCallTests(object): # call_release_gil was simply lost and when guard_not_forced # failed, and the value of "res" was unpredictable. # See commit b84ff38f34bd and subsequents. - assert res == n*2 + assert_(res == n*2) jit.virtual_ref_finish(vref, xy) exctx.topframeref = jit.vref_None n += 1 @@ -322,7 +323,7 @@ class FfiCallTests(object): assert f() == 100 res = self.meta_interp(f, []) assert res == 100 - + class TestFfiCall(FfiCallTests, LLJitMixin): def test_jit_ffi_vref(self): @@ -349,7 +350,7 @@ class TestFfiCall(FfiCallTests, LLJitMixin): # jit_ffi_prep_cif(cd) # - assert rffi.sizeof(rffi.DOUBLE) == 8 + assert_(rffi.sizeof(rffi.DOUBLE) == 8) exb = lltype.malloc(rffi.DOUBLEP.TO, 8, flavor='raw') exb[2] = 1.23 jit_ffi_call(cd, math_sin, rffi.cast(rffi.CCHARP, exb)) diff --git a/rpython/jit/metainterp/test/test_jitiface.py b/rpython/jit/metainterp/test/test_jitiface.py index 877ca6998c8bb4782c27e5c6130658177cc31d64..64124cefde3e8868c4e852080b57bc42fefdc852 100644 --- a/rpython/jit/metainterp/test/test_jitiface.py +++ b/rpython/jit/metainterp/test/test_jitiface.py @@ -1,19 +1,18 @@ -import py -from rpython.rlib.jit import JitDriver, JitHookInterface, Counters, dont_look_inside +from rpython.rlib.objectmodel import assert_ +from rpython.rlib.jit import ( + JitDriver, JitHookInterface, Counters, dont_look_inside) from rpython.rlib import jit_hooks from rpython.jit.metainterp.test.support import LLJitMixin from rpython.jit.codewriter.policy import JitPolicy -from rpython.jit.metainterp.resoperation import rop -from rpython.rtyper.annlowlevel import hlstr, cast_instance_to_gcref +from rpython.rtyper.annlowlevel import cast_instance_to_gcref from rpython.jit.metainterp.jitprof import Profiler, EmptyProfiler -from rpython.jit.codewriter.policy import JitPolicy class JitHookInterfaceTests(object): # !!!note!!! - don't subclass this from the backend. Subclass the LL # class later instead - + def test_abort_quasi_immut(self): reasons = [] @@ -71,7 +70,7 @@ class JitHookInterfaceTests(object): iface = MyJitIface() - driver = JitDriver(greens = ['n', 'm'], reds = ['i']) + driver = JitDriver(greens=['n', 'm'], reds=['i']) def loop(n, m): i = 0 @@ -94,7 +93,7 @@ class JitHookInterfaceTests(object): def test_on_compile_bridge(self): called = [] - + class MyJitIface(JitHookInterface): def after_compile(self, di): called.append("compile") @@ -104,8 +103,8 @@ class JitHookInterfaceTests(object): def before_compile_bridge(self, di): called.append("before_compile_bridge") - - driver = JitDriver(greens = ['n', 'm'], reds = ['i']) + + driver = JitDriver(greens=['n', 'm'], reds=['i']) def loop(n, m): i = 0 @@ -120,7 +119,7 @@ class JitHookInterfaceTests(object): assert called == ["compile", "before_compile_bridge", "compile_bridge"] def test_get_stats(self): - driver = JitDriver(greens = [], reds = ['i', 's']) + driver = JitDriver(greens=[], reds=['i', 's']) def loop(i): s = 0 @@ -134,31 +133,33 @@ class JitHookInterfaceTests(object): def main(): loop(30) - assert jit_hooks.stats_get_counter_value(None, - Counters.TOTAL_COMPILED_LOOPS) == 1 - assert jit_hooks.stats_get_counter_value(None, - Counters.TOTAL_COMPILED_BRIDGES) == 1 - assert jit_hooks.stats_get_counter_value(None, - Counters.TRACING) == 2 - assert jit_hooks.stats_get_times_value(None, Counters.TRACING) >= 0 + assert_(jit_hooks.stats_get_counter_value( + None, Counters.TOTAL_COMPILED_LOOPS) == 1) + assert_(jit_hooks.stats_get_counter_value( + None, Counters.TOTAL_COMPILED_BRIDGES) == 1) + assert_(jit_hooks.stats_get_counter_value( + None, Counters.TRACING) == 2) + assert_(jit_hooks.stats_get_times_value( + None, Counters.TRACING) >= 0) self.meta_interp(main, [], ProfilerClass=Profiler) def test_get_stats_empty(self): - driver = JitDriver(greens = [], reds = ['i']) + driver = JitDriver(greens=[], reds=['i']) def loop(i): while i > 0: driver.jit_merge_point(i=i) i -= 1 def main(): loop(30) - assert jit_hooks.stats_get_counter_value(None, - Counters.TOTAL_COMPILED_LOOPS) == 0 - assert jit_hooks.stats_get_times_value(None, Counters.TRACING) == 0 + assert_(jit_hooks.stats_get_counter_value( + None, Counters.TOTAL_COMPILED_LOOPS) == 0) + assert_(jit_hooks.stats_get_times_value( + None, Counters.TRACING) == 0) self.meta_interp(main, [], ProfilerClass=EmptyProfiler) def test_get_jitcell_at_key(self): - driver = JitDriver(greens = ['s'], reds = ['i'], name='jit') + driver = JitDriver(greens=['s'], reds=['i'], name='jit') def loop(i, s): while i > s: @@ -167,17 +168,17 @@ class JitHookInterfaceTests(object): def main(s): loop(30, s) - assert jit_hooks.get_jitcell_at_key("jit", s) - assert not jit_hooks.get_jitcell_at_key("jit", s + 1) + assert_(jit_hooks.get_jitcell_at_key("jit", s)) + assert_(not jit_hooks.get_jitcell_at_key("jit", s + 1)) jit_hooks.trace_next_iteration("jit", s + 1) loop(s + 3, s + 1) - assert jit_hooks.get_jitcell_at_key("jit", s + 1) + assert_(jit_hooks.get_jitcell_at_key("jit", s + 1)) self.meta_interp(main, [5]) self.check_jitcell_token_count(2) def test_get_jitcell_at_key_ptr(self): - driver = JitDriver(greens = ['s'], reds = ['i'], name='jit') + driver = JitDriver(greens=['s'], reds=['i'], name='jit') class Green(object): pass @@ -193,17 +194,17 @@ class JitHookInterfaceTests(object): g1_ptr = cast_instance_to_gcref(g1) g2_ptr = cast_instance_to_gcref(g2) loop(10, g1) - assert jit_hooks.get_jitcell_at_key("jit", g1_ptr) - assert not jit_hooks.get_jitcell_at_key("jit", g2_ptr) + assert_(jit_hooks.get_jitcell_at_key("jit", g1_ptr)) + assert_(not jit_hooks.get_jitcell_at_key("jit", g2_ptr)) jit_hooks.trace_next_iteration("jit", g2_ptr) loop(2, g2) - assert jit_hooks.get_jitcell_at_key("jit", g2_ptr) + assert_(jit_hooks.get_jitcell_at_key("jit", g2_ptr)) self.meta_interp(main, [5]) self.check_jitcell_token_count(2) def test_dont_trace_here(self): - driver = JitDriver(greens = ['s'], reds = ['i', 'k'], name='jit') + driver = JitDriver(greens=['s'], reds=['i', 'k'], name='jit') def loop(i, s): k = 4 @@ -228,10 +229,10 @@ class JitHookInterfaceTests(object): self.check_resops(call_assembler_n=8) def test_trace_next_iteration_hash(self): - driver = JitDriver(greens = ['s'], reds = ['i'], name="name") + driver = JitDriver(greens=['s'], reds=['i'], name="name") class Hashes(object): check = False - + def __init__(self): self.l = [] self.t = [] @@ -319,9 +320,9 @@ class JitHookInterfaceTests(object): class LLJitHookInterfaceTests(JitHookInterfaceTests): # use this for any backend, instead of the super class - + def test_ll_get_stats(self): - driver = JitDriver(greens = [], reds = ['i', 's']) + driver = JitDriver(greens=[], reds=['i', 's']) def loop(i): s = 0 @@ -330,7 +331,7 @@ class LLJitHookInterfaceTests(JitHookInterfaceTests): if i % 2: s += 1 i -= 1 - s+= 2 + s += 2 return s def main(b): @@ -338,26 +339,27 @@ class LLJitHookInterfaceTests(JitHookInterfaceTests): loop(30) l = jit_hooks.stats_get_loop_run_times(None) if b: - assert len(l) == 4 + assert_(len(l) == 4) # completely specific test that would fail each time # we change anything major. for now it's 4 # (loop, bridge, 2 entry points) - assert l[0].type == 'e' - assert l[0].number == 0 - assert l[0].counter == 4 - assert l[1].type == 'l' - assert l[1].counter == 4 - assert l[2].type == 'l' - assert l[2].counter == 23 - assert l[3].type == 'b' - assert l[3].number == 4 - assert l[3].counter == 11 + assert_(l[0].type == 'e') + assert_(l[0].number == 0) + assert_(l[0].counter == 4) + assert_(l[1].type == 'l') + assert_(l[1].counter == 4) + assert_(l[2].type == 'l') + assert_(l[2].counter == 23) + assert_(l[3].type == 'b') + assert_(l[3].number == 4) + assert_(l[3].counter == 11) else: - assert len(l) == 0 + assert_(len(l) == 0) self.meta_interp(main, [True], ProfilerClass=Profiler) # this so far does not work because of the way setup_once is done, # but fine, it's only about untranslated version anyway #self.meta_interp(main, [False], ProfilerClass=Profiler) + class TestJitHookInterface(JitHookInterfaceTests, LLJitMixin): pass diff --git a/rpython/jit/metainterp/test/test_loop.py b/rpython/jit/metainterp/test/test_loop.py index dca48361541d52569180feb86546c2da31d29d43..14aba8c4f73205a4a599a11fb533d194e326444a 100644 --- a/rpython/jit/metainterp/test/test_loop.py +++ b/rpython/jit/metainterp/test/test_loop.py @@ -1,19 +1,20 @@ import py -from rpython.rlib.jit import JitDriver, hint, set_param, dont_look_inside,\ - elidable -from rpython.rlib.objectmodel import compute_hash +from rpython.rlib.jit import ( + JitDriver, set_param, dont_look_inside, elidable) +from rpython.rlib.objectmodel import compute_hash, assert_ +from rpython.rlib.rerased import new_erasing_pair +from rpython.rtyper.lltypesystem import lltype + from rpython.jit.metainterp.warmspot import ll_meta_interp, get_stats from rpython.jit.metainterp.test.support import LLJitMixin from rpython.jit.codewriter.policy import StopAtXPolicy -from rpython.jit.metainterp.resoperation import rop -from rpython.jit.metainterp import history class LoopTest(object): enable_opts = '' automatic_promotion_result = { - 'int_add' : 6, 'int_gt' : 1, 'guard_false' : 1, 'jump' : 1, - 'guard_value' : 3 + 'int_add': 6, 'int_gt': 1, 'guard_false': 1, 'jump': 1, + 'guard_value': 3 } def meta_interp(self, f, args, policy=None, backendopt=False): @@ -26,7 +27,8 @@ class LoopTest(object): return f(*args) def test_simple_loop(self): - myjitdriver = JitDriver(greens = [], reds = ['x', 'y', 'res']) + myjitdriver = JitDriver(greens=[], reds=['x', 'y', 'res']) + def f(x, y): res = 0 while y > 0: @@ -40,7 +42,8 @@ class LoopTest(object): self.check_trace_count(1) def test_loop_with_delayed_setfield(self): - myjitdriver = JitDriver(greens = [], reds = ['x', 'y', 'res', 'a']) + myjitdriver = JitDriver(greens=[], reds=['x', 'y', 'res', 'a']) + class A(object): def __init__(self): self.x = 3 @@ -67,7 +70,7 @@ class LoopTest(object): def test_loop_with_two_paths(self): from rpython.rtyper.lltypesystem import lltype from rpython.rtyper.lltypesystem.lloperation import llop - myjitdriver = JitDriver(greens = [], reds = ['x', 'y', 'res']) + myjitdriver = JitDriver(greens=[], reds=['x', 'y', 'res']) def l(y, x, t): llop.debug_print(lltype.Void, y, x, t) @@ -96,7 +99,7 @@ class LoopTest(object): self.check_trace_count(2) def test_alternating_loops(self): - myjitdriver = JitDriver(greens = [], reds = ['pattern']) + myjitdriver = JitDriver(greens=[], reds=['pattern']) def f(pattern): while pattern > 0: myjitdriver.can_enter_jit(pattern=pattern) @@ -114,7 +117,7 @@ class LoopTest(object): self.check_trace_count(2) def test_interp_simple(self): - myjitdriver = JitDriver(greens = ['i'], reds = ['x', 'y']) + myjitdriver = JitDriver(greens=['i'], reds=['x', 'y']) bytecode = "bedca" def f(x, y): i = 0 @@ -139,7 +142,7 @@ class LoopTest(object): self.check_trace_count(0) def test_green_prevents_loop(self): - myjitdriver = JitDriver(greens = ['i'], reds = ['x', 'y']) + myjitdriver = JitDriver(greens=['i'], reds=['x', 'y']) bytecode = "+--+++++----" def f(x, y): i = 0 @@ -158,7 +161,7 @@ class LoopTest(object): self.check_trace_count(0) def test_interp_single_loop(self): - myjitdriver = JitDriver(greens = ['i'], reds = ['x', 'y']) + myjitdriver = JitDriver(greens=['i'], reds=['x', 'y']) bytecode = "abcd" def f(x, y): i = 0 @@ -201,7 +204,7 @@ class LoopTest(object): assert found == 1 def test_interp_many_paths(self): - myjitdriver = JitDriver(greens = ['i'], reds = ['x', 'node']) + myjitdriver = JitDriver(greens=['i'], reds=['x', 'node']) NODE = self._get_NODE() bytecode = "xxxxxxxb" def f(node): @@ -240,7 +243,7 @@ class LoopTest(object): oldlimit = sys.getrecursionlimit() try: sys.setrecursionlimit(10000) - myjitdriver = JitDriver(greens = ['i'], reds = ['x', 'node']) + myjitdriver = JitDriver(greens=['i'], reds=['x', 'node']) NODE = self._get_NODE() bytecode = "xxxxxxxb" @@ -281,7 +284,7 @@ class LoopTest(object): sys.setrecursionlimit(oldlimit) def test_nested_loops(self): - myjitdriver = JitDriver(greens = ['i'], reds = ['x', 'y']) + myjitdriver = JitDriver(greens=['i'], reds=['x', 'y']) bytecode = "abc= 0 + assert_(x >= 0) i = 0 while i < len(bytecode): myjitdriver.jit_merge_point(i=i, x=x) @@ -590,7 +593,7 @@ class LoopTest(object): assert res == expected def test_unused_loop_constant(self): - myjitdriver = JitDriver(greens = [], reds = ['x', 'y', 'z']) + myjitdriver = JitDriver(greens=[], reds=['x', 'y', 'z']) def f(x, y, z): while z > 0: myjitdriver.can_enter_jit(x=x, y=y, z=z) @@ -603,7 +606,7 @@ class LoopTest(object): assert res == expected def test_loop_unicode(self): - myjitdriver = JitDriver(greens = [], reds = ['n', 'x']) + myjitdriver = JitDriver(greens=[], reds=['n', 'x']) def f(n): x = u'' while n > 13: @@ -617,7 +620,7 @@ class LoopTest(object): assert res == expected def test_loop_string(self): - myjitdriver = JitDriver(greens = [], reds = ['n', 'x']) + myjitdriver = JitDriver(greens=[], reds=['n', 'x']) def f(n): x = '' while n > 13: @@ -632,7 +635,7 @@ class LoopTest(object): assert res == expected def test_adapt_bridge_to_merge_point(self): - myjitdriver = JitDriver(greens = [], reds = ['x', 'z']) + myjitdriver = JitDriver(greens=[], reds=['x', 'z']) class Z(object): def __init__(self, elem): @@ -812,7 +815,7 @@ class LoopTest(object): self.check_trace_count(2) def test_path_with_operations_not_from_start(self): - jitdriver = JitDriver(greens = ['k'], reds = ['n', 'z']) + jitdriver = JitDriver(greens=['k'], reds=['n', 'z']) def f(n): k = 0 @@ -831,11 +834,11 @@ class LoopTest(object): n -= 1 return 42 - res = self.meta_interp(f, [200]) + self.meta_interp(f, [200]) def test_path_with_operations_not_from_start_2(self): - jitdriver = JitDriver(greens = ['k'], reds = ['n', 'z', 'stuff']) + jitdriver = JitDriver(greens=['k'], reds=['n', 'z', 'stuff']) class Stuff(object): def __init__(self, n): @@ -869,7 +872,8 @@ class LoopTest(object): BASE = lltype.GcStruct('BASE') A = lltype.GcStruct('A', ('parent', BASE), ('val', lltype.Signed)) B = lltype.GcStruct('B', ('parent', BASE), ('charval', lltype.Char)) - myjitdriver = JitDriver(greens = [], reds = ['n', 'm', 'i', 'j', 'sa', 'p']) + myjitdriver = JitDriver(greens=[], reds=['n', 'm', 'i', 'j', 'sa', 'p']) + def f(n, m, j): i = sa = 0 pa = lltype.malloc(A) @@ -888,22 +892,22 @@ class LoopTest(object): pb = lltype.cast_pointer(lltype.Ptr(B), p) sa += ord(pb.charval) sa += 100 - assert n>0 and m>0 + assert_(n > 0 and m > 0) i += j return sa # This is detected as invalid by the codewriter, for now py.test.raises(NotImplementedError, self.meta_interp, f, [20, 10, 1]) def test_unerased_pointers_in_short_preamble(self): - from rpython.rlib.rerased import new_erasing_pair - from rpython.rtyper.lltypesystem import lltype class A(object): def __init__(self, val): self.val = val erase_A, unerase_A = new_erasing_pair('A') erase_TP, unerase_TP = new_erasing_pair('TP') TP = lltype.GcArray(lltype.Signed) - myjitdriver = JitDriver(greens = [], reds = ['n', 'm', 'i', 'j', 'sa', 'p']) + myjitdriver = JitDriver( + greens=[], reds=['n', 'm', 'i', 'j', 'sa', 'p']) + def f(n, m, j): i = sa = 0 p = erase_A(A(7)) @@ -918,14 +922,13 @@ class LoopTest(object): else: sa += unerase_TP(p)[0] sa += A(i).val - assert n>0 and m>0 + assert_(n > 0 and m > 0) i += j return sa res = self.meta_interp(f, [20, 10, 1]) assert res == f(20, 10, 1) def test_boxed_unerased_pointers_in_short_preamble(self): - from rpython.rlib.rerased import new_erasing_pair from rpython.rtyper.lltypesystem import lltype class A(object): def __init__(self, val): @@ -940,7 +943,7 @@ class LoopTest(object): erase_A, unerase_A = new_erasing_pair('A') erase_TP, unerase_TP = new_erasing_pair('TP') TP = lltype.GcArray(lltype.Signed) - myjitdriver = JitDriver(greens = [], reds = ['n', 'm', 'i', 'sa', 'p']) + myjitdriver = JitDriver(greens=[], reds=['n', 'm', 'i', 'sa', 'p']) def f(n, m): i = sa = 0 p = Box(erase_A(A(7))) @@ -1011,7 +1014,6 @@ class LoopTest(object): class C(object): pass - from rpython.rlib.rerased import new_erasing_pair b_erase, b_unerase = new_erasing_pair("B") c_erase, c_unerase = new_erasing_pair("C") @@ -1044,7 +1046,6 @@ class LoopTest(object): def test_unroll_issue_3(self): py.test.skip("decide") - from rpython.rlib.rerased import new_erasing_pair b_erase, b_unerase = new_erasing_pair("B") # list of ints c_erase, c_unerase = new_erasing_pair("C") # list of Nones @@ -1075,7 +1076,7 @@ class LoopTest(object): assert res == 420 def test_not_too_many_bridges(self): - jitdriver = JitDriver(greens = [], reds = 'auto') + jitdriver = JitDriver(greens=[], reds='auto') def f(i): s = 0 @@ -1097,7 +1098,7 @@ class LoopTest(object): def test_sharing_guards(self): py.test.skip("unimplemented") - driver = JitDriver(greens = [], reds = 'auto') + driver = JitDriver(greens=[], reds='auto') def f(i): s = 0 @@ -1145,7 +1146,7 @@ class LoopTest(object): v = reverse(W_Cons(pc + 1, W_Cons(pc + 2, W_Cons(pc + 3, W_Cons(pc + 4, W_Nil()))))) pc = pc + 1 repetitions += 1 - + self.meta_interp(entry_point, []) diff --git a/rpython/memory/test/test_hybrid_gc.py b/rpython/memory/test/test_hybrid_gc.py index 9318fac2ebedb9d2be63f89a49dd4177b3adf5b1..b1e4b677ab4ae71ee3d4040c4e0cd0392b80bfbf 100644 --- a/rpython/memory/test/test_hybrid_gc.py +++ b/rpython/memory/test/test_hybrid_gc.py @@ -2,6 +2,7 @@ import py from rpython.rtyper.lltypesystem import lltype from rpython.rtyper.lltypesystem.lloperation import llop +from rpython.rlib.objectmodel import assert_ from rpython.memory.test import test_generational_gc @@ -35,12 +36,12 @@ class TestHybridGC(test_generational_gc.TestGenerationalGC): while i < x: gc.collect() i += 1 - assert ref() is a - assert ref().x == 42 + assert_(ref() is a) + assert_(ref().x == 42) return ref def step2(ref): gc.collect() # 'a' is freed here - assert ref() is None + assert_(ref() is None) def f(x): ref = step1(x) step2(ref) diff --git a/rpython/memory/test/test_incminimark_gc.py b/rpython/memory/test/test_incminimark_gc.py index 4b49316bcfc24cdb93cf8673da735339cdf50c39..4831107c796da056c7959fc00a9251711292668b 100644 --- a/rpython/memory/test/test_incminimark_gc.py +++ b/rpython/memory/test/test_incminimark_gc.py @@ -2,6 +2,7 @@ import py from rpython.rtyper.lltypesystem import lltype from rpython.rtyper.lltypesystem.lloperation import llop from rpython.rlib import rgc +from rpython.rlib.objectmodel import assert_ from rpython.memory.test import test_minimark_gc @@ -21,8 +22,8 @@ class TestIncrementalMiniMarkGC(test_minimark_gc.TestMiniMarkGC): a.x = 5 wr = weakref.ref(a) llop.gc__collect(lltype.Void) # make everything old - assert wr() is not None - assert a.x == 5 + assert_(wr() is not None) + assert_(a.x == 5) return wr def f(): ref = g() @@ -31,7 +32,7 @@ class TestIncrementalMiniMarkGC(test_minimark_gc.TestMiniMarkGC): # to an object not found, but still reachable: b = ref() llop.debug_print(lltype.Void, b) - assert b is not None + assert_(b is not None) llop.gc__collect(lltype.Void) # finish the major cycle # assert does not crash, because 'b' is still kept alive b.x = 42 @@ -46,7 +47,7 @@ class TestIncrementalMiniMarkGC(test_minimark_gc.TestMiniMarkGC): def f(): a = A() ref = weakref.ref(a) - assert not rgc.pin(ref) + assert_(not rgc.pin(ref)) self.interpret(f, []) def test_pin_finalizer_not_implemented(self): @@ -63,8 +64,8 @@ class TestIncrementalMiniMarkGC(test_minimark_gc.TestMiniMarkGC): def f(): a = A() b = B() - assert not rgc.pin(a) - assert not rgc.pin(b) + assert_(not rgc.pin(a)) + assert_(not rgc.pin(b)) self.interpret(f, []) def test_weakref_to_pinned(self): @@ -75,18 +76,18 @@ class TestIncrementalMiniMarkGC(test_minimark_gc.TestMiniMarkGC): pass def g(): a = A() - assert rgc.pin(a) + assert_(rgc.pin(a)) a.x = 100 wr = weakref.ref(a) llop.gc__collect(lltype.Void) - assert wr() is not None - assert a.x == 100 + assert_(wr() is not None) + assert_(a.x == 100) return wr def f(): ref = g() llop.gc__collect(lltype.Void, 1) b = ref() - assert b is not None + assert_(b is not None) b.x = 101 return ref() is b res = self.interpret(f, []) diff --git a/rpython/memory/test/test_transformed_gc.py b/rpython/memory/test/test_transformed_gc.py index 083c8cdf60fb48831e13e624a2defab7a62f3396..3c653e5b56763981f2fc01e5c1c293b3732e98e7 100644 --- a/rpython/memory/test/test_transformed_gc.py +++ b/rpython/memory/test/test_transformed_gc.py @@ -17,6 +17,7 @@ from rpython.rlib.rarithmetic import LONG_BIT from rpython.rlib.nonconst import NonConstant from rpython.rtyper.rtyper import llinterp_backend from rpython.memory.gc.hook import GcHooks +from rpython.rlib.objectmodel import assert_ WORD = LONG_BIT // 8 @@ -808,7 +809,7 @@ class GenericMovingGCTests(GenericGCTests): [A() for i in range(20)] i = 0 while i < len(alist): - assert idarray[i] == compute_unique_id(alist[i]) + assert_(idarray[i] == compute_unique_id(alist[i])) i += 1 j += 1 lltype.free(idarray, flavor='raw') @@ -859,7 +860,7 @@ class GenericMovingGCTests(GenericGCTests): if cls.gcname == 'incminimark': marker = cls.marker def cleanup(): - assert marker[0] > 0 + assert_(marker[0] > 0) marker[0] = 0 else: cleanup = None @@ -991,7 +992,7 @@ class GenericMovingGCTests(GenericGCTests): for i in range(20): x.append((1, lltype.malloc(S))) for i in range(50): - assert l2[i] == l[50 + i] + assert_(l2[i] == l[50 + i]) return 0 return fn @@ -1040,9 +1041,9 @@ class TestGenerationGC(GenericMovingGCTests): while i < x: all[i] = [i] * i i += 1 - assert ref() is a + assert_(ref() is a) llop.gc__collect(lltype.Void) - assert ref() is a + assert_(ref() is a) return a.foo + len(all) return f @@ -1119,7 +1120,7 @@ class TestGenerationGC(GenericMovingGCTests): i = 0 while i < 17: ref = weakref.ref(a) - assert ref() is a + assert_(ref() is a) i += 1 return 0 @@ -1186,9 +1187,9 @@ class TestGenerationGC(GenericMovingGCTests): a1 = A() nf1 = nf_a.address[0] nt1 = nt_a.address[0] - assert nf1 > nf0 - assert nt1 > nf1 - assert nt1 == nt0 + assert_(nf1 > nf0) + assert_(nt1 > nf1) + assert_(nt1 == nt0) return 0 return f @@ -1363,7 +1364,7 @@ class TestMiniMarkGC(TestHybridGC): hashes.append(compute_identity_hash(obj)) unique = {} for i in range(len(objects)): - assert compute_identity_hash(objects[i]) == hashes[i] + assert_(compute_identity_hash(objects[i]) == hashes[i]) unique[hashes[i]] = None return len(unique) return fn diff --git a/rpython/pytest.ini b/rpython/pytest.ini deleted file mode 100644 index 6879c8b3e6b60dcff17ffc7b6eb3c7887332058f..0000000000000000000000000000000000000000 --- a/rpython/pytest.ini +++ /dev/null @@ -1,2 +0,0 @@ -[pytest] -addopts = --assert=reinterp -rf diff --git a/rpython/rlib/objectmodel.py b/rpython/rlib/objectmodel.py index 8e59b387ece182307429db105a0cbff7cfe8917d..7273aae9c5e64ebcdb2a5dd48c61dd97d0d6e9f4 100644 --- a/rpython/rlib/objectmodel.py +++ b/rpython/rlib/objectmodel.py @@ -14,7 +14,7 @@ from collections import OrderedDict from rpython.tool.sourcetools import rpython_wrapper, func_with_new_name from rpython.rtyper.extregistry import ExtRegistryEntry from rpython.flowspace.specialcase import register_flow_sc -from rpython.flowspace.model import Constant +from rpython.flowspace.model import Constant, const # specialize is a decorator factory for attaching _annspecialcase_ # attributes to functions: for example @@ -226,6 +226,34 @@ def not_rpython(func): func._not_rpython_ = True return func +def assert_(condition, msg=None): + """ + A function version of the assert statement. + + The RPython toolchain interprets it in exactly the same way as the + statement version. This is useful in tests to prevent py.test assertion + rewriting from modifying the bytecode of RPython functions. + """ + if msg is None: + assert condition + else: + assert condition, msg + +@register_flow_sc(assert_) +def sc_assert(ctx, *args_w): + from rpython.flowspace.operation import op + from rpython.flowspace.flowcontext import Raise, FlowingError + if len(args_w) == 2: + w_condition, w_msg = args_w + elif len(args_w) == 1: + w_condition, = args_w + w_msg = const(None) + else: + raise FlowingError( + "assert_() requires 1 or 2 arguments, %s given" % len(args_w)) + if not ctx.guessbool(op.bool(w_condition).eval(ctx)): + raise Raise(ctx.exc_from_raise(const(AssertionError), w_msg)) + def llhelper_can_raise(func): """ Instruct ll2ctypes that this llhelper can raise RPython exceptions, which diff --git a/rpython/rlib/parsing/test/test_translate.py b/rpython/rlib/parsing/test/test_translate.py index 834183458b4b249b6a2e540b56db5e0470b5611c..7ffdcb87fe0b34b172fa38342b7e59a6a739e66b 100644 --- a/rpython/rlib/parsing/test/test_translate.py +++ b/rpython/rlib/parsing/test/test_translate.py @@ -4,6 +4,7 @@ from rpython.rlib.parsing.makepackrat import BacktrackException, Status from rpython.rlib.parsing.regex import * from rpython.rlib.parsing.parsing import * from rpython.translator.c.test.test_genc import compile +from rpython.rlib.objectmodel import assert_ class TestTranslateLexer(object): @@ -100,7 +101,7 @@ primary: "(" ")" | ; def f(): tree = parse("(0 +! 10) *! (999 +! 10) +! 1") tree = ToAST().visit_additive(tree) - assert len(tree) == 1 + assert_(len(tree) == 1) tree = tree[0] return tree.symbol + " " + "-&-".join([c.symbol for c in tree.children]) res1 = f() diff --git a/rpython/rlib/rsre/test/test_zinterp.py b/rpython/rlib/rsre/test/test_zinterp.py index 46113df2b9dc6ed1ce480a2eb96f4973c89001b1..06818b69043823e6675d732a80e79e6fa5357a6f 100644 --- a/rpython/rlib/rsre/test/test_zinterp.py +++ b/rpython/rlib/rsre/test/test_zinterp.py @@ -3,9 +3,10 @@ from rpython.rtyper.test.test_llinterp import gengraph, interpret from rpython.rlib.rsre import rsre_core from rpython.rlib.rsre.rsre_re import compile +from rpython.rlib.objectmodel import assert_ def main(n): - assert n >= 0 + assert_(n >= 0) pattern = [n] * n string = chr(n) * n rsre_core.search(pattern, string) diff --git a/rpython/rlib/rvmprof/test/test_rvmprof.py b/rpython/rlib/rvmprof/test/test_rvmprof.py index bbacd8d3291428cf2021ac2fc64b3406ea92001b..12fc8122a4597f48625a1ba879c80332c90a5a48 100644 --- a/rpython/rlib/rvmprof/test/test_rvmprof.py +++ b/rpython/rlib/rvmprof/test/test_rvmprof.py @@ -6,6 +6,7 @@ from rpython.rlib import rvmprof from rpython.translator.c.test.test_genc import compile from rpython.translator.tool.cbuild import ExternalCompilationInfo from rpython.rtyper.lltypesystem import rffi, lltype +from rpython.rlib.objectmodel import assert_ @pytest.mark.usefixtures('init') class RVMProfTest(object): @@ -33,7 +34,7 @@ class TestExecuteCode(RVMProfTest): def entry_point(self): res = self.main(self.MyCode(), 5) - assert res == 42 + assert_(res == 42) return 0 @rvmprof.vmprof_execute_code("xcode1", lambda self, code, num: code) @@ -58,7 +59,7 @@ class TestResultClass(RVMProfTest): def entry_point(self): a = self.main(7, self.MyCode()) - assert isinstance(a, self.A) + assert_(isinstance(a, self.A)) return 0 def test(self): @@ -67,7 +68,7 @@ class TestResultClass(RVMProfTest): class TestRegisterCode(RVMProfTest): - + @rvmprof.vmprof_execute_code("xcode1", lambda self, code, num: code) def main(self, code, num): print num @@ -77,7 +78,7 @@ class TestRegisterCode(RVMProfTest): code = self.MyCode() rvmprof.register_code(code, lambda code: 'some code') res = self.main(code, 5) - assert res == 42 + assert_(res == 42) return 0 def test(self): diff --git a/rpython/rlib/test/test_debug.py b/rpython/rlib/test/test_debug.py index 0830511405e049da31b4d6fba42498215a8ca4d1..4e16db6618092e9a65d72d25417ca04972c904db 100644 --- a/rpython/rlib/test/test_debug.py +++ b/rpython/rlib/test/test_debug.py @@ -9,6 +9,7 @@ from rpython.rlib.debug import (check_annotation, make_sure_not_resized, NotAListOfChars) from rpython.rlib import debug from rpython.rtyper.test.test_llinterp import interpret, gengraph +from rpython.rlib.objectmodel import assert_ @pytest.fixture def debuglog(monkeypatch): @@ -42,7 +43,7 @@ def test_check_annotation(): def test_check_nonneg(): def f(x): - assert x >= 5 + assert_(x >= 5) check_nonneg(x) interpret(f, [9]) diff --git a/rpython/rlib/test/test_jit.py b/rpython/rlib/test/test_jit.py index d73001a7cef0c78d947ed51b775a6d686f505f28..49fadd4fe439d582c76cc869917ed9479059d4ad 100644 --- a/rpython/rlib/test/test_jit.py +++ b/rpython/rlib/test/test_jit.py @@ -2,6 +2,7 @@ import py, pytest from rpython.conftest import option from rpython.annotator.model import UnionError +from rpython.rlib.objectmodel import assert_ from rpython.rlib.jit import (hint, we_are_jitted, JitDriver, elidable_promote, JitHintError, oopspec, isconstant, conditional_call, elidable, unroll_safe, dont_look_inside, conditional_call_elidable, @@ -246,7 +247,7 @@ class TestJIT(BaseRtypingTest): def test_isconstant(self): def f(n): - assert isconstant(n) is False + assert_(isconstant(n) is False) l = [] l.append(n) return len(l) diff --git a/rpython/rlib/test/test_longlong2float.py b/rpython/rlib/test/test_longlong2float.py index c44ec0076d3b9d022c6177ce5dfb6cf2cf7c35ab..6435a696d535162cc3aa10b8334b110ac1486e9e 100644 --- a/rpython/rlib/test/test_longlong2float.py +++ b/rpython/rlib/test/test_longlong2float.py @@ -4,6 +4,7 @@ from rpython.rlib.longlong2float import longlong2float, float2longlong from rpython.rlib.longlong2float import uint2singlefloat, singlefloat2uint from rpython.rlib.rarithmetic import r_singlefloat, r_longlong from rpython.rtyper.test.test_llinterp import interpret +from rpython.rlib.objectmodel import assert_ def fn(f1): @@ -75,15 +76,15 @@ def fn_encode_nan(f1, i2): from rpython.rlib.longlong2float import encode_int32_into_longlong_nan from rpython.rlib.longlong2float import decode_int32_from_longlong_nan from rpython.rlib.longlong2float import is_int32_from_longlong_nan - assert can_encode_float(f1) - assert can_encode_int32(i2) + assert_(can_encode_float(f1)) + assert_(can_encode_int32(i2)) l1 = float2longlong(f1) l2 = encode_int32_into_longlong_nan(i2) - assert not is_int32_from_longlong_nan(l1) - assert is_int32_from_longlong_nan(l2) + assert_(not is_int32_from_longlong_nan(l1)) + assert_(is_int32_from_longlong_nan(l2)) f1b = longlong2float(l1) - assert f1b == f1 or (math.isnan(f1b) and math.isnan(f1)) - assert decode_int32_from_longlong_nan(l2) == i2 + assert_(f1b == f1 or (math.isnan(f1b) and math.isnan(f1))) + assert_(decode_int32_from_longlong_nan(l2) == i2) return 42 def test_compiled_encode_nan(): diff --git a/rpython/rlib/test/test_objectmodel.py b/rpython/rlib/test/test_objectmodel.py index 6bcb9d60c6dcdfb303bac1623984d61ce4e7bef6..fc026f29db8a62e869a52192f02f188b2ded9471 100644 --- a/rpython/rlib/test/test_objectmodel.py +++ b/rpython/rlib/test/test_objectmodel.py @@ -7,7 +7,8 @@ from rpython.rlib.objectmodel import ( resizelist_hint, is_annotation_constant, always_inline, NOT_CONSTANT, iterkeys_with_hash, iteritems_with_hash, contains_with_hash, setitem_with_hash, getitem_with_hash, delitem_with_hash, import_from_mixin, - fetch_translated_config, try_inline, delitem_if_value_is, move_to_end) + fetch_translated_config, try_inline, delitem_if_value_is, move_to_end, + assert_) from rpython.translator.translator import TranslationContext, graphof from rpython.rtyper.test.tool import BaseRtypingTest from rpython.rtyper.test.test_llinterp import interpret @@ -21,54 +22,54 @@ def strange_key_hash(key): def play_with_r_dict(d): d['hello'] = 41 d['hello'] = 42 - assert d['hi there'] == 42 + assert_(d['hi there'] == 42) try: unexpected = d["dumb"] except KeyError: pass else: - assert False, "should have raised, got %s" % unexpected - assert len(d) == 1 - assert 'oops' not in d + assert_(False, "should have raised, got %s" % unexpected) + assert_(len(d) == 1) + assert_('oops' not in d) count = 0 for x in d: - assert x == 'hello' + assert_(x == 'hello') count += 1 - assert count == 1 + assert_(count == 1) - assert d.get('hola', -1) == 42 - assert d.get('salut', -1) == -1 + assert_(d.get('hola', -1) == 42) + assert_(d.get('salut', -1) == -1) d1 = d.copy() del d['hu!'] - assert len(d) == 0 - assert d1.keys() == ['hello'] + assert_(len(d) == 0) + assert_(d1.keys() == ['hello']) d.update(d1) - assert d.values() == [42] + assert_(d.values() == [42]) lst = d.items() - assert len(lst) == 1 and len(lst[0]) == 2 - assert lst[0][0] == 'hello' and lst[0][1] == 42 + assert_(len(lst) == 1 and len(lst[0]) == 2) + assert_(lst[0][0] == 'hello' and lst[0][1] == 42) count = 0 for x in d.iterkeys(): - assert x == 'hello' + assert_(x == 'hello') count += 1 - assert count == 1 + assert_(count == 1) count = 0 for x in d.itervalues(): - assert x == 42 + assert_(x == 42) count += 1 - assert count == 1 + assert_(count == 1) count = 0 for x in d.iteritems(): - assert len(x) == 2 and x[0] == 'hello' and x[1] == 42 + assert_(len(x) == 2 and x[0] == 'hello' and x[1] == 42) count += 1 - assert count == 1 + assert_(count == 1) d.clear() - assert d.keys() == [] + assert_(d.keys() == []) return True # for the tests below @@ -372,22 +373,22 @@ class TestObjectModel(BaseRtypingTest): class Foo(object): pass def f(i): - assert compute_hash(i) == compute_hash(42) - assert compute_hash(i + 1.0) == compute_hash(43.0) - assert compute_hash("Hello" + str(i)) == compute_hash("Hello42") + assert_(compute_hash(i) == compute_hash(42)) + assert_(compute_hash(i + 1.0) == compute_hash(43.0)) + assert_(compute_hash("Hello" + str(i)) == compute_hash("Hello42")) if i == 42: p = None else: p = Foo() - assert compute_hash(p) == compute_hash(None) - assert (compute_hash(("world", None, i, 7.5)) == - compute_hash(("world", None, 42, 7.5))) + assert_(compute_hash(p) == compute_hash(None)) + assert_(compute_hash(("world", None, i, 7.5)) == + compute_hash(("world", None, 42, 7.5))) q = Foo() - assert compute_hash(q) == compute_identity_hash(q) + assert_(compute_hash(q) == compute_identity_hash(q)) from rpython.rlib.rfloat import INFINITY, NAN - assert compute_hash(INFINITY) == 314159 - assert compute_hash(-INFINITY) == -271828 - assert compute_hash(NAN) == 0 + assert_(compute_hash(INFINITY) == 314159) + assert_(compute_hash(-INFINITY) == -271828) + assert_(compute_hash(NAN) == 0) return i * 2 res = self.interpret(f, [42]) assert res == 84 @@ -620,8 +621,8 @@ def test_iteritems_with_hash(): def test_contains_with_hash(): def f(i): d = {i + .5: 5} - assert contains_with_hash(d, i + .5, compute_hash(i + .5)) - assert not contains_with_hash(d, i + .3, compute_hash(i + .3)) + assert_(contains_with_hash(d, i + .5, compute_hash(i + .5))) + assert_(not contains_with_hash(d, i + .3, compute_hash(i + .3))) return 0 f(29) @@ -670,11 +671,11 @@ def test_delitem_if_value_is(): x612 = X() d = {i + .5: x42, i + .6: x612} delitem_if_value_is(d, i + .5, x612) - assert (i + .5) in d + assert_((i + .5) in d) delitem_if_value_is(d, i + .5, x42) - assert (i + .5) not in d + assert_((i + .5) not in d) delitem_if_value_is(d, i + .5, x612) - assert (i + .5) not in d + assert_((i + .5) not in d) return 0 f(29) @@ -684,9 +685,9 @@ def test_rdict_with_hash(): def f(i): d = r_dict(strange_key_eq, strange_key_hash) h = strange_key_hash("abc") - assert h == strange_key_hash("aXX") and strange_key_eq("abc", "aXX") + assert_(h == strange_key_hash("aXX") and strange_key_eq("abc", "aXX")) setitem_with_hash(d, "abc", h, i) - assert getitem_with_hash(d, "aXX", h) == i + assert_(getitem_with_hash(d, "aXX", h) == i) try: getitem_with_hash(d, "bYY", strange_key_hash("bYY")) except KeyError: diff --git a/rpython/rlib/test/test_rawrefcount.py b/rpython/rlib/test/test_rawrefcount.py index 0e1f9261aaadb9dc6271e35a936c8c5401d94e77..9fc2a2312412a7234ee0d51adc079d65e1c3433c 100644 --- a/rpython/rlib/test/test_rawrefcount.py +++ b/rpython/rlib/test/test_rawrefcount.py @@ -5,6 +5,7 @@ from rpython.rtyper.lltypesystem import lltype from rpython.rtyper.annlowlevel import llhelper from rpython.translator.c.test.test_standalone import StandaloneTests from rpython.config.translationoption import get_combined_translation_config +from rpython.rlib.objectmodel import assert_ class W_Root(object): @@ -238,8 +239,8 @@ class TestTranslated(StandaloneTests): ob = lltype.malloc(PyObjectS, flavor='raw', zero=True) rawrefcount.create_link_pypy(p, ob) ob.c_ob_refcnt += REFCNT_FROM_PYPY - assert rawrefcount.from_obj(PyObject, p) == ob - assert rawrefcount.to_obj(W_Root, ob) == p + assert_(rawrefcount.from_obj(PyObject, p) == ob) + assert_(rawrefcount.to_obj(W_Root, ob) == p) return ob, p FTYPE = rawrefcount.RAWREFCOUNT_DEALLOC_TRIGGER diff --git a/rpython/rlib/test/test_rerased.py b/rpython/rlib/test/test_rerased.py index 989a62bede8fe0e39382bcb14cafafedc0cf31a4..3b249afd794d5394239ea7665a0add1a443ebeab 100644 --- a/rpython/rlib/test/test_rerased.py +++ b/rpython/rlib/test/test_rerased.py @@ -8,6 +8,7 @@ from rpython.annotator import model as annmodel from rpython.annotator.annrpython import RPythonAnnotator from rpython.rtyper.rclass import OBJECTPTR from rpython.rtyper.lltypesystem import lltype, llmemory +from rpython.rlib.objectmodel import assert_ from rpython.rtyper.test.tool import BaseRtypingTest @@ -295,7 +296,7 @@ class TestRErased(BaseRtypingTest): l = prebuilt_l e = prebuilt_e #assert is_integer(e) is False - assert unerase_list_X(e) is l + assert_(unerase_list_X(e) is l) self.interpret(l, [0]) self.interpret(l, [1]) self.interpret(l, [2]) @@ -314,7 +315,7 @@ class TestRErased(BaseRtypingTest): p = s.gcref else: p = erase(l) - assert unerase(p) is l + assert_(unerase(p) is l) self.interpret(l, [3]) self.interpret(l, [8]) diff --git a/rpython/rlib/test/test_rfile.py b/rpython/rlib/test/test_rfile.py index edadfe11102daf16102dae70e68e801b55b5f916..bceb2e26f1d975ac2044138df9ac0b6528beb5b1 100644 --- a/rpython/rlib/test/test_rfile.py +++ b/rpython/rlib/test/test_rfile.py @@ -2,6 +2,7 @@ import os, sys, py, errno, gc from rpython.rtyper.test.tool import BaseRtypingTest from rpython.tool.udir import udir from rpython.rlib import rfile +from rpython.rlib.objectmodel import assert_ class TestFile(BaseRtypingTest): @@ -21,7 +22,7 @@ class TestFile(BaseRtypingTest): except ValueError: pass else: - assert False + assert_(False) f.close() f() @@ -37,53 +38,53 @@ class TestFile(BaseRtypingTest): except ValueError: pass else: - assert False + assert_(False) try: open('zzz') except IOError as e: - assert e.errno == errno.ENOENT + assert_(e.errno == errno.ENOENT) else: - assert False + assert_(False) try: open('.') except IOError as e: if os.name == 'posix': - assert e.errno == errno.EISDIR + assert_(e.errno == errno.EISDIR) else: - assert e.errno == errno.EACCES + assert_(e.errno == errno.EACCES) else: - assert False + assert_(False) try: os.fdopen(42, "badmode") except ValueError: pass else: - assert False + assert_(False) try: fd = os.open('.', os.O_RDONLY, 0777) except OSError as e: - assert os.name == 'nt' and e.errno == errno.EACCES + assert_(os.name == 'nt' and e.errno == errno.EACCES) else: - assert os.name != 'nt' + assert_(os.name != 'nt') if run: try: os.fdopen(fd) except IOError as e: - assert e.errno == errno.EISDIR + assert_(e.errno == errno.EISDIR) else: - assert False + assert_(False) os.close(fd) try: os.fdopen(12345) except OSError as e: - assert e.errno == errno.EBADF + assert_(e.errno == errno.EBADF) else: - assert False + assert_(False) f(sys.version_info >= (2, 7, 9)) self.interpret(f, [True]) @@ -97,9 +98,9 @@ class TestFile(BaseRtypingTest): f = open(fname, 'w', 1) f.write('dupa\ndupb') f2 = open(fname, 'r') - assert f2.read() == 'dupa\n' + assert_(f2.read() == 'dupa\n') f.close() - assert f2.read() == 'dupb' + assert_(f2.read() == 'dupb') f2.close() f() @@ -117,9 +118,9 @@ class TestFile(BaseRtypingTest): g.close() f.write('dupa\ndupb') f2 = open(fname, 'r') - assert f2.read() == 'dupa\n' + assert_(f2.read() == 'dupa\n') f.close() - assert f2.read() == 'dupb' + assert_(f2.read() == 'dupb') f2.close() f() @@ -133,11 +134,11 @@ class TestFile(BaseRtypingTest): f = open(fname, 'w', 128) f.write('dupa\ndupb') f2 = open(fname, 'r') - assert f2.read() == '' + assert_(f2.read() == '') f.write('z' * 120) - assert f2.read() != '' + assert_(f2.read() != '') f.close() - assert f2.read() != '' + assert_(f2.read() != '') f2.close() f() @@ -153,11 +154,11 @@ class TestFile(BaseRtypingTest): g.close() f.write('dupa\ndupb') f2 = open(fname, 'r') - assert f2.read() == '' + assert_(f2.read() == '') f.write('z' * 120) - assert f2.read() != '' + assert_(f2.read() != '') f.close() - assert f2.read() != '' + assert_(f2.read() != '') f2.close() f() @@ -174,13 +175,13 @@ class TestFile(BaseRtypingTest): except IOError as e: pass else: - assert False + assert_(False) try: f.readline() except IOError as e: pass else: - assert False + assert_(False) f.write("dupa\x00dupb") f.close() for mode in ['r', 'U']: @@ -190,21 +191,21 @@ class TestFile(BaseRtypingTest): except IOError as e: pass else: - assert False + assert_(False) dupa = f2.read(0) - assert dupa == "" + assert_(dupa == "") dupa = f2.read() - assert dupa == "dupa\x00dupb" + assert_(dupa == "dupa\x00dupb") f2.seek(0) dupa = f2.readline(0) - assert dupa == "" + assert_(dupa == "") dupa = f2.readline(2) - assert dupa == "du" + assert_(dupa == "du") dupa = f2.readline(100) - assert dupa == "pa\x00dupb" + assert_(dupa == "pa\x00dupb") f2.seek(0) dupa = f2.readline() - assert dupa == "dupa\x00dupb" + assert_(dupa == "dupa\x00dupb") f2.close() f() @@ -224,11 +225,11 @@ class TestFile(BaseRtypingTest): d = f.read(1) e = f.read() f.close() - assert a == "d" - assert b == "u" - assert c == "p" - assert d == "a" - assert e == "" + assert_(a == "d") + assert_(b == "u") + assert_(c == "p") + assert_(d == "a") + assert_(e == "") f() self.interpret(f, []) @@ -240,27 +241,27 @@ class TestFile(BaseRtypingTest): def f(): f = open(fname, 'U') - assert f.read() == "dupa\ndupb\ndupc\ndupd" - assert f.read() == "" + assert_(f.read() == "dupa\ndupb\ndupc\ndupd") + assert_(f.read() == "") f.seek(0) - assert f.read(10) == "dupa\ndupb\n" - assert f.read(42) == "dupc\ndupd" - assert f.read(1) == "" + assert_(f.read(10) == "dupa\ndupb\n") + assert_(f.read(42) == "dupc\ndupd") + assert_(f.read(1) == "") f.seek(0) - assert f.readline() == "dupa\n" - assert f.tell() == 5 - assert f.readline() == "dupb\n" - assert f.tell() == 11 - assert f.readline() == "dupc\n" - assert f.tell() == 16 - assert f.readline() == "dupd" - assert f.tell() == 20 - assert f.readline() == "" + assert_(f.readline() == "dupa\n") + assert_(f.tell() == 5) + assert_(f.readline() == "dupb\n") + assert_(f.tell() == 11) + assert_(f.readline() == "dupc\n") + assert_(f.tell() == 16) + assert_(f.readline() == "dupd") + assert_(f.tell() == 20) + assert_(f.readline() == "") f.seek(0) - assert f.readline() == "dupa\n" - assert f.readline() == "dupb\n" + assert_(f.readline() == "dupa\n") + assert_(f.readline() == "dupb\n") f.seek(4) - assert f.read(1) == "\n" + assert_(f.read(1) == "\n") f.close() f() @@ -273,23 +274,23 @@ class TestFile(BaseRtypingTest): f = open(fname, "w+") f.write("abcdef") f.seek(0) - assert f.read() == "abcdef" + assert_(f.read() == "abcdef") f.seek(1) - assert f.read() == "bcdef" + assert_(f.read() == "bcdef") f.seek(2) f.seek(-2, 2) - assert f.read() == "ef" + assert_(f.read() == "ef") f.seek(2) f.seek(-1, 1) - assert f.read() == "bcdef" + assert_(f.read() == "bcdef") #---is the following behavior interesting in RPython? #---I claim not, and it doesn't work on Windows #try: # f.seek(0, 42) #except IOError as e: - # assert e.errno == errno.EINVAL + # assert_(e.errno == errno.EINVAL) #else: - # assert False + # assert_(False) f.close() f() @@ -301,7 +302,7 @@ class TestFile(BaseRtypingTest): f = os.tmpfile() f.write("xxx") f.seek(0) - assert f.read() == "xxx" + assert_(f.read() == "xxx") f.close() f() @@ -320,7 +321,7 @@ class TestFile(BaseRtypingTest): except IOError as e: pass else: - assert False + assert_(False) f2.write("xxx") f2.close() @@ -335,7 +336,7 @@ class TestFile(BaseRtypingTest): def f(): f = open(fname, "w") - assert not f.isatty() + assert_(not f.isatty()) try: return f.fileno() finally: @@ -372,7 +373,7 @@ class TestFile(BaseRtypingTest): f.write("xyz") f.flush() f2 = open(fname) - assert f2.read() == "xyz" + assert_(f2.read() == "xyz") f2.close() f.close() @@ -390,7 +391,7 @@ class TestFile(BaseRtypingTest): f.truncate() f.seek(0) data = f.read() - assert data == "hello w" + assert_(data == "hello w") f.close() f = open(fname) try: @@ -398,7 +399,7 @@ class TestFile(BaseRtypingTest): except IOError as e: pass else: - assert False + assert_(False) f.close() f() @@ -411,15 +412,15 @@ class TestFile(BaseRtypingTest): def f(): with open(fname, "w") as f: f.write("dupa") - assert not f.closed + assert_(not f.closed) try: - assert f.closed + assert_(f.closed) f.write("dupb") except ValueError: pass else: - assert False + assert_(False) f() assert open(fname, "r").read() == "dupa" @@ -531,7 +532,7 @@ class TestPopenR(BaseRtypingTest): f = rfile.create_popen_file(cmd, "r") s = f.read() f.close() - assert s == "%s\n" % printval + assert_(s == "%s\n" % printval) self.interpret(f, []) def test_pclose(self): @@ -542,7 +543,7 @@ class TestPopenR(BaseRtypingTest): def f(): f = rfile.create_popen_file(cmd, "r") s = f.read() - assert s == "%s\n" % printval + assert_(s == "%s\n" % printval) return f.close() r = self.interpret(f, []) assert os.WEXITSTATUS(r) == retval diff --git a/rpython/rtyper/lltypesystem/test/test_llarena.py b/rpython/rtyper/lltypesystem/test/test_llarena.py index 874461db15209b65e1f3b95799b166e7d44ebec6..fc42d9058894eab8e1bda8920228248301b17393 100644 --- 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 @@ def test_look_inside_object(): 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 @@ class TestStandalone(test_standalone.StandaloneTests): 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 index cec56d09c2938c1c463e4317527620285aebf9b6..e1c311e99da92e160c2d5c03a102c4547b9429f0 100644 --- 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 build_test(): # 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 index 7766ffa6852bf6c96d4c2f986caa8fdecab48b9e..c6507310ebab3c3d3874c25d32dbbd13d6d6490a 100644 --- 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 @@ def test_composite(): 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 @@ def test_dont_mix_offsets_and_ints(): 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 @@ def test_raw_free(): 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 @@ def test_raw_free(): 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(): 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 @@ def test_raw_free_with_hdr(): 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 @@ def test_raw_free_with_hdr(): 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 @@ def test_cast_gcref_to_int(): 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 index cd073f14b33027d0d228ad46794c0c2e04458e13..b06342db29d4ebf2030bacb1f903225f06709384 100644 --- 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 @@ -646,9 +647,9 @@ class TestRffiInternals: 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') @@ -732,11 +733,11 @@ class TestRffiInternals: 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 @@ -831,9 +832,9 @@ def test_ptradd(): 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(): @@ -858,7 +859,7 @@ class TestCRffi(BaseTestRffi): p = rawptrs[i] expected = strings[i] + '\x00' for j in range(len(expected)): - assert p[j] == expected[j] + assert_(p[j] == expected[j]) def f(n): strings = ["foo%d" % i for i in range(n)] @@ -870,7 +871,7 @@ class TestCRffi(BaseTestRffi): for i in range(len(strings)): # check that it still returns the # same raw ptrs p1 = rffi._get_raw_address_buf_from_string(strings[i]) - assert rawptrs[i] == p1 + assert_(rawptrs[i] == p1) del strings rgc.collect(); rgc.collect(); rgc.collect() return 42 diff --git a/rpython/rtyper/lltypesystem/test/test_ztranslated.py b/rpython/rtyper/lltypesystem/test/test_ztranslated.py index c2e0848933798ff74b31eaa59b115b30969f2f87..00dccd200fa2cb9cffcc81503cc6cf72c0968b5b 100644 --- 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 @@ from rpython.rlib import rgc 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 index 12fd8aca5ffe55edd9a5a5586758b9b19b2ad8a6..800aec7dabb52688a0332d0e696fe2f8a869cf12 100644 --- 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 @@ -49,39 +50,39 @@ class TestException(BaseRtypingTest): try: g(n) except IOError as e: - assert e.errno == 0 - assert e.strerror == "test" - assert e.filename is None + assert_(e.errno == 0) + assert_(e.strerror == "test") + assert_(e.filename is None) else: - assert False + assert_(False) try: h(n) except OSError as e: - assert e.errno == 42 - assert e.strerror == "?" - assert e.filename is None + assert_(e.errno == 42) + assert_(e.strerror == "?") + assert_(e.filename is None) else: - assert False + assert_(False) try: i(n) except EnvironmentError as e: - assert e.errno == 42 - assert e.strerror == "?" - assert e.filename == "test" + assert_(e.errno == 42) + assert_(e.strerror == "?") + assert_(e.filename == "test") else: - assert False + assert_(False) try: j(n) except (IOError, OSError) as e: - assert e.errno == 0 - assert e.strerror == "test" - assert e.filename is None + assert_(e.errno == 0) + assert_(e.strerror == "test") + assert_(e.filename is None) try: k(n) except EnvironmentError as e: - assert e.errno == 0 - assert e.strerror is None - assert e.filename is None + assert_(e.errno == 0) + assert_(e.strerror is None) + assert_(e.filename is None) self.interpret(f, [42]) def test_catch_incompatible_class(self): @@ -91,7 +92,7 @@ class TestException(BaseRtypingTest): pass def f(n): try: - assert n < 10 + assert_(n < 10) except MyError as operr: h(operr) res = self.interpret(f, [7]) diff --git a/rpython/rtyper/test/test_llann.py b/rpython/rtyper/test/test_llann.py index d6e4cdcf39c02b7826715835e838fc3477e4090f..847d51d002c2f0b964a5a2c6f0598ebf77af898d 100644 --- 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 @@ def test_llhelper(): 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 @@ def test_llhelper_multiple_functions(): 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 index d42086a02d9f09df9c6d26a095ceee5618f540e8..d327ee2fe123bf8464850d95b22dbc028fc03572 100644 --- 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 @@ def test_scoped_allocator(): 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 index 8b3e1228272444eea81ab3300aebddd3ff63488c..4456e3b36843d1fbbff50ae8023742bd0c1f1f90 100644 --- 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.rtyper.llannotation import SomeAddress from rpython.annotator.annrpython import RPythonAnnotator +from rpython.rtyper.llannotation import SomeAddress 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 @@ def test_isinstance(): 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 index cb97129392547269cc6bbaa7b8e94b204a9d2942..972c4ce2c9e2e76e336dfb21fc349967a4114f2b 100644 --- a/rpython/rtyper/test/test_rclass.py +++ b/rpython/rtyper/test/test_rclass.py @@ -5,6 +5,7 @@ import pytest 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 @@ -1262,13 +1263,13 @@ class TestRclass(BaseRtypingTest): 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 index 81d3a6f67fd1cc92710df7023048dbff8d0fb8ac..6e0130244c71bb3c76c0cb90fe6e2b437d92ea61 100644 --- a/rpython/rtyper/test/test_rdict.py +++ b/rpython/rtyper/test/test_rdict.py @@ -3,21 +3,23 @@ from contextlib import contextmanager import signal from collections import OrderedDict +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 -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 def ann2strategy(s_value): if isinstance(s_value, SomeChar): @@ -193,7 +195,7 @@ class BaseTestRDict(BaseRtypingTest): 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, []) @@ -732,15 +734,15 @@ class BaseTestRDict(BaseRtypingTest): 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, []) @@ -990,15 +992,15 @@ class BaseTestRDict(BaseRtypingTest): 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 index e0cfa4296a919511cc10f5d3ca977ee1836ab4f4..db6c07f7293d453dc5fa7d12c60f185d9acb8407 100644 --- 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 @@ class TestRint(BaseRtypingTest): 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 @@ class TestRint(BaseRtypingTest): 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 index 3dbe6c9f8747675037fcb5f3a80d8d42500cd3ce..1d3534855d401ee37cb059a8dfc6e269abb71b4b 100644 --- a/rpython/rtyper/test/test_rlist.py +++ b/rpython/rtyper/test/test_rlist.py @@ -3,11 +3,13 @@ import re 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 @@ class TestRlist(BaseRtypingTest): 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 @@ class TestRlist(BaseRtypingTest): 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 @@ class TestRlist(BaseRtypingTest): 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 @@ class TestRlist(BaseRtypingTest): res = self.interpret(dummyfn, [1, 0]) assert res == 0 - def test_getitem_exc_1(self): def f(x): l = [1] @@ -1339,7 +1340,7 @@ class TestRlist(BaseRtypingTest): 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 @@ class TestRlist(BaseRtypingTest): def test_unicharlist_extension_2(self): def f(n, i): s = u'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 @@ class TestRlist(BaseRtypingTest): 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 @@ class TestRlist(BaseRtypingTest): 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 @@ class TestRlist(BaseRtypingTest): def test_unicharlist_extension_3(self): def f(n, i, j): s = u'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 @@ class TestRlist(BaseRtypingTest): ("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 @@ class TestRlist(BaseRtypingTest): 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 @@ class TestRlist(BaseRtypingTest): 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 index ee25fedff50bdca2680d79bcbe7973e205cb7583..9c5364132dbb3d9be0022f4079551dee5ef5f792 100644 --- 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 @@ class TestOrderedRDict(BaseTestRDict): @staticmethod def new_r_dict(myeq, myhash, force_non_null=False, simple_hash_eq=False): - return objectmodel.r_ordereddict( + return r_ordereddict( myeq, myhash, force_non_null=force_non_null, simple_hash_eq=simple_hash_eq) @@ -408,14 +408,14 @@ class TestOrderedRDict(BaseTestRDict): 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 index cf1ce408870e691a7ae621c99c0a53ca4af14f57..4b64b820617632130cb8847451781fd2ada9ee1c 100644 --- a/rpython/rtyper/test/test_rpbc.py +++ b/rpython/rtyper/test/test_rpbc.py @@ -2,6 +2,7 @@ import py 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 @@ class TestRPBC(BaseRtypingTest): try: o.m() except KeyError: - assert 0 + raise ValueError return B().m() self.interpret_raises(KeyError, f, [7]) @@ -1717,7 +1718,7 @@ class TestRPBC(BaseRtypingTest): 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 index 20b4b3d48482ad7987f16c11ff50a570b5adb12a..3db9fbf4d16f5c2ef2c68ac0eda252712062cdef 100644 --- a/rpython/rtyper/test/test_rptr.py +++ b/rpython/rtyper/test/test_rptr.py @@ -6,9 +6,11 @@ from rpython.annotator import model as annmodel 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 @@ def test_runtime_type_info(): 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 @@ def test_adtmeths(): 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 @@ def test_odd_ints(): 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 @@ def test_odd_ints_opaque(): 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_len(): 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_interior_ptr_with_setitem(): 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 index 49939e8deaa46b274a4833eee3f3410d451de353..860eaee0dfcc314aee7cbe9c70da9a2b869c5abc 100644 --- a/rpython/rtyper/test/test_rstr.py +++ b/rpython/rtyper/test/test_rstr.py @@ -4,6 +4,7 @@ import py 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 @@ class AbstractTestRstr(BaseRtypingTest): 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 @@ class AbstractTestRstr(BaseRtypingTest): 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 @@ class AbstractTestRstr(BaseRtypingTest): 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 @@ class AbstractTestRstr(BaseRtypingTest): 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 index 8bb465015931758f867f7f1acf4ee628629519d2..ec27b296c7af7c7c6b5a1b9842c0fc9b7f986b8c 100644 --- 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 @@ class TestRtuple(BaseRtypingTest): 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 @@ class TestRtuple(BaseRtypingTest): 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 @@ class TestRtuple(BaseRtypingTest): 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 index 82fa43aec17dff3416d863024fa783cab107be40..48031a491bf5583c6b0b31a497b2eba2e60f8961 100644 --- 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 @@ class TestRweakref(BaseRtypingTest): 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 @@ class TestRweakref(BaseRtypingTest): 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 @@ class TestRweakref(BaseRtypingTest): 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 @@ class TestRWeakrefDisabled(BaseRtypingTest): 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 diff --git a/rpython/translator/backendopt/test/test_all.py b/rpython/translator/backendopt/test/test_all.py index 0081fce2235889ed1f411cc8fcedfb9bffc658c4..e6916045a315aa07a91c7efd28b030744321ee39 100644 --- a/rpython/translator/backendopt/test/test_all.py +++ b/rpython/translator/backendopt/test/test_all.py @@ -7,6 +7,7 @@ from rpython.translator.translator import TranslationContext, graphof from rpython.flowspace.model import Constant, summary from rpython.rtyper.llinterp import LLInterpreter from rpython.rlib.rarithmetic import intmask +from rpython.rlib.objectmodel import assert_ from rpython.conftest import option class A: @@ -222,7 +223,7 @@ class TestLLType(object): return b def fn(n): x = g(n) - assert isinstance(x, B) + assert_(isinstance(x, B)) return x.value t = self.translateopt(fn, [int], really_remove_asserts=True, remove_asserts=True) diff --git a/rpython/translator/backendopt/test/test_removeassert.py b/rpython/translator/backendopt/test/test_removeassert.py index bd9612c5e5e5240f0c5ca5bbfb4e3d2c51a9690f..29a5fb965c97ff30e3fbdd6305c0ed7c4616a917 100644 --- a/rpython/translator/backendopt/test/test_removeassert.py +++ b/rpython/translator/backendopt/test/test_removeassert.py @@ -1,4 +1,5 @@ from rpython.flowspace.model import summary +from rpython.rlib.objectmodel import assert_ from rpython.translator.backendopt.removeassert import remove_asserts from rpython.translator.backendopt.constfold import constant_fold_graph from rpython.translator.backendopt.test import test_constfold @@ -28,13 +29,13 @@ def check(fn, args, expected_result, remaining_raise=False): def test_simple(): def fn(n): - assert n >= 1 + assert_(n >= 1) return n-1 check(fn, [125], 124) def test_simple_melting_away(): def fn(n): - assert n >= 1 + assert_(n >= 1) return n-1 graph, t = get_graph(fn, [int]) assert summary(graph) == {'int_ge': 1, 'int_sub': 1} @@ -50,13 +51,13 @@ def test_simple_melting_away(): def test_and(): def fn(n): - assert n >= 1 and n < 10 + assert_(n >= 1 and n < 10) return n-1 check(fn, [1], 0) def test_or(): def fn(n): - assert n >= 1 or n % 2 == 0 + assert_(n >= 1 or n % 2 == 0) return n-1 check(fn, [-120], -121) @@ -74,7 +75,7 @@ def test_isinstance(): return b def fn(n): x = g(n) - assert isinstance(x, B) + assert_(isinstance(x, B)) return x.value t, graph = check(fn, [5], 321) assert summary(graph)['debug_assert'] == 1 @@ -92,7 +93,7 @@ def test_with_exception(): def fn(n): try: g(n) - assert False + assert_(False) except ValueError: return 42 check(fn, [-8], 42, remaining_raise=True) diff --git a/rpython/translator/c/test/test_boehm.py b/rpython/translator/c/test/test_boehm.py index 80356e56186794397a5f63f3ab13311451e37300..14a34c6461180abbcb25ba73719160204fc1c20d 100644 --- a/rpython/translator/c/test/test_boehm.py +++ b/rpython/translator/c/test/test_boehm.py @@ -3,8 +3,9 @@ import weakref import py from rpython.rlib import rgc, debug -from rpython.rlib.objectmodel import (keepalive_until_here, compute_unique_id, - compute_hash, current_object_addr_as_int) +from rpython.rlib.objectmodel import ( + keepalive_until_here, compute_unique_id, compute_hash, + current_object_addr_as_int, assert_) from rpython.rtyper.lltypesystem import lltype, llmemory from rpython.rtyper.lltypesystem.lloperation import llop from rpython.rtyper.lltypesystem.rstr import STR @@ -230,7 +231,7 @@ class TestUsingBoehm(AbstractGCTestClass): if i & 1 == 0: a = A() a.index = i - assert a is not None + assert_(a is not None) weakrefs.append(weakref.ref(a)) if i % 7 == 6: keepalive.append(a) @@ -239,9 +240,9 @@ class TestUsingBoehm(AbstractGCTestClass): for i in range(n): a = weakrefs[i]() if i % 7 == 6: - assert a is not None + assert_(a is not None) if a is not None: - assert a.index == i & ~1 + assert_(a.index == i & ~1) else: count_free += 1 keepalive_until_here(keepalive) @@ -286,7 +287,7 @@ class TestUsingBoehm(AbstractGCTestClass): lst = [weakref.ref(a) for i in range(n)] rgc.collect() for r in lst: - assert r() is a + assert_(r() is a) c_fn = self.getcompiled(fn, [int]) c_fn(100) @@ -424,7 +425,7 @@ class TestUsingBoehm(AbstractGCTestClass): a = fq.next_dead() if a is None: break - assert a.i not in seen + assert_(a.i not in seen) seen[a.i] = True if len(seen) < 500: print "seen only %d!" % len(seen) diff --git a/rpython/translator/c/test/test_exception.py b/rpython/translator/c/test/test_exception.py index 719d8741ff0125bf58708e02846a007a8c6c6692..c63bad05d98219c53f8101d7efba00b57788e3b4 100644 --- a/rpython/translator/c/test/test_exception.py +++ b/rpython/translator/c/test/test_exception.py @@ -4,6 +4,7 @@ from rpython.translator.c.test import test_typed from rpython.translator.c.test import test_backendoptimized from rpython.rtyper.lltypesystem import lltype from rpython.rlib.rarithmetic import ovfcheck +from rpython.rlib.objectmodel import assert_ getcompiled = test_typed.TestTypedTestCase().getcompiled getcompiledopt = test_backendoptimized.TestTypedOptimizedTestCase().getcompiled @@ -117,7 +118,7 @@ def test_memoryerror(): def test_assert(): def testfn(n): - assert n >= 0 + assert_(n >= 0) f1 = getcompiled(testfn, [int]) res = f1(0) diff --git a/rpython/translator/c/test/test_extfunc.py b/rpython/translator/c/test/test_extfunc.py index ca3d4740223af3f70fc0771214805e793d241ba4..dcaf46aae417f8462922394154b200a322aa5db7 100644 --- a/rpython/translator/c/test/test_extfunc.py +++ b/rpython/translator/c/test/test_extfunc.py @@ -2,6 +2,7 @@ import py import os, time, sys from rpython.tool.udir import udir from rpython.rlib.rarithmetic import r_longlong +from rpython.rlib.objectmodel import assert_ from rpython.annotator import model as annmodel from rpython.translator.c.test.test_genc import compile from rpython.translator.c.test.test_standalone import StandaloneTests @@ -54,13 +55,13 @@ def test_open_read_write_seek_close(): def does_stuff(): fd = os.open(filename, os.O_WRONLY | os.O_CREAT, 0777) count = os.write(fd, "hello world\n") - assert count == len("hello world\n") + assert_(count == len("hello world\n")) os.close(fd) fd = os.open(filename, os.O_RDONLY, 0777) result = os.lseek(fd, 1, 0) - assert result == 1 + assert_(result == 1) data = os.read(fd, 500) - assert data == "ello world\n" + assert_(data == "ello world\n") os.close(fd) f1 = compile(does_stuff, []) @@ -95,7 +96,7 @@ def test_ftruncate(): fd = os.open(filename, os.O_RDWR, 0777) os.ftruncate(fd, 5) data = os.read(fd, 500) - assert data == "hello" + assert_(data == "hello") os.close(fd) does_stuff() f1 = compile(does_stuff, []) @@ -123,11 +124,11 @@ def test_largefile(): fd = os.open(filename, os.O_RDWR | os.O_CREAT, 0666) os.ftruncate(fd, r10000000000) res = os.lseek(fd, r9900000000, 0) - assert res == r9900000000 + assert_(res == r9900000000) res = os.lseek(fd, -r5000000000, 1) - assert res == r4900000000 + assert_(res == r4900000000) res = os.lseek(fd, -r5200000000, 2) - assert res == r4800000000 + assert_(res == r4800000000) os.close(fd) try: os.lseek(fd, 0, 0) @@ -137,7 +138,7 @@ def test_largefile(): print "DID NOT RAISE" raise AssertionError st = os.stat(filename) - assert st.st_size == r10000000000 + assert_(st.st_size == r10000000000) does_stuff() os.unlink(filename) f1 = compile(does_stuff, []) @@ -185,7 +186,7 @@ def test_os_stat_raises_winerror(): os.stat("nonexistentdir/nonexistentfile") except WindowsError as e: return e.winerror - return 0 + return 0 f = compile(call_stat, []) res = f() expected = call_stat() @@ -329,24 +330,24 @@ def test_pipe_dup_dup2(): a, b = os.pipe() c = os.dup(a) d = os.dup(b) - assert a != b - assert a != c - assert a != d - assert b != c - assert b != d - assert c != d + assert_(a != b) + assert_(a != c) + assert_(a != d) + assert_(b != c) + assert_(b != d) + assert_(c != d) os.close(c) os.dup2(d, c) e, f = os.pipe() - assert e != a - assert e != b - assert e != c - assert e != d - assert f != a - assert f != b - assert f != c - assert f != d - assert f != e + assert_(e != a) + assert_(e != b) + assert_(e != c) + assert_(e != d) + assert_(f != a) + assert_(f != b) + assert_(f != c) + assert_(f != d) + assert_(f != e) os.close(a) os.close(b) os.close(c) @@ -466,7 +467,7 @@ if hasattr(os, 'link'): def does_stuff(): os.symlink(tmpfile1, tmpfile2) os.link(tmpfile1, tmpfile3) - assert os.readlink(tmpfile2) == tmpfile1 + assert_(os.readlink(tmpfile2) == tmpfile1) flag= 0 st = os.lstat(tmpfile1) flag = flag*10 + stat.S_ISREG(st[0]) @@ -491,7 +492,7 @@ if hasattr(os, 'fork'): if pid == 0: # child os._exit(4) pid1, status1 = os.waitpid(pid, 0) - assert pid1 == pid + assert_(pid1 == pid) return status1 f1 = compile(does_stuff, []) status1 = f1() @@ -507,7 +508,7 @@ if hasattr(os, 'fork'): os._exit(4) os.kill(pid, signal.SIGTERM) # in the parent pid1, status1 = os.waitpid(pid, 0) - assert pid1 == pid + assert_(pid1 == pid) return status1 f1 = compile(does_stuff, []) status1 = f1() @@ -527,7 +528,7 @@ elif hasattr(os, 'waitpid'): #if pid == 0: # child # os._exit(4) pid1, status1 = os.waitpid(pid, 0) - assert pid1 == pid + assert_(pid1 == pid) return status1 f1 = compile(does_stuff, []) status1 = f1() diff --git a/rpython/translator/c/test/test_genc.py b/rpython/translator/c/test/test_genc.py index a82aba8d20b7dc582f2c65817f0098c9e1429b05..04bcacb4ed703bb38039e7c7b0e7a08f1cc4224f 100644 --- a/rpython/translator/c/test/test_genc.py +++ b/rpython/translator/c/test/test_genc.py @@ -9,7 +9,7 @@ from rpython.rlib.rfloat import NAN, INFINITY from rpython.rlib.entrypoint import entrypoint_highlevel from rpython.rlib.unroll import unrolling_iterable from rpython.rlib.rarithmetic import r_longlong, r_ulonglong, r_uint, intmask -from rpython.rlib.objectmodel import specialize +from rpython.rlib.objectmodel import specialize, assert_ from rpython.rtyper.lltypesystem import lltype from rpython.rtyper.lltypesystem.lltype import * from rpython.rtyper.lltypesystem.rstr import STR @@ -79,7 +79,7 @@ def compile(fn, argtypes, view=False, gcpolicy="none", backendopt=True, if a == 'True': args += (True,) else: - assert a == 'False' + assert_(a == 'False') args += (False,) elif argtype is float: if a == 'inf': @@ -589,7 +589,7 @@ def test_ordered_dict(): d = OrderedDict(expected) def f(): - assert d.items() == expected + assert_(d.items() == expected) fn = compile(f, []) fn() diff --git a/rpython/translator/c/test/test_lladdresses.py b/rpython/translator/c/test/test_lladdresses.py index f3982fb9daba7029e04f4c795e3f1ba54d53ec50..dde5b69188c07b263c52c31c6b3b7b23a5017dd7 100644 --- a/rpython/translator/c/test/test_lladdresses.py +++ b/rpython/translator/c/test/test_lladdresses.py @@ -1,7 +1,7 @@ import py, sys from rpython.rtyper.lltypesystem.llmemory import * from rpython.translator.c.test.test_genc import compile -from rpython.rlib.objectmodel import free_non_gc_object +from rpython.rlib.objectmodel import free_non_gc_object, assert_ def test_null(): def f(): @@ -64,10 +64,10 @@ def test_memory_float(): s.x = 123.2 a = cast_ptr_to_adr(s) b = a + offset - assert b.float[0] == 123.2 + assert_(b.float[0] == 123.2) b.float[0] = 234.1 (a + offsety).float[0] = value - assert s.x == 234.1 + assert_(s.x == 234.1) return s.x + value fc = compile(f, [float]) res = fc(42.42) @@ -90,7 +90,7 @@ def test_pointer_arithmetic(): def f(offset, char): char = chr(char) addr = raw_malloc(10000) - same_offset = (addr + 2 * offset - offset) - addr + same_offset = (addr + 2 * offset - offset) - addr addr.char[offset] = char result = (addr + same_offset).char[0] raw_free(addr) diff --git a/rpython/translator/c/test/test_lltyped.py b/rpython/translator/c/test/test_lltyped.py index 528d1e16b39dd2aaa20aa962e81f6569aef32c81..39ab6f12745d050a8c680c5d742cf6f24b64aba2 100644 --- a/rpython/translator/c/test/test_lltyped.py +++ b/rpython/translator/c/test/test_lltyped.py @@ -3,6 +3,7 @@ from rpython.rtyper.lltypesystem.lltype import * from rpython.rtyper.lltypesystem import rffi from rpython.translator.c.test.test_genc import compile from rpython.tool.sourcetools import func_with_new_name +from rpython.rlib.objectmodel import assert_ class TestLowLevelType(object): @@ -45,12 +46,12 @@ class TestLowLevelType(object): a3[2].v = -4 a42[0][0] = -5 a42[5][6] = -6 - assert a7[0] == -1 - assert a7[6] == -2 - assert a3[0].v == -3 - assert a3.item2.v == -4 - assert a42[0][0] == -5 - assert a42[5][6] == -6 + assert_(a7[0] == -1) + assert_(a7[6] == -2) + assert_(a3[0].v == -3) + assert_(a3.item2.v == -4) + assert_(a42[0][0] == -5) + assert_(a42[5][6] == -6) return len(a42)*100 + len(a42[4]) fn = self.getcompiled(llf, []) res = fn() @@ -64,7 +65,7 @@ class TestLowLevelType(object): def llf(): tree.root[0].a = tree.root tree.root[1].a = tree.other - assert tree.root[0].a[0].a[0].a[0].a[0].a[1].a == tree.other + assert_(tree.root[0].a[0].a[0].a[0].a[0].a[1].a == tree.other) fn = self.getcompiled(llf, []) fn() @@ -80,7 +81,7 @@ class TestLowLevelType(object): s = '' for i in range(5): s += chr(64+a[i]) - assert s == "HELLO" + assert_(s == "HELLO") fn = self.getcompiled(llf, []) fn() @@ -555,9 +556,9 @@ class TestLowLevelType(object): for i in xrange(len(data)): a[i] = data[i] a2 = rffi.ptradd(a, 2) - assert typeOf(a2) == typeOf(a) == Ptr(ARRAY_OF_CHAR) + assert_(typeOf(a2) == typeOf(a) == Ptr(ARRAY_OF_CHAR)) for i in xrange(len(data) - 2): - assert a2[i] == a[i + 2] + assert_(a2[i] == a[i + 2]) free(a, flavor='raw') fn = self.getcompiled(llf, []) @@ -610,7 +611,7 @@ class TestLowLevelType(object): s = '' for i in range(5): s += chr(64+a[i]) - assert s == "HELLO" + assert_(s == "HELLO") fn = self.getcompiled(llf, []) fn() @@ -628,7 +629,7 @@ class TestLowLevelType(object): s = '' for i in range(5): s += a[i] - assert s == "85?!" + lastchar + assert_(s == "85?!" + lastchar) fn = self.getcompiled(llf, []) fn() @@ -793,12 +794,12 @@ class TestLowLevelType(object): # ARM has stronger rules about aligned memory access # so according to the rules for round_up_for_allocation # we get two words here - assert ssize == llmemory.sizeof(Signed) * 2 + assert_(ssize == llmemory.sizeof(Signed) * 2) else: - assert ssize == llmemory.sizeof(Signed) - assert msize == llmemory.sizeof(Signed) * 2 - assert smsize == msize - assert mssize == msize + assert_(ssize == llmemory.sizeof(Signed)) + assert_(msize == llmemory.sizeof(Signed) * 2) + assert_(smsize == msize) + assert_(mssize == msize) # def f(): check(glob_sizes) @@ -1029,10 +1030,10 @@ class TestLowLevelType(object): def check(lst): hashes = [] for i, (s, a) in enumerate(lst): - assert a.x == i + assert_(a.x == i) rgc.ll_write_final_null_char(s) for i, (s, a) in enumerate(lst): - assert a.x == i # check it was not overwritten + assert_(a.x == i) # check it was not overwritten def f(): check(prebuilt) lst1 = [] diff --git a/rpython/translator/c/test/test_newgc.py b/rpython/translator/c/test/test_newgc.py index 6b4f62fc147ef731cba7d09a14ba741dac6f681d..444c5a365f0edbd1ac6346250b7a202edaccc563 100644 --- a/rpython/translator/c/test/test_newgc.py +++ b/rpython/translator/c/test/test_newgc.py @@ -9,7 +9,8 @@ import py from rpython.conftest import option from rpython.rlib import rgc -from rpython.rlib.objectmodel import keepalive_until_here, compute_hash, compute_identity_hash, r_dict +from rpython.rlib.objectmodel import ( + assert_, keepalive_until_here, compute_hash, compute_identity_hash, r_dict) from rpython.rlib.rstring import StringBuilder from rpython.rtyper.lltypesystem import lltype, llmemory, rffi from rpython.rtyper.lltypesystem.lloperation import llop @@ -107,7 +108,7 @@ class UsingFrameworkTest(object): funcstr = funcsstr[num] if funcstr: return funcstr(arg) - assert 0, 'unreachable' + assert_(0, 'unreachable') cls.funcsstr = funcsstr cls.c_allfuncs = staticmethod(cls._makefunc_str_int(allfuncs)) cls.allfuncs = staticmethod(allfuncs) @@ -516,7 +517,7 @@ class UsingFrameworkTest(object): if i & 1 == 0: a = A() a.index = i - assert a is not None + assert_(a is not None) weakrefs.append(weakref.ref(a)) if i % 7 == 6: keepalive.append(a) @@ -525,9 +526,9 @@ class UsingFrameworkTest(object): for i in range(n): a = weakrefs[i]() if i % 7 == 6: - assert a is not None + assert_(a is not None) if a is not None: - assert a.index == i & ~1 + assert_(a.index == i & ~1) else: count_free += 1 return count_free @@ -585,10 +586,10 @@ class UsingFrameworkTest(object): for n in range(len(dlist)): d = dlist[n] keys = keyslist[n] - assert len(d) == len(keys) + assert_(len(d) == len(keys)) i = 0 while i < len(keys): - assert d[keys[i]] == i + assert_(d[keys[i]] == i) i += 1 return 42 return fn @@ -701,13 +702,13 @@ class UsingFrameworkTest(object): def does_stuff(): fd = os.open(filename, os.O_WRONLY | os.O_CREAT, 0777) count = os.write(fd, "hello world\n") - assert count == len("hello world\n") + assert_(count == len("hello world\n")) os.close(fd) fd = os.open(filename, os.O_RDONLY, 0777) result = os.lseek(fd, 1, 0) - assert result == 1 + assert_(result == 1) data = os.read(fd, 500) - assert data == "ello world\n" + assert_(data == "ello world\n") os.close(fd) return 0 @@ -870,7 +871,7 @@ class UsingFrameworkTest(object): # ^^^ likely to trigger a collection xr = xr.prev i += 1 - assert xr is None + assert_(xr is None) def check(xr, n, step): "Check that the identity hashes are still correct." @@ -882,7 +883,7 @@ class UsingFrameworkTest(object): raise ValueError xr = xr.prev i += 1 - assert xr is None + assert_(xr is None) def h(n): x3 = g(3) @@ -947,7 +948,7 @@ class UsingFrameworkTest(object): for i in range(20): x.append((1, lltype.malloc(S))) for i in range(50): - assert l2[i] == (40 + i) * 3 + assert_(l2[i] == (40 + i) * 3) return 0 return fn @@ -965,7 +966,7 @@ class UsingFrameworkTest(object): rgc.ll_arraycopy(l, l2, 40, 0, 50) rgc.collect() for i in range(50): - assert l2[i] == l[40 + i] + assert_(l2[i] == l[40 + i]) return 0 return fn @@ -985,7 +986,7 @@ class UsingFrameworkTest(object): found = True if x == lltype.cast_opaque_ptr(llmemory.GCREF, s.u): os.write(2, "s.u should not be found!\n") - assert False + assert_(False) return found == 1 def fn(): @@ -994,7 +995,7 @@ class UsingFrameworkTest(object): found = g(s) if not found: os.write(2, "not found!\n") - assert False + assert_(False) s.u.x = 42 return 0 @@ -1013,8 +1014,8 @@ class UsingFrameworkTest(object): gcref1 = lltype.cast_opaque_ptr(llmemory.GCREF, s) gcref2 = lltype.cast_opaque_ptr(llmemory.GCREF, s.u) lst = rgc.get_rpy_referents(gcref1) - assert gcref2 in lst - assert gcref1 not in lst + assert_(gcref2 in lst) + assert_(gcref1 not in lst) s.u.x = 42 return 0 @@ -1030,7 +1031,7 @@ class UsingFrameworkTest(object): def check(gcref, expected): result = rgc._is_rpy_instance(gcref) - assert result == expected + assert_(result == expected) def fn(): s = lltype.malloc(S) @@ -1060,21 +1061,21 @@ class UsingFrameworkTest(object): def fn(): foo = Foo() gcref1 = rgc.cast_instance_to_gcref(foo) - assert rgc.try_cast_gcref_to_instance(Foo, gcref1) is foo - assert rgc.try_cast_gcref_to_instance(FooBar, gcref1) is None - assert rgc.try_cast_gcref_to_instance(Biz, gcref1) is None + assert_(rgc.try_cast_gcref_to_instance(Foo, gcref1) is foo) + assert_(rgc.try_cast_gcref_to_instance(FooBar, gcref1) is None) + assert_(rgc.try_cast_gcref_to_instance(Biz, gcref1) is None) foobar = FooBar() gcref2 = rgc.cast_instance_to_gcref(foobar) - assert rgc.try_cast_gcref_to_instance(Foo, gcref2) is foobar - assert rgc.try_cast_gcref_to_instance(FooBar, gcref2) is foobar - assert rgc.try_cast_gcref_to_instance(Biz, gcref2) is None + assert_(rgc.try_cast_gcref_to_instance(Foo, gcref2) is foobar) + assert_(rgc.try_cast_gcref_to_instance(FooBar, gcref2) is foobar) + assert_(rgc.try_cast_gcref_to_instance(Biz, gcref2) is None) s = lltype.malloc(S) gcref3 = lltype.cast_opaque_ptr(llmemory.GCREF, s) - assert rgc.try_cast_gcref_to_instance(Foo, gcref3) is None - assert rgc.try_cast_gcref_to_instance(FooBar, gcref3) is None - assert rgc.try_cast_gcref_to_instance(Biz, gcref3) is None + assert_(rgc.try_cast_gcref_to_instance(Foo, gcref3) is None) + assert_(rgc.try_cast_gcref_to_instance(FooBar, gcref3) is None) + assert_(rgc.try_cast_gcref_to_instance(Biz, gcref3) is None) return 0 @@ -1101,13 +1102,13 @@ class UsingFrameworkTest(object): a = lltype.malloc(A, 1000) gcref1 = lltype.cast_opaque_ptr(llmemory.GCREF, s) int1 = rgc.get_rpy_memory_usage(gcref1) - assert 8 <= int1 <= 32 + assert_(8 <= int1 <= 32) gcref2 = lltype.cast_opaque_ptr(llmemory.GCREF, s.u) int2 = rgc.get_rpy_memory_usage(gcref2) - assert 4 * 9 <= int2 <= 8 * 12 + assert_(4 * 9 <= int2 <= 8 * 12) gcref3 = lltype.cast_opaque_ptr(llmemory.GCREF, a) int3 = rgc.get_rpy_memory_usage(gcref3) - assert 4 * 1001 <= int3 <= 8 * 1010 + assert_(4 * 1001 <= int3 <= 8 * 1010) return 0 return fn @@ -1133,10 +1134,10 @@ class UsingFrameworkTest(object): int3 = rgc.get_rpy_type_index(gcref3) gcref4 = lltype.cast_opaque_ptr(llmemory.GCREF, s2) int4 = rgc.get_rpy_type_index(gcref4) - assert int1 != int2 - assert int1 != int3 - assert int2 != int3 - assert int1 == int4 + assert_(int1 != int2) + assert_(int1 != int3) + assert_(int2 != int3) + assert_(int1 == int4) return 0 return fn @@ -1216,8 +1217,8 @@ class UsingFrameworkTest(object): os.close(fd) # a = rgc.get_typeids_list() - assert len(a) > 1 - assert 0 < rffi.cast(lltype.Signed, a[1]) < 10000 + assert_(len(a) > 1) + assert_(0 < rffi.cast(lltype.Signed, a[1]) < 10000) return 0 return fn @@ -1240,20 +1241,20 @@ class UsingFrameworkTest(object): a2 = A() if not rgc.has_gcflag_extra(): return 0 # cannot test it then - assert rgc.get_gcflag_extra(a1) == False - assert rgc.get_gcflag_extra(a2) == False + assert_(rgc.get_gcflag_extra(a1) == False) + assert_(rgc.get_gcflag_extra(a2) == False) rgc.toggle_gcflag_extra(a1) - assert rgc.get_gcflag_extra(a1) == True - assert rgc.get_gcflag_extra(a2) == False + assert_(rgc.get_gcflag_extra(a1) == True) + assert_(rgc.get_gcflag_extra(a2) == False) rgc.toggle_gcflag_extra(a2) - assert rgc.get_gcflag_extra(a1) == True - assert rgc.get_gcflag_extra(a2) == True + assert_(rgc.get_gcflag_extra(a1) == True) + assert_(rgc.get_gcflag_extra(a2) == True) rgc.toggle_gcflag_extra(a1) - assert rgc.get_gcflag_extra(a1) == False - assert rgc.get_gcflag_extra(a2) == True + assert_(rgc.get_gcflag_extra(a1) == False) + assert_(rgc.get_gcflag_extra(a2) == True) rgc.toggle_gcflag_extra(a2) - assert rgc.get_gcflag_extra(a1) == False - assert rgc.get_gcflag_extra(a2) == False + assert_(rgc.get_gcflag_extra(a1) == False) + assert_(rgc.get_gcflag_extra(a2) == False) return 0 return fn @@ -1271,11 +1272,11 @@ class UsingFrameworkTest(object): def fn(): s = lltype.malloc(S, zero=True) - assert s.x == 0 + assert_(s.x == 0) s2 = lltype.malloc(S2, zero=True) - assert s2.parent.x == 0 + assert_(s2.parent.x == 0) a = lltype.malloc(A, 3, zero=True) - assert a[2] == 0 + assert_(a[2] == 0) # XXX not supported right now in gctransform/framework.py: #b = lltype.malloc(B, 3, zero=True) #assert len(b.y) == 3 @@ -1307,7 +1308,7 @@ class UsingFrameworkTest(object): def test_long_chain_of_instances(self): res = self.run("long_chain_of_instances") assert res == 1500 - + class TestSemiSpaceGC(UsingFrameworkTest, snippet.SemiSpaceGCTestDefines): gcpolicy = "semispace" @@ -1475,7 +1476,7 @@ class TestSemiSpaceGC(UsingFrameworkTest, snippet.SemiSpaceGCTestDefines): def define_nursery_hash_base(cls): from rpython.rlib.debug import debug_print - + class A: pass def fn(): @@ -1492,7 +1493,7 @@ class TestSemiSpaceGC(UsingFrameworkTest, snippet.SemiSpaceGCTestDefines): debug_print("objects", len(objects)) for i in range(len(objects)): debug_print(i) - assert compute_identity_hash(objects[i]) == hashes[i] + assert_(compute_identity_hash(objects[i]) == hashes[i]) debug_print("storing in dict") unique[hashes[i]] = None debug_print("done") @@ -1528,10 +1529,10 @@ class TestSemiSpaceGC(UsingFrameworkTest, snippet.SemiSpaceGCTestDefines): def check(lst): hashes = [] for i, (s, a) in enumerate(lst): - assert a.x == i + assert_(a.x == i) rgc.ll_write_final_null_char(s) for i, (s, a) in enumerate(lst): - assert a.x == i # check it was not overwritten + assert_(a.x == i) # check it was not overwritten def fn(): check(prebuilt) lst1 = [] @@ -1769,7 +1770,7 @@ class TestIncrementalMiniMarkGC(TestMiniMarkGC): assert popen.wait() in (-6, 134) # aborted # note: it seems that on some systems we get 134 and on # others we get -6. Bash is supposed to translate the - # SIGABRT (signal 6) from the subprocess into the exit + # SIGABRT (signal 6) from the subprocess into the exit # code 128+6, but I guess it may not always do so. assert 'out of memory:' in child_stderr return '42' @@ -1822,12 +1823,12 @@ class TestIncrementalMiniMarkGC(TestMiniMarkGC): def f(should_disable): x1 = X() rgc.collect() # make x1 old - assert not rgc.can_move(x1) + assert_(not rgc.can_move(x1)) x1 = None # if should_disable: gc.disable() - assert not gc.isenabled() + assert_(not gc.isenabled()) # try to trigger a major collection N = 100 # this should be enough, increase if not lst = [] @@ -1836,7 +1837,7 @@ class TestIncrementalMiniMarkGC(TestMiniMarkGC): #print i, counter.val # gc.enable() - assert gc.isenabled() + assert_(gc.isenabled()) return counter.val return f @@ -1861,7 +1862,7 @@ class TestIncrementalMiniMarkGC(TestMiniMarkGC): def f(): x1 = X() rgc.collect() # make x1 old - assert not rgc.can_move(x1) + assert_(not rgc.can_move(x1)) x1 = None # gc.disable() @@ -1875,11 +1876,11 @@ class TestIncrementalMiniMarkGC(TestMiniMarkGC): break if n == 100: print 'Endless loop!' - assert False, 'this looks like an endless loop' - + assert_(False, 'this looks like an endless loop') + if n < 4: # we expect at least 4 steps print 'Too few steps! n =', n - assert False + assert_(False) # check that the state transitions are reasonable first_state, _ = states[0] @@ -1887,9 +1888,9 @@ class TestIncrementalMiniMarkGC(TestMiniMarkGC): is_last = (i == len(states) - 1) is_valid = False if is_last: - assert old_state != new_state == first_state + assert_(old_state != new_state == first_state) else: - assert new_state == old_state or new_state == old_state+1 + assert_(new_state == old_state or new_state == old_state+1) return counter.val return f diff --git a/rpython/translator/c/test/test_rtagged.py b/rpython/translator/c/test/test_rtagged.py index 8ad224dcb89b016ceddf602f5563740cae33ce23..e070a784e7625d2ed5c1e768754ab4a882824e01 100644 --- a/rpython/translator/c/test/test_rtagged.py +++ b/rpython/translator/c/test/test_rtagged.py @@ -1,5 +1,5 @@ import sys, os -from rpython.rlib.objectmodel import UnboxedValue +from rpython.rlib.objectmodel import UnboxedValue, assert_ class A(object): @@ -38,24 +38,24 @@ prebuilt_b = B(939393) def entry_point(argv): n = 100 + len(argv) - assert C(n).get_untagged_value() == n + assert_(C(n).get_untagged_value() == n) x = makeint(42) - assert isinstance(x, C) - assert x.smallint == 42 + assert_(isinstance(x, C)) + assert_(x.smallint == 42) x = makeint(sys.maxint) - assert isinstance(x, B) - assert x.normalint == sys.maxint + assert_(isinstance(x, B)) + assert_(x.normalint == sys.maxint) x = makeint2(12) - assert x.meth(1000) == 1015 + assert_(x.meth(1000) == 1015) x = makeint2(-1) - assert x.meth(1000) == 1114 + assert_(x.meth(1000) == 1114) x = makeint2(0) - assert x.meth(1000) == 940395 + assert_(x.meth(1000) == 940395) os.write(1, "ALL OK\n") return 0 diff --git a/rpython/translator/c/test/test_standalone.py b/rpython/translator/c/test/test_standalone.py index 4ae9441bb323fe141f6ae95c96f71863fcb3578e..d89470d29313086d1c834d007b683c7fabe3cd85 100644 --- a/rpython/translator/c/test/test_standalone.py +++ b/rpython/translator/c/test/test_standalone.py @@ -4,7 +4,7 @@ import textwrap from rpython.config.translationoption import get_combined_translation_config from rpython.config.translationoption import SUPPORT__THREAD -from rpython.rlib.objectmodel import keepalive_until_here +from rpython.rlib.objectmodel import keepalive_until_here, assert_ from rpython.rlib.rarithmetic import r_longlong from rpython.rlib.debug import ll_assert, have_debug_prints, debug_flush from rpython.rlib.debug import debug_print, debug_start, debug_stop @@ -245,18 +245,18 @@ class TestStandalone(StandaloneTests): t = Translation(entry_point, backend='c', profopt=True, profoptargs="10", shared=True) t.backendopt() exe = t.compile() - assert (os.path.isfile("%s" % exe)) + assert os.path.isfile("%s" % exe) t = Translation(entry_point, backend='c', profopt=True, profoptargs="10", shared=False) t.backendopt() exe = t.compile() - assert (os.path.isfile("%s" % exe)) + assert os.path.isfile("%s" % exe) import rpython.translator.goal.targetrpystonedalone as rpy t = Translation(rpy.entry_point, backend='c', profopt=True, profoptargs='1000', shared=False) t.backendopt() exe = t.compile() - assert (os.path.isfile("%s" % exe)) + assert os.path.isfile("%s" % exe) if hasattr(os, 'setpgrp'): @@ -297,7 +297,7 @@ class TestStandalone(StandaloneTests): filename = str(udir.join('test_standalone_largefile')) r4800000000 = r_longlong(4800000000L) def entry_point(argv): - assert str(r4800000000 + r_longlong(len(argv))) == '4800000003' + assert_(str(r4800000000 + r_longlong(len(argv))) == '4800000003') fd = os.open(filename, os.O_RDWR | os.O_CREAT, 0644) os.lseek(fd, r4800000000, 0) newpos = os.lseek(fd, 0, 1) @@ -794,7 +794,7 @@ class TestStandalone(StandaloneTests): def test_assertion_error_debug(self): def entry_point(argv): - assert len(argv) != 1 + assert_(len(argv) != 1) return 0 t, cbuilder = self.compile(entry_point, debug=True) out, err = cbuilder.cmdexec("", expect_crash=True) @@ -804,7 +804,7 @@ class TestStandalone(StandaloneTests): def test_assertion_error_nondebug(self): def g(x): - assert x != 1 + assert_(x != 1) def f(argv): try: g(len(argv)) @@ -1120,7 +1120,7 @@ class TestStandalone(StandaloneTests): "NOT_RPYTHON" def entry_point(argv): state.seen += 100 - assert state.seen == 101 + assert_(state.seen == 101) print 'ok' enablestartup() return 0 @@ -1151,7 +1151,7 @@ class TestStandalone(StandaloneTests): # which, for some version of gcc8 compiler produced # out1 == out2 from rpython.rlib.rarithmetic import intmask - + def entry_point(argv): if len(argv) < 4: print 'need 3 arguments, not %s' % str(argv) @@ -1248,9 +1248,9 @@ class TestThread(object): break time.sleep(0.1) # invokes before/after # check that the malloced structures were not overwritten - assert s1.x == 0x11111111 - assert s2.x == 0x22222222 - assert s3.x == 0x33333333 + assert_(s1.x == 0x11111111) + assert_(s2.x == 0x22222222) + assert_(s3.x == 0x33333333) os.write(1, "done\n") return 0 @@ -1296,7 +1296,7 @@ class TestThread(object): rposix.set_saved_errno(value) for i in range(10000000): pass - assert rposix.get_saved_errno() == value + assert_(rposix.get_saved_errno() == value) def bootstrap(): rthread.gc_thread_start() @@ -1331,15 +1331,15 @@ class TestThread(object): break time.sleep(0.1) # invokes before/after # check that the malloced structures were not overwritten - assert x2.head == 51 - assert x2.tail.head == 62 - assert x2.tail.tail.head == 74 - assert x2.tail.tail.tail is None + assert_(x2.head == 51) + assert_(x2.tail.head == 62) + assert_(x2.tail.tail.head == 74) + assert_(x2.tail.tail.tail is None) # check the structures produced by the threads for i in range(5): - assert state.xlist[i].head == 123 - assert state.xlist[i].tail.head == 456 - assert state.xlist[i].tail.tail is None + assert_(state.xlist[i].head == 123) + assert_(state.xlist[i].tail.head == 456) + assert_(state.xlist[i].tail.tail is None) os.write(1, "%d ok\n" % (i+1)) return 0 @@ -1368,8 +1368,8 @@ class TestThread(object): print "Testing..." else: pid, status = os.waitpid(childpid, 0) - assert pid == childpid - assert status == 0 + assert_(pid == childpid) + assert_(status == 0) print "OK." return 0 diff --git a/rpython/translator/c/test/test_typed.py b/rpython/translator/c/test/test_typed.py index d6afbbfbaed9a6cf040351d167592ee438ba6c1f..67d8bff2beb1fe1735134c4b876326c210f6cfe4 100644 --- a/rpython/translator/c/test/test_typed.py +++ b/rpython/translator/c/test/test_typed.py @@ -5,7 +5,8 @@ import sys, os import py from rpython.rlib.rstackovf import StackOverflow -from rpython.rlib.objectmodel import compute_hash, current_object_addr_as_int +from rpython.rlib.objectmodel import ( + compute_hash, current_object_addr_as_int, assert_) from rpython.rlib.nonconst import NonConstant from rpython.rlib.rarithmetic import r_uint, r_ulonglong, r_longlong, intmask, longlongmask from rpython.rtyper.lltypesystem import rffi, lltype @@ -145,7 +146,7 @@ class TestTypedTestCase(object): def test_memoryerror(self): def g(i): return [0] * i - + def f(i): try: lst = g(i) @@ -613,7 +614,7 @@ class TestTypedTestCase(object): if algo == "siphash24": from rpython.rlib import rsiphash rsiphash.enable_siphash24() - assert length >= 1 + assert_(length >= 1) return str((compute_hash(s), compute_hash(u), compute_hash(v), @@ -657,7 +658,7 @@ class TestTypedTestCase(object): # didn't do the initial rehashing on its own for key, h in objectmodel.iterkeys_with_hash(prebuilt_d): print key, h - assert h == compute_hash(key) + assert_(h == compute_hash(key)) return 42 f = self.getcompiled(fn, [int]) @@ -759,7 +760,7 @@ class TestTypedTestCase(object): return f(n) except StackOverflow: return -42 - + def f(n): if n == 0: return 1 diff --git a/rpython/translator/sandbox/test/test_sandbox.py b/rpython/translator/sandbox/test/test_sandbox.py index 0db26a6b951cf65724c7b74d216ba001ce71dd11..b218d2296f995882bda003f8a00b2c992884163b 100644 --- a/rpython/translator/sandbox/test/test_sandbox.py +++ b/rpython/translator/sandbox/test/test_sandbox.py @@ -4,6 +4,7 @@ import struct import subprocess import signal +from rpython.rlib.objectmodel import assert_ from rpython.rtyper.lltypesystem import rffi from rpython.translator.interactive import Translation from rpython.translator.sandbox.sandlib import read_message, write_message @@ -51,9 +52,9 @@ def run_in_subprocess(exe): def test_open_dup(): def entry_point(argv): fd = os.open("/tmp/foobar", os.O_RDONLY, 0777) - assert fd == 77 + assert_(fd == 77) fd2 = os.dup(fd) - assert fd2 == 78 + assert_(fd2 == 78) return 0 exe = compile(entry_point) @@ -69,9 +70,9 @@ def test_open_dup_rposix(): from rpython.rlib import rposix def entry_point(argv): fd = rposix.open("/tmp/foobar", os.O_RDONLY, 0777) - assert fd == 77 + assert_(fd == 77) fd2 = rposix.dup(fd) - assert fd2 == 78 + assert_(fd2 == 78) return 0 exe = compile(entry_point) @@ -86,11 +87,11 @@ def test_open_dup_rposix(): def test_read_write(): def entry_point(argv): fd = os.open("/tmp/foobar", os.O_RDONLY, 0777) - assert fd == 77 + assert_(fd == 77) res = os.read(fd, 123) - assert res == "he\x00llo" + assert_(res == "he\x00llo") count = os.write(fd, "world\x00!\x00") - assert count == 42 + assert_(count == 42) os.close(fd) return 0 diff --git a/rpython/translator/test/test_exceptiontransform.py b/rpython/translator/test/test_exceptiontransform.py index 03f2a4c15e01e95842977fce39bbd9c799fc9dd7..e73f29885b6e9e989b99d7c9a5192486e5abf1ad 100644 --- a/rpython/translator/test/test_exceptiontransform.py +++ b/rpython/translator/test/test_exceptiontransform.py @@ -5,6 +5,7 @@ from rpython.translator import exceptiontransform from rpython.flowspace.model import summary from rpython.rtyper.test.test_llinterp import get_interpreter from rpython.translator.backendopt.all import backend_optimizations +from rpython.rlib.objectmodel import assert_ from rpython.conftest import option import sys @@ -259,9 +260,9 @@ class TestExceptionTransform: def foo(): # a bit hard to test, really a = llop.get_exception_addr(llmemory.Address) - assert lltype.typeOf(a) is llmemory.Address + assert_(lltype.typeOf(a) is llmemory.Address) a = llop.get_exc_value_addr(llmemory.Address) - assert lltype.typeOf(a) is llmemory.Address + assert_(lltype.typeOf(a) is llmemory.Address) return 42 f = self.compile(foo, []) res = f()