Exemple #1
0
def test_NS():
    ns = NS(x=1, y=2)

    assert ns.x == 1
    assert ns.y == 2

    ns.a = 3
    assert ns.a == 3
    assert ns['a'] == 3

    ns['b'] = 4
    assert ns['b'] == 4
    assert ns.b == 4

    assert repr(ns) == 'NS(x=1, y=2, a=3, b=4)'
Exemple #2
0
def test_NS():
    ns = NS(x=1, y=2)

    assert ns.x == 1
    assert ns.y == 2

    ns.a = 3
    assert ns.a == 3
    assert ns["a"] == 3

    ns["b"] = 4
    assert ns["b"] == 4
    assert ns.b == 4

    assert repr(ns) == "NS(x=1, y=2, a=3, b=4)"
Exemple #3
0
    assert new.get(skx, 0) == 17
    assert new.get(sky, 0) == 8


def test_operation_str():
    assert str(operations.user_switch) == repr(operations.user_switch)
    assert str(operations.user_switch) == "myia.operations.user_switch"


def test_list_to_cons():
    li = [1, 2, 3]
    li_c = Cons(1, Cons(2, Cons(3, Empty())))
    assert Cons.from_list(li) == li_c


cantaloup = NS(apple={"banana": 456})


def test_registry():
    r = Registry(default_field="banana")
    a = HasDefaults("a", {"banana": 123}, defaults_field=None)
    b = HasDefaults("b", {"banana": 123}, defaults_field=None)
    c = HasDefaults("c",
                    "tests.utils.test_misc.cantaloup",
                    defaults_field="apple")
    r.register(a)(2)
    assert r[a] == 2
    assert r[b] == 123
    assert r[c] == 456
    with pytest.raises(TypeError):
        print(HasDefaults("d", 123, defaults_field="apple"))
Exemple #4
0
    assert new.get(skx, 0) == 17
    assert new.get(sky, 0) == 8


def test_operation_str():
    assert str(operations.user_switch) == repr(operations.user_switch)
    assert str(operations.user_switch) == 'myia.operations.user_switch'


def test_list_to_cons():
    li = [1, 2, 3]
    li_c = Cons(1, Cons(2, Cons(3, Empty())))
    assert Cons.from_list(li) == li_c


cantaloup = NS(apple={'banana': 456})


def test_registry():
    r = Registry(default_field='banana')
    a = HasDefaults('a', {'banana': 123}, defaults_field=None)
    b = HasDefaults('b', {'banana': 123}, defaults_field=None)
    c = HasDefaults('c',
                    'tests.utils.test_misc.cantaloup',
                    defaults_field='apple')
    r.register(a)(2)
    assert r[a] == 2
    assert r[b] == 123
    assert r[c] == 456
    with pytest.raises(TypeError):
        print(HasDefaults('d', 123, defaults_field='apple'))