Ejemplo n.º 1
0
def test_repl():
    t = setup()
    t.daemon = True
    t.start()

    while not t.running:
        time.sleep(0.01)

    asyncio.set_event_loop(asyncio.new_event_loop())
    client = TSDBClient()
    r = repl.REPL(client)
    output = []

    def print_to_output(*args):
        output.append(' '.join(str(a) for a in args))

    r.print = print_to_output

    def reset():
        del output[:]

    # test do_hello
    r.onecmd('hello')
    assert output == ['Hello!']
    reset()

    # test do_insert with syntax error
    r.onecmd('insert abc @ [4,5,6] into pke')
    r.onecmd('dump')
    assert output == ['Error!']
    reset()

    # test do_insert
    r.onecmd('insert [1,2,3] @ [4, 5, 6] into tabby')
    r.onecmd('dump')
    assert [line.strip() for line in output] == \
           ['OK!', 'tabby', 'ts', 'times :  [4.0, 5.0, 6.0]', 'values :  [1.0, 2.0, 3.0]']
    reset()

    # test do_select
    r.onecmd('select ts')
    assert [line.strip() for line in output] == \
           ['tabby', 'ts', 'times :  [4.0, 5.0, 6.0]', 'values :  [1.0, 2.0, 3.0]']
    reset()

    r.onecmd('select from tabby')
    print([line.strip() for line in output])
    assert [line.strip() for line in output] == \
           ['tabby', 'label :  null', 'order :  -1', 'pk :  tabby']
    reset()

    r.onecmd('select ts, pk')
    assert [line.strip() for line in output] == \
           ['tabby', 'pk :  tabby', 'ts', 'times :  [4.0, 5.0, 6.0]', 'values :  [1.0, 2.0, 3.0]']
    reset()

    r.onecmd('select limit 1')
    assert output == ['Error!']
    reset()

    r.onecmd('select ts limit 1')
    assert [line.strip() for line in output] == \
           ['tabby', 'ts', 'times :  [4.0, 5.0, 6.0]', 'values :  [1.0, 2.0, 3.0]']
    reset()

    r.onecmd('select stats() as mean, std')
    assert [line.strip() for line in output] == \
           ['tabby', 'mean :  2.0', 'std :  0.816496580927726']
    reset()

    r.onecmd('insert [8, 9, 10] @ [11.0, 12.0, 13.0] into calico')
    r.onecmd('select ts order by pk')
    assert [line.strip() for line in output] == \
           ['OK!', 'calico', 'ts', 'times :  [11.0, 12.0, 13.0]', 'values :  [8.0, 9.0, 10.0]', 'tabby', 'ts',
            'times :  [4.0, 5.0, 6.0]', 'values :  [1.0, 2.0, 3.0]']
    reset()

    r.onecmd('select ts order by pk desc')
    assert [line.strip() for line in output] == \
           ['tabby', 'ts', 'times :  [4.0, 5.0, 6.0]', 'values :  [1.0, 2.0, 3.0]', 'calico', 'ts',
            'times :  [11.0, 12.0, 13.0]', 'values :  [8.0, 9.0, 10.0]']
    reset()

    r.onecmd('upsert calico {"label": "cute"}')
    r.onecmd('select label from calico')
    assert [line.strip()
            for line in output] == ['OK!', 'calico', 'label :  cute']
    reset()
Ejemplo n.º 2
0
#!/usr/bin/env python3

from repl import repl

if __name__ == "__main__":
    repl.REPL(application_name="Rule 110",
              modules_enabled=["readline", "math", "text"],
              dotfile_prefix="rule110",
              debug=True).go()
Ejemplo n.º 3
0
        def visit(*args):
            try:
                html.get_webpage(url)
            except WebOpenFailed as e:
                print("Failed to retrieve webpage: {}".format(url))
                return 1
            else: html.extract_links()
            return 0

        return Command(
            visit,
            "no-op",
            "no-op",
            "no-op",
        )

    R = repl.REPL(application_name = "Links",
            modules_enabled = ["readline"])

    R.register(GetWebpageCommand)
    R.register(ExtractLinksCommand)
    R.register(LinkTextCommand)
    R.register(LinkDestinationCommand)

    R.set_unknown_command(bare_url_command)
    R.set_prompt(lambda _: "({}) >>> " .format(html.url) if html.url
            else "(Enter a URL) >>> ")

    R.go()

Ejemplo n.º 4
0
#!/usr/bin/env python3

import sys

from repl import repl
from repl.base import common

if __name__ == "__main__":
    r = repl.REPL(
        "bad-math",
        modules_enabled=["readline", "math", "text"],
    )

    r.go()
Ejemplo n.º 5
0
#!/usr/bin/env python3

from repl import repl

repl.REPL("test", modules_enabled = ["shell", "readline", "math", "debug",
    "text", "json"],
        debug = True).go()