Beispiel #1
0
    def test_list_key_invalid_index(self):
        def test_f_subscr():
            l = [0, 1, 2]
            return l[4] == 'b'

        with self.assertRaises(IndexError):
            test_f_subscr()
        self.assertTrue(pyjion.info(test_f_subscr)['compiled'])
        f = io.StringIO()
        with contextlib.redirect_stdout(f):
            pyjion.dis.dis(test_f_subscr)
        self.assertIn("ldarg.1", f.getvalue())
        self.assertIn("MethodTokens.METHOD_SUBSCR_LIST_I", f.getvalue())
Beispiel #2
0
    def test_arg0(self):
        def arg0() -> int:
            a = 1
            b = 2
            c = 3
            d = 4
            return a + b + c + d

        self.assertEqual(sys.getrefcount(arg0), 2)
        self.assertEqual(arg0(), 10)
        self.assertEqual(sys.getrefcount(arg0), 2)
        info = pyjion.info(arg0)
        self.assertTrue(info['compiled'])
Beispiel #3
0
    def test_arg4(self):
        class F:
            @classmethod
            def arg4(cls, e, f, g, h):
                a = 1
                b = 2
                c = 3
                d = 4
                return a + b + c + d + e + f + g + h

        self.assertEqual(F.arg4(5, 6, 7, 8), 36)
        info = pyjion.info(F.arg4.__code__)
        self.assertTrue(info['compiled'])
Beispiel #4
0
    def test_arg6(self):
        class F:
            def arg6(self, e, f, g, h, i, j):
                a = 1
                b = 2
                c = 3
                d = 4
                return a + b + c + d + e + f + g + h + i + j

        f = F()
        self.assertEqual(f.arg6(5, 6, 7, 8, 9, 10), 55)
        info = pyjion.info(f.arg6.__code__)
        self.assertTrue(info['compiled'])
Beispiel #5
0
    def test_arg10(self):
        class F:
            def arg10(self, e, f, g, h, i, j, k, l, m, n):
                a = 1
                b = 2
                c = 3
                d = 4
                return a + b + c + d + e + f + g + h + i + j + k + l + m + n

        f = F()
        self.assertEqual(f.arg10(5, 6, 7, 8, 9, 10, 11, 12, 13, 14), 105)
        info = pyjion.info(f.arg10.__code__)
        self.assertTrue(info['compiled'])
Beispiel #6
0
 def test_arg1_cfunction_exc(self):
     f = str("hello")
     o = 1000000
     pre_target_ref = sys.getrefcount(str.strip)
     pre_arg_ref = sys.getrefcount(f)
     pre_arg1_ref = sys.getrefcount(o)
     with self.assertRaises(TypeError):
         f.strip(o)
     self.assertEqual(sys.getrefcount(f), pre_arg_ref)
     self.assertEqual(sys.getrefcount(o), pre_arg1_ref)
     self.assertEqual(sys.getrefcount(str.strip), pre_target_ref)
     info = pyjion.info(self.test_arg1_cfunction_exc.__code__)
     self.assertTrue(info['compiled'])
Beispiel #7
0
    def test_arg3(self):
        class F:
            def arg3(self, e, f, g):
                a = 1
                b = 2
                c = 3
                d = 4
                return a + b + c + d + e + f + g

        f = F()
        self.assertEqual(f.arg3(5, 6, 7), 28)
        info = pyjion.info(f.arg3.__code__)
        self.assertTrue(info['compiled'])
Beispiel #8
0
    def test_arg8(self):
        class F:
            @classmethod
            def arg8(cls, e, f, g, h, i, j, k, l):
                a = 1
                b = 2
                c = 3
                d = 4
                return a + b + c + d + e + f + g + h + i + j + k + l

        self.assertEqual(F.arg8(5, 6, 7, 8, 9, 10, 11, 12), 78)
        info = pyjion.info(F.arg8.__code__)
        self.assertTrue(info['compiled'], info['compile_result'])
Beispiel #9
0
    def test_arg10(self):
        class F:
            @classmethod
            def arg10(cls, e, f, g, h, i, j, k, l, m, n):
                a = 1
                b = 2
                c = 3
                d = 4
                return a + b + c + d + e + f + g + h + i + j + k + l + m + n

        self.assertEqual(F.arg10(5, 6, 7, 8, 9, 10, 11, 12, 13, 14), 105)
        info = pyjion.info(F.arg10.__code__)
        self.assertTrue(info['compiled'], info['compile_result'])
Beispiel #10
0
def test_never():
    def _f():
        a = 1
        b = 2
        c = 3
        d = 4
        return a + b + c + d

    info = pyjion.info(_f)

    assert not info.compiled
    assert not info.failed
    assert info.run_count == 0
