Example #1
0
def test_set_get_value(val):
    inter = duktape.Interpreter()
    inter.set('val', val)

    result = inter.get('val')
    assert val == result

    result = inter.eval('val')
    assert val == result
Example #2
0
def test_invalid_call_js_function():
    inter = duktape.Interpreter()
    result = inter.eval(r"""
        function f(x, y) {
            return [x, y];
        }
        f(1);
    """)
    assert result == [1, None]
Example #3
0
def test_invalid_call_native_function():
    inter = duktape.Interpreter()
    inter.set('f', lambda x, y: [x, y])

    with pytest.raises(duktape.EvalError):
        inter.eval('f(1)')
Example #4
0
def test_call_function():
    inter = duktape.Interpreter()
    inter.set('f', lambda x, y: [x, y])

    assert inter.eval('f(1, 2)') == [1, 2]
Example #5
0
def test_set_function():
    inter = duktape.Interpreter()
    inter.set('f', lambda x: x)
    f = inter.get('f')
    assert f(123) == 123
Example #6
0
def test_eval():
    inter = duktape.Interpreter()
    result = inter.eval("1 + 2")
    assert result == 1 + 2
Example #7
0
def test_invalid_get_value():
    inter = duktape.Interpreter()
    result = inter.get('xyz')
    assert result is None
Example #8
0
def test_invalid_set_value(val):
    inter = duktape.Interpreter()
    with pytest.raises(Exception):
        inter.set('val', val)
Example #9
0
def test_eval_without_result():
    inter = duktape.Interpreter()
    result = inter.eval("1 + 2", False)
    assert result is None