예제 #1
0
def test_literal_unpacking():
    l0 = Literal([1, 2, 3])
    a, b, c = l0
    print(a)
    assert c.name == "getitem"
    assert c.pos_args[0] is l0
    assert isinstance(c.pos_args[1], Literal)
    assert c.pos_args[1]._obj == 2
예제 #2
0
def test_literal_apply():
    l0 = Literal([1, 2, 3])
    print(str(l0))
    assert str(l0) == "0 Literal{[1, 2, 3]}"
예제 #3
0
def test_kwswitch():
    i = Literal()
    ab = scope.kwswitch(i, k1="a", k2="b", err=scope.Raise(Exception))
    assert rec_eval(ab, memo={i: "k1"}) == "a"
    assert rec_eval(ab, memo={i: "k2"}) == "b"
    assert_raises(Exception, rec_eval, ab, memo={i: "err"})
예제 #4
0
def test_switch_and_Raise():
    i = Literal()
    ab = scope.switch(i, "a", "b", scope.Raise(Exception))
    assert rec_eval(ab, memo={i: 0}) == "a"
    assert rec_eval(ab, memo={i: 1}) == "b"
    assert_raises(Exception, rec_eval, ab, memo={i: 2})
예제 #5
0
def test_literal_pprint():
    l = Literal(5)
    print(str(l))
    assert str(l) == "0 Literal{5}"
예제 #6
0
def test_kwswitch():
    i = Literal()
    ab = scope.kwswitch(i, k1='a', k2='b', err=scope.Raise(Exception))
    assert rec_eval(ab, memo={i: 'k1'}) == 'a'
    assert rec_eval(ab, memo={i: 'k2'}) == 'b'
    assert_raises(Exception, rec_eval, ab, memo={i: 'err'})
예제 #7
0
def test_switch_and_Raise():
    i = Literal()
    ab = scope.switch(i, 'a', 'b', scope.Raise(Exception))
    assert rec_eval(ab, memo={i: 0}) == 'a'
    assert rec_eval(ab, memo={i: 1}) == 'b'
    assert_raises(Exception, rec_eval, ab, memo={i: 2})