示例#1
0
def test_amerge():
    a = T([S(1), S(t=ty.Int[64])])
    b = T([S(1), S(t=ty.Int[64])])
    c = T([S(t=ty.Int[64]), S(t=ty.Int[64])])

    assert amerge(a, b, forced=False) is a
    assert amerge(a, c, forced=False) == c
    assert amerge(c, a, forced=False) is c

    with pytest.raises(MyiaTypeError):
        amerge(a, c, forced=True)

    assert amerge(1, 2, forced=False) is ANYTHING
    with pytest.raises(MyiaTypeError):
        assert amerge(1, 2, forced=True)

    with pytest.raises(MyiaTypeError):
        assert amerge("hello", "world", forced=False)

    assert amerge(ty.Int, ty.Int[64], forced=False) is ty.Int
    assert amerge(ty.Int[64], ty.Int, forced=False) is ty.Int
    with pytest.raises(MyiaTypeError):
        amerge(ty.Float, ty.Int, forced=False)
    with pytest.raises(MyiaTypeError):
        amerge(ty.Int[64], ty.Int, forced=True)

    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))

    assert amerge(AbstractError(DEAD),
                  AbstractError(ANYTHING),
                  forced=False) is AbstractError(ANYTHING)

    d1 = {'x': 1}
    d2 = {'y': 2}
    with pytest.raises(MyiaTypeError):
        print(amerge(d1, d2))

    td1 = TrackDict({ALIASID: 1})
    td2 = TrackDict({})
    with pytest.raises(MyiaTypeError):
        print(amerge(td1, td2, forced=True))
示例#2
0
def test_amerge():
    a = T([S(1), S(t=ty.Int[64])])
    b = T([S(1), S(t=ty.Int[64])])
    c = T([S(t=ty.Int[64]), S(t=ty.Int[64])])

    assert amerge(a, b, forced=False) is a
    assert amerge(a, c, forced=False) == c
    assert amerge(c, a, forced=False) is c

    with pytest.raises(MyiaTypeError):
        amerge(a, c, forced=True)

    assert amerge(1, 2, forced=False) is ANYTHING
    with pytest.raises(MyiaTypeError):
        assert amerge(1, 2, forced=True)

    with pytest.raises(MyiaTypeError):
        assert amerge("hello", "world", forced=False)

    assert amerge(ty.Int, ty.Int[64], forced=False) is ty.Int
    assert amerge(ty.Int[64], ty.Int, forced=False) is ty.Int
    with pytest.raises(MyiaTypeError):
        amerge(ty.Float, ty.Int, forced=False)
    with pytest.raises(MyiaTypeError):
        amerge(ty.Int[64], ty.Int, forced=True)

    assert amerge(
        AbstractError(DEAD), AbstractError(ANYTHING), forced=False
    ) is AbstractError(ANYTHING)

    assert amerge(
        AbstractError(ANYTHING), AbstractError(DEAD), forced=True
    ) is AbstractError(ANYTHING)

    d1 = {"x": 1}
    d2 = {"y": 2}
    with pytest.raises(MyiaTypeError):
        print(amerge(d1, d2))

    td1 = TrackDict({ALIASID: 1})
    td2 = TrackDict({})
    with pytest.raises(MyiaTypeError):
        print(amerge(td1, td2, forced=True))