Beispiel #11
0
    def test_arg6(self):
        class F:
            @classmethod
            def arg6(cls, e, f, g, h, i, j):
                a = 1
                b = 2
                c = 3
                d = 4
                return a + b + c + d + e + f + g + h + i + j

        self.assertEqual(F.arg6(5, 6, 7, 8, 9, 10), 55)
        info = pyjion.info(F.arg6.__code__)
        self.assertTrue(info['compiled'], info['compile_result'])
Beispiel #12
0
def test_basic():
    def _f():
        def add_a(z):
            if len(z) < 5:
                z.append('a')
                return add_a(z)
            return z

        return add_a([])

    assert _f() == ['a', 'a', 'a', 'a', 'a']
    inf = pyjion.info(_f)
    assert inf.compiled
Beispiel #13
0
    def test_dict_key(self):
        def test_f():
            a = {0: 'a'}
            a[0] = 'b'
            return a[0] == 'b'

        self.assertTrue(test_f())
        self.assertTrue(pyjion.info(test_f)['compiled'])
        f = io.StringIO()
        with contextlib.redirect_stdout(f):
            pyjion.dis.dis(test_f)
        self.assertIn("ldarg.1", f.getvalue())
        self.assertIn("MethodTokens.METHOD_STORE_SUBSCR_DICT", f.getvalue())
Beispiel #14
0
    def test_unknown_key_string_const(self):
        def test_f(x):
            x['y'] = 'b'
            return x['y'] == 'b'

        self.assertTrue(test_f({}))
        self.assertTrue(pyjion.info(test_f)['compiled'])
        f = io.StringIO()
        with contextlib.redirect_stdout(f):
            pyjion.dis.dis(test_f)
        self.assertIn("ldarg.1", f.getvalue())
        self.assertIn("MethodTokens.METHOD_STORE_SUBSCR_DICT_HASH",
                      f.getvalue())
Beispiel #15
0
    def test_arg11(self):
        class F:
            @classmethod
            def arg11(cls, e, f, g, h, i, j, k, l, m, n, o):
                a = 1
                b = 2
                c = 3
                d = 4
                return a + b + c + d + e + f + g + h + i + j + k + l + m + n + o

        self.assertEqual(F.arg11(5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15), 120)
        info = pyjion.info(F.arg11.__code__)
        self.assertTrue(info['compiled'])
Beispiel #16
0
    def test_arg5(self):
        class F:
            def arg5(self, e, f, g, h, i):
                a = 1
                b = 2
                c = 3
                d = 4
                return a + b + c + d + e + f + g + h + i

        f = F()
        self.assertEqual(f.arg5(5, 6, 7, 8, 9), 45)
        info = pyjion.info(f.arg5.__code__)
        self.assertTrue(info['compiled'], info['compile_result'])
Beispiel #17
0
    def test_arg1_unpack_tuple_exc(self):
        def arg1(e):
            raise ValueError

        args = ('5',)
        pre_ref = sys.getrefcount(args)
        self.assertEqual(sys.getrefcount(arg1), 2)
        with self.assertRaises(ValueError):
            arg1(*args)
        self.assertEqual(sys.getrefcount(arg1), 2)
        self.assertEqual(sys.getrefcount(args), pre_ref)
        info = pyjion.info(arg1)
        self.assertTrue(info['compiled'])
Beispiel #18
0
    def test_arg7(self):
        class F:
            def arg7(self, e, f, g, h, i, j, k):
                a = 1
                b = 2
                c = 3
                d = 4
                return a + b + c + d + e + f + g + h + i + j + k

        f = F()
        self.assertEqual(f.arg7(5, 6, 7, 8, 9, 10, 11), 66)
        info = pyjion.info(f.arg7.__code__)
        self.assertTrue(info['compiled'], info['compile_result'])
Beispiel #19
0
    def test_arg2(self):
        class F:
            def arg2(self, e, f):
                a = 1
                b = 2
                c = 3
                d = 4
                return a + b + c + d + e + f

        f = F()
        self.assertEqual(f.arg2(5, 6), 21)
        info = pyjion.info(f.arg2.__code__)
        self.assertTrue(info['compiled'])
Beispiel #20
0
    def test_arg9(self):
        class F:
            def arg9(self, e, f, g, h, i, j, k, l, m):
                a = 1
                b = 2
                c = 3
                d = 4
                return a + b + c + d + e + f + g + h + i + j + k + l + m

        f = F()
        self.assertEqual(f.arg9(5, 6, 7, 8, 9, 10, 11, 12, 13), 91)
        info = pyjion.info(f.arg9.__code__)
        self.assertTrue(info['compiled'], info['compile_result'])
Beispiel #21
0
    def test_arg4(self):
        class F:
            def arg4(self, e, f, g, h):
                a = 1
                b = 2
                c = 3
                d = 4
                return a + b + c + d + e + f + g + h

        f = F()
        self.assertEqual(f.arg4(5, 6, 7, 8), 36)
        info = pyjion.info(f.arg4.__code__)
        self.assertTrue(info['compiled'])
Beispiel #22
0
 def test_arg15_cfunction_exc(self):
     f = str("{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}")
     arg1 = '5'
     pre_refcnt = sys.getrefcount(f)
     pre_refcnt_a = sys.getrefcount(arg1)
     target_pre_refcnt = sys.getrefcount(str.format)
     with self.assertRaises(IndexError):
         f.format(arg1, '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18')
     self.assertEqual(sys.getrefcount(f), pre_refcnt)
     self.assertEqual(sys.getrefcount(str.format), target_pre_refcnt)
     self.assertEqual(sys.getrefcount(arg1), pre_refcnt_a)
     info = pyjion.info(self.test_arg15_cfunction_exc.__code__)
     self.assertTrue(info['compiled'])
Beispiel #23
0
    def test_arg8(self):
        class F:
            def arg8(self, e, f, g, h, i, j, k, l):
                a = 1
                b = 2
                c = 3
                d = 4
                return a + b + c + d + e + f + g + h + i + j + k + l

        f = F()
        self.assertEqual(f.arg8(5, 6, 7, 8, 9, 10, 11, 12), 78)
        info = pyjion.info(f.arg8.__code__)
        self.assertTrue(info['compiled'])
Beispiel #24
0
 def test_arg15_cfunction(self):
     a = 500
     b = 600
     target = math.hypot
     pre_ref_target = sys.getrefcount(target)
     pre_ref_a = sys.getrefcount(a)
     pre_ref_b = sys.getrefcount(b)
     self.assertEqual(target(a, b, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19), 782.54648424231)
     self.assertEqual(sys.getrefcount(target), pre_ref_target)
     self.assertEqual(sys.getrefcount(a), pre_ref_a)
     self.assertEqual(sys.getrefcount(b), pre_ref_b)
     info = pyjion.info(self.test_arg15_cfunction.__code__)
     self.assertTrue(info['compiled'])
Beispiel #25
0
    def test_arg2(self):
        class F:
            @classmethod
            def arg2(cls, e, f):
                a = 1
                b = 2
                c = 3
                d = 4
                return a + b + c + d + e + f

        self.assertEqual(F.arg2(5, 6), 21)
        info = pyjion.info(F.arg2.__code__)
        self.assertTrue(info['compiled'])
Beispiel #26
0
    def test_arg7(self):
        class F:
            @classmethod
            def arg7(cls, e, f, g, h, i, j, k):
                a = 1
                b = 2
                c = 3
                d = 4
                return a + b + c + d + e + f + g + h + i + j + k

        self.assertEqual(F.arg7(5, 6, 7, 8, 9, 10, 11), 66)
        info = pyjion.info(F.arg7.__code__)
        self.assertTrue(info['compiled'])
Beispiel #27
0
    def test_arg3(self):
        class F:
            @classmethod
            def arg3(cls, e, f, g):
                a = 1
                b = 2
                c = 3
                d = 4
                return a + b + c + d + e + f + g

        self.assertEqual(F.arg3(5, 6, 7), 28)
        info = pyjion.info(F.arg3.__code__)
        self.assertTrue(info['compiled'])
Beispiel #28
0
    def test_arg9(self):
        class F:
            @classmethod
            def arg9(cls, e, f, g, h, i, j, k, l, m):
                a = 1
                b = 2
                c = 3
                d = 4
                return a + b + c + d + e + f + g + h + i + j + k + l + m

        self.assertEqual(F.arg9(5, 6, 7, 8, 9, 10, 11, 12, 13), 91)
        info = pyjion.info(F.arg9.__code__)
        self.assertTrue(info['compiled'])
Beispiel #29
0
    def test_arg5(self):
        class F:
            @classmethod
            def arg5(cls, e, f, g, h, i):
                a = 1
                b = 2
                c = 3
                d = 4
                return a + b + c + d + e + f + g + h + i

        self.assertEqual(F.arg5(5, 6, 7, 8, 9), 45)
        info = pyjion.info(F.arg5.__code__)
        self.assertTrue(info['compiled'])
Beispiel #30
0
    def test_list_key_builtin(self):
        def test_f():
            a = list(('a', ))
            a[0] = 'b'
            return a[0] == 'b'

        self.assertTrue(test_f())
        self.assertTrue(pyjion.info(test_f)['compiled'])
        f = io.StringIO()
        with contextlib.redirect_stdout(f):
            pyjion.dis.dis(test_f)
        self.assertIn("ldarg.1", f.getvalue())
        self.assertIn("MethodTokens.METHOD_STORE_SUBSCR_LIST_I", f.getvalue())