Пример #1
0
def test_identifier_await_propagates_promise_rejection_as_exception(
        node_server):
    with raises(NodeError) as excinfo:
        node_server("p = () => { return Promise.reject(new Error('hello')); }")
        node_server(GlobalAwait(Identifier("p")()))
    assert excinfo.value.message == "hello"
    assert excinfo.value.stack
    with raises(NodeError) as excinfo:
        node_server("async_func = async () => { throw new Error('hello'); };")
        node_server(GlobalAwait(Identifier("async_func")()))
        node_server("throw new Error('hello')", timeout=5)
    assert excinfo.value.message == "hello"
    assert excinfo.value.stack
Пример #2
0
def test_calling_function_with_dict_with_node(node_server):
    node_server("id = (x) => (x);")
    assert node_server("return {}".format(
        Identifier("id")({
            "hello": 1,
            "world": 2
        }))) == {
            "hello": 1,
            "world": 2
        }
Пример #3
0
def test_identifier_property_call_with_0_args():
    assert str(Identifier("g").prop()) == """g.prop()"""
Пример #4
0
def test_identifier_property():
    assert str(Identifier("g").prop) == """g.prop"""
Пример #5
0
def test_identifier_call_1_arg_with_object():
    assert str(Identifier("g")(Identifier("other"),
                               123)) == """g(other, 123)"""
Пример #6
0
def test_identifier_call_2_args_with_string_and_int():
    assert str(Identifier("g")("string", 123)) == """g("string", 123)"""
Пример #7
0
def test_identifier_call_1_arg_with_string():
    assert str(Identifier("g")("string")) == """g("string")"""
Пример #8
0
def test_identifier_call_0_args():
    assert str(Identifier("g")()) == "g()"
Пример #9
0
def test_property_is_a_global_property(node_server):
    node_server("property = 4")
    assert node_server("return {}".format(Identifier("global").property)) == 4
Пример #10
0
def test_identifier_await_is_able_to_set_result(node_server):
    node_server("async_func = async (x) => { global.x = x };")
    node_server(GlobalAwait(Identifier("async_func")(1)))
    assert node_server("return global.x") == 1
Пример #11
0
def test_require_function_is_available(node_server):
    node_server("{} = {}".format(Identifier("readline"),
                                 Call(args=["readline"], parent="require")))
    assert node_server("return readline") is not None
Пример #12
0
def test_access_property_of_result_of_function(node_server):
    node_server("id = (x) => (x);")
    assert node_server("return {}".format(
        Identifier("id")({
            "hello": 1
        }).hello)) == 1
Пример #13
0
def test_calling_function_with_list_with_node(node_server):
    node_server("id = (x) => (x);")
    assert node_server("return {}".format(
        Identifier("id")(["hello", 1, "world",
                          2]))) == ["hello", 1, "world", 2]
Пример #14
0
def test_function_works_with_node(node_server):
    node_server("add = (x, y) => (x+y);")
    assert node_server("return {}".format(Identifier("add")(3, 4))) == 7
Пример #15
0
def test_identifier_property_property():
    assert str(Identifier("g").prop.prop_child) == """g.prop.prop_child"""
Пример #16
0
def test_identifier():
    assert str(Identifier("g")) == "g"
Пример #17
0
def test_await():
    assert (
        str(GlobalAwait(Identifier("g").some_method("hello", 1337))) ==
        """return (async ()=> { return await g.some_method("hello", 1337); })()"""
    )
Пример #18
0
def test_property_works_with_node(node_server):
    node_server("property = 4")
    assert node_server("return {}".format(Identifier("property"))) == 4