当前位置: 首页>>代码示例>>Python>>正文


Python runtest.compile_function函数代码示例

本文整理汇总了Python中pypy.translator.js.test.runtest.compile_function函数的典型用法代码示例。如果您正苦于以下问题:Python compile_function函数的具体用法?Python compile_function怎么用?Python compile_function使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了compile_function函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_bool_return

def test_bool_return():
    def bool_return_False():
        return False
    def bool_return_True():
        return True
    f_false = compile_function(bool_return_False, [])
    assert f_false() == bool_return_False()
    f_true  = compile_function(bool_return_True , [])
    assert f_true()  == bool_return_True()    
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:9,代码来源:test_runtest.py

示例2: test_slice

 def test_slice(self):
     def one_slice(s):
         return s[1:]
         
     def two_slice(s):
         return s[2:]
     
     fn = compile_function(one_slice, [str])
     assert fn("dupa") == "upa"
     fn = compile_function(two_slice, [str])
     assert fn("kupa") == "pa"
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:11,代码来源:test_seq.py

示例3: test_is

def test_is():
    def testfn():
        l1 = []
        return l1 is l1
    fn = compile_function(testfn, [])
    result = fn()
    assert result == True
    def testfn():
        l1 = []
        return l1 is None
    fn = compile_function(testfn, [])
    result = fn()
    assert result == False
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:13,代码来源:test_typed.py

示例4: test_get_set_del_slice

def test_get_set_del_slice():
    def get_set_del_nonneg_slice(): # no neg slices for now!
        l = [ord('a'), ord('b'), ord('c'), ord('d'), ord('e'), ord('f'), ord('g'), ord('h'), ord('i'), ord('j')]
        del l[:1]
        bound = len(l)-1
        if bound >= 0:
            del l[bound:]
        del l[2:4]
        #l[:1] = [3]
        #bound = len(l)-1
        #assert bound >= 0
        #l[bound:] = [9]    no setting slice into lists for now
        #l[2:4] = [8,11]
        l[0], l[-1], l[2], l[3] = 3, 9, 8, 11

        list_3_c = l[:2]
        list_9 = l[5:]
        list_11_h = l[3:5]
        return list((len(l), l[0], l[1], l[2], l[3], l[4], l[5],
                     len(list_3_c),  list_3_c[0],  list_3_c[1],
                     len(list_9),    list_9[0],
                     len(list_11_h), list_11_h[0], list_11_h[1]))
    
    def wrapper():
        res = get_set_del_nonneg_slice()
        expected = [6, 3, ord('c'), 8, 11, ord('h'), 9,
                    2, 3, ord('c'),
                    1, 9,
                    2, 11, ord('h')]
    
        return res == expected

    fn = compile_function(wrapper, [])
    result = fn()
    assert result 
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:35,代码来源:test_typed.py

示例5: test_global_instance

 def test_global_instance(self): #issue we restart every test with a fresh set of globals
     f = compile_function(llvmsnippet.global_instance, [int])
     assert f(-1) == llvmsnippet.global_instance(-1)
     for i in range(20):
         x = f(i)
         y = llvmsnippet.global_instance(i)
         assert x == y
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:7,代码来源:test_class.py

示例6: test_circular_class

def test_circular_class():
    def circular_class():
        b = A(a)
        return b.b
    
    fn = compile_function(circular_class, [])
    assert fn() == 3
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:7,代码来源:test_class.py

示例7: test_ackermann

 def test_ackermann(self):
     f = compile_function(llvmsnippet.ackermann, [int, int])
     for i in range(4):  # (otherwise too much recursion) max 4 in Safari, max 7 in Firefox, IE allows more recursion
         assert f(0, i) == i + 1
         assert f(1, i) == i + 2
         assert f(2, i) == 2 * i + 3
         assert f(3, i) == 2 ** (i + 3) - 3
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:7,代码来源:test_rsnippet1.py

示例8: test_pbc_function1

 def test_pbc_function1(self):
     #py.test.skip("Method mapping not implemented")
     f = compile_function(llvmsnippet.pbc_function1, [int])
     assert f(0) == 2
     assert f(1) == 4
     assert f(2) == 6
     assert f(3) == 8
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:7,代码来源:test_rsnippet1.py

示例9: test_time_waster

 def test_time_waster(self):
     #py.test.skip("Loop error in loop detection software")
     f = compile_function(test.time_waster, [int])
     assert f(1) == 1
     assert f(2) == 2
     assert f(3) == 6
     assert f(4) == 12
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:7,代码来源:test_snippet.py

示例10: test_simple3

def test_simple3():
    def raise_(i):
        if i == 0:
            raise TestException()
        elif i == 1:
            raise MyException(42)
        else:
            return 3
    def fn(i):
        try:
            a = raise_(i) + 11
            b = raise_(i) + 12
            c = raise_(i) + 13
            return a+b+c
        except TestException: 
            return 7
        except MyException: 
            return 123
        except:
            return 22
        return 66
    f = compile_function(fn, [int])
    assert f(0) == fn(0)
    assert f(1) == fn(1)
    assert f(2) == fn(2)
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:25,代码来源:test_exception.py

示例11: test_normal_list

 def test_normal_list(self):
     def normal_list():
         l = [1,2,3]
         return l[1]
     
     fn = compile_function(normal_list, [])
     assert fn() == 2
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:7,代码来源:test_seq.py

示例12: test_raise_outside_testfn

def test_raise_outside_testfn():
    def raiser(n):
        if n < 0:
            raise ValueError("hello")
        else:
            raise MyException("world")

    def intermediate(n):
        raiser(n)
        
    def testfn(n):
        try:
            intermediate(n)
        except ValueError:
            return 1
        except Exception:
            return 2
        return 0

    saved = no_magic()
    try:
        f = compile_function(testfn, [int])
        assert f(1) == testfn(1)
        assert f(-1) == testfn(-1)
    finally:
        restore_magic(saved)
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:26,代码来源:test_exception.py

示例13: test_init_0

 def test_init_0(self):
     def l_init():
         l = [0] * 100
         return l[38]
     
     fn = compile_function(l_init, [])
     assert fn() == 0
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:7,代码来源:test_seq.py

示例14: test_upperlower

 def test_upperlower(self):
     def upperlower():
         s = "aBaF"
         return s.upper() + s.lower()
     
     fn = compile_function(upperlower, [])
     assert fn() == "ABAFabaf"
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:7,代码来源:test_seq.py

示例15: test_basicexternal_element

def test_basicexternal_element():
    def be_fun():
        b = B()
        b.a = a
        b.a.some_code("aa")
    
    fun = compile_function(be_fun, [])
    assert check_source_contains(fun, "\.some_code")
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:8,代码来源:test_basicexternal.py


注:本文中的pypy.translator.js.test.runtest.compile_function函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。