Пример #1
0
def test_abstract_clone_pending():
    loop = asyncio.new_event_loop()
    s1 = S(t=ty.Int[32])
    p = Pending(loop=loop, resolve=None, priority=None)
    sp = S(t=p)
    assert abstract_clone(sp) is sp
    p.set_result(ty.Int[32])
    assert abstract_clone(sp) is s1
Пример #2
0
def test_find_coherent_result_sync():
    def fn(x):
        if x == 0:
            raise ValueError('Oh no! Zero!')
        else:
            return x > 0

    loop = asyncio.new_event_loop()
    p1 = PendingFromList([1, 2, 3], None, None, loop=loop)
    p2 = PendingFromList([-1, -2, -3], None, None, loop=loop)
    p3 = PendingFromList([1, 2, -3], None, None, loop=loop)
    p4 = PendingFromList([0], None, None, loop=loop)
    assert find_coherent_result_sync(p1, fn) is True
    assert find_coherent_result_sync(p2, fn) is False
    with pytest.raises(InferenceError):
        find_coherent_result_sync(p3, fn)
    with pytest.raises(ValueError):
        find_coherent_result_sync(p4, fn)

    p = Pending(None, None, loop=loop)
    with pytest.raises(InferenceError):
        find_coherent_result_sync(p, fn)

    assert find_coherent_result_sync(10, fn) is True
    assert find_coherent_result_sync(-10, fn) is False
Пример #3
0
def test_concretize_recursive():
    loop = asyncio.new_event_loop()
    s = S(t=ty.Int[64])
    p = Pending(None, None, loop=loop)
    t = T([s, p])
    p.set_result(t)

    sa = S(t=ty.Int[64])
    ta = T.empty()
    ta.__init__([sa, ta])
    ta = ta.intern()

    async def coro():
        assert (await concretize_abstract(t)) is ta

    asyncio.run(coro())
Пример #4
0
def test_amerge_pending():
    loop = asyncio.new_event_loop()

    p = PendingFromList([ty.Int[64], ty.Float[64]], None, None, loop=loop)
    assert amerge(ty.Number, p, forced=False, bind_pending=False) is ty.Number
    assert amerge(p, ty.Number, forced=False, bind_pending=False) is ty.Number
    with pytest.raises(MyiaTypeError):
        print(amerge(p, ty.Number, forced=True, bind_pending=False))

    s1 = S(t=ty.Int[32])
    p = Pending(loop=loop, resolve=None, priority=None)
    sp = S(t=p)
    assert amerge(sp, s1, forced=True) is sp
    p.set_result(ty.Int[32])
    assert amerge(sp, s1) is s1
    assert amerge(s1, sp) is s1