Example #1
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"})
Example #2
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'})
Example #3
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})
Example #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})