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
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="")
def test_scope_exists(obj): assert run(obj) is None assert run(obj.lower()) is None
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
def test_user_agent(): assert run( f"assert http.get('http://httpbin.org/user-agent').json() == {{'user-agent': 'bitccl/{VERSION}'}}" ) is None
def test_http2_enabled(): assert run( "assert http.get('https://nghttp2.org/httpbin/status/200').http_version == 'HTTP/2'" ) is None
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
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
def test_builtin_functions(): for name in functions: assert run(f'assert "function" in str(type({name}))') is None
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
def test_disallowed_imports(func): assert "Imports disabled" in run(f"from functions import {func}")
def test_disable_imports(): assert "Imports disabled" in run("import pdb")
def test_plugin_exceptions(): with pytest.raises(ZeroDivisionError ): # plugins should handle their errors by themselves run("assert y", plugins=[DummyPluginWithException])
def test_plugin_shutdown(): assert run("assert obj.state", plugins=[DummyPluginWithShutdown()]) is None
def test_plugin_injection(): assert run("assert x == 5", plugins=[DummyPlugin()]) is None