Ejemplo n.º 1
0
def test_status_codes():
    assert run("assert http_codes.OK == 200") is None
    assert run("assert http_codes.FOUND == 302") is None
    assert run("assert http_codes.BAD_REQUEST == 400") is None
    assert run("assert http_codes.NOT_FOUND == 404") is None
    assert run("assert http_codes.TOO_MANY_REQUESTS == 429") is None
    assert run("assert http_codes.INTERNAL_SERVER_ERROR == 500") is None
Ejemplo n.º 2
0
def main():
    if len(sys.argv) != 2:
        sys.exit(f"Usage: {sys.argv[0]} file.bccl")

    filename = sys.argv[1]
    if not os.path.exists(filename):
        sys.exit(f"File {filename} does not exist")
    try:
        with open(filename) as f:
            source = f.read()
    except OSError:
        sys.exit("Error reading input file")

    error_message = run(source, filename)
    if error_message:
        print(error_message, end="")
Ejemplo n.º 3
0
def test_scope_exists(obj):
    assert run(obj) is None
    assert run(obj.lower()) is None
Ejemplo n.º 4
0
def test_anonymous_coins(obj):
    with pytest.warns(UserWarning):
        assert run(f"assert {obj.lower()}.xpub == {obj}().xpub"
                   ) is None  # ensure lowercase coin names have no xpub set
Ejemplo n.º 5
0
def test_user_agent():
    assert run(
        f"assert http.get('http://httpbin.org/user-agent').json() == {{'user-agent': 'bitccl/{VERSION}'}}"
    ) is None
Ejemplo n.º 6
0
def test_http2_enabled():
    assert run(
        "assert http.get('https://nghttp2.org/httpbin/status/200').http_version == 'HTTP/2'"
    ) is None
Ejemplo n.º 7
0
def test_run():
    assert run("a = 2+2") is None  # no output if no errors
    error_message = run("a = 2 / 0")
    assert error_message
    assert "ZeroDivisionError" in error_message
    import os  # noqa # imports working after run function finalization
Ejemplo n.º 8
0
def test_empty_event_listeners():
    event_listeners.clear()
    assert not event_listeners
    assert run("add_event_listener('test', lambda:None)") is None  # no errors
    assert not event_listeners  # cleanup after run
Ejemplo n.º 9
0
def test_builtin_functions():
    for name in functions:
        assert run(f'assert "function" in str(type({name}))') is None
Ejemplo n.º 10
0
def test_builtin_events():
    for name in events:
        assert run(f'assert "class" in str({name})') is None
        assert run(f"assert issubclass({name}, BaseEvent)") is None
Ejemplo n.º 11
0
def test_disallowed_imports(func):
    assert "Imports disabled" in run(f"from functions import {func}")
Ejemplo n.º 12
0
def test_disable_imports():
    assert "Imports disabled" in run("import pdb")
Ejemplo n.º 13
0
def test_plugin_exceptions():
    with pytest.raises(ZeroDivisionError
                       ):  # plugins should handle their errors by themselves
        run("assert y", plugins=[DummyPluginWithException])
Ejemplo n.º 14
0
def test_plugin_shutdown():
    assert run("assert obj.state", plugins=[DummyPluginWithShutdown()]) is None
Ejemplo n.º 15
0
def test_plugin_injection():
    assert run("assert x == 5", plugins=[DummyPlugin()]) is None