示例#1
0
文件: app.py 项目: jayvdb/sls
def test_complete_with_line_column(hub):
    """
    Tests that an SLS App can perform completion.
    """
    app = App()
    result = app.complete('.uri.', 'foobar\nhttp foo', line=1, column=1)
    del result[0]['documentation']
    del result[0]['detail']
    result = [{
        'label': 'http',
        'kind': 3,
        'textEdit': {
            'range': {
                'start': {
                    'line': 0,
                    'character': 0
                },
                'end': {
                    'line': 0,
                    'character': 1
                },
            },
            'newText': 'http '
        }
    }]
示例#2
0
def test_click(hub):
    """
    Tests that an SLS App can perform click.
    """
    app = App(hub=hub)
    result = app.click(".uri.", "app")
    assert result == {"detail": "Symbol. Object", "kind": 6, "label": "app"}
示例#3
0
def run_test_completion(uri, source, expected, patch, options):
    action = options.pop("action", "complete")
    if action == "complete":
        result = App(hub=hub).complete(uri=uri, text=source, **options)
    else:
        assert action == "click"
        result = App(hub=hub).click(uri=uri, text=source, **options)
    assert result == expected
示例#4
0
def test_stdio(patch):
    """
    Tests whether starting a stdio server works.
    """
    patch.init(Workspace)
    patch.init(LanguageServer)
    patch.object(ConstServiceHub, 'from_json', return_value='ConstServiceHub')
    patch.object(LanguageServer, 'start')
    app = App(hub_path='.hub.')
    app.start_stdio_server()
    LanguageServer.__init__.assert_called_with(sys.stdin.buffer,
                                               sys.stdout.buffer,
                                               hub='ConstServiceHub')
    LanguageServer.start.assert_called()
示例#5
0
def test_stdio(patch):
    """
    Tests whether starting a stdio server works.
    """
    patch.init(Workspace)
    patch.init(LanguageServer)
    patch.object(ServiceWrapper,
                 "from_json_file",
                 return_value="ConstServiceHub")
    patch.object(LanguageServer, "start")
    app = App(hub_path=".hub.")
    app.start_stdio_server()
    LanguageServer.__init__.assert_called_with(hub="ConstServiceHub")
    LanguageServer.start.assert_called_with(sys.stdin.buffer,
                                            sys.stdout.buffer)
示例#6
0
def test_tcp(patch, magic, keyboard_abort):
    """
    Tests whether starting a tcp server works.
    """
    server = magic()
    if keyboard_abort:
        server.serve_forever.side_effect = KeyboardInterrupt()
    did_exit = False

    class FakeServer:
        def __init__(self, arg_port, cls):
            assert arg_port == (".addr.", ".port.")
            self.cls = cls

        def __enter__(self):
            LanguageServer.start.assert_not_called()
            tcp_server = self.cls()
            tcp_server.rfile = "rfile"
            tcp_server.wfile = "wfile"
            tcp_server.handle()
            return server

        def __exit__(self, a, b, c):
            nonlocal did_exit
            did_exit = True

    patch.init(Workspace)
    patch.object(ServiceWrapper,
                 "from_json_file",
                 return_value="ConstServiceHub")

    patch.init(LanguageServer)
    patch.object(LanguageServer, "start")

    patch("socketserver.TCPServer", FakeServer)
    patch.init(StreamRequestHandler)

    app = App(hub_path=".hub.")
    app.start_tcp_server(addr=".addr.", port=".port.")
    assert FakeServer.allow_reuse_address

    server.serve_forever.assert_called()
    server.server_close.assert_called()
    LanguageServer.__init__.assert_called_with(hub="ConstServiceHub")
    LanguageServer.start.assert_called_with("rfile", "wfile")
    assert did_exit
示例#7
0
def test_tcp(patch, magic, keyboard_abort):
    """
    Tests whether starting a tcp server works.
    """
    server = magic()
    if keyboard_abort:
        server.serve_forever.side_effect = KeyboardInterrupt()
    did_exit = False

    class FakeServer:
        def __init__(self, arg_port, cls):
            assert arg_port == ('.addr.', '.port.')
            self.cls = cls

        def __enter__(self):
            LanguageServer.start.assert_not_called()
            tcp_server = self.cls()
            tcp_server.rfile = 'rfile'
            tcp_server.wfile = 'wfile'
            tcp_server.handle()
            return server

        def __exit__(self, a, b, c):
            nonlocal did_exit
            did_exit = True

    patch.init(Workspace)
    patch.object(ConstServiceHub, 'from_json', return_value='ConstServiceHub')

    patch.init(LanguageServer)
    patch.object(LanguageServer, 'start')

    patch('socketserver.TCPServer', FakeServer)
    patch.init(StreamRequestHandler)

    app = App(hub_path='.hub.')
    app.start_tcp_server(addr='.addr.', port='.port.')
    assert FakeServer.allow_reuse_address

    server.serve_forever.assert_called()
    server.server_close.assert_called()
    LanguageServer.__init__.assert_called_with('rfile',
                                               'wfile',
                                               hub='ConstServiceHub')
    LanguageServer.start.assert_called()
    assert did_exit
示例#8
0
def test_init_hub_path(patch):
    """
    Tests that an SLS App with a Hub Path gets properly initialized.
    """
    patch.object(ServiceWrapper, "from_json_file")
    hub_path = ".hub.path."
    app = App(hub_path=hub_path)
    ServiceWrapper.from_json_file.assert_called_with(hub_path)
    assert app.hub is ServiceWrapper.from_json_file()
示例#9
0
def test_init(patch):
    """
    Tests that an SLS App gets properly initialized.
    """
    patch.init(Workspace)
    app = App()
    Workspace.__init__.assert_called_with('.root.', hub=None)
    assert app.hub is None
    assert isinstance(app.ws, Workspace)
示例#10
0
文件: app.py 项目: jayvdb/sls
def test_init_hub_path(patch):
    """
    Tests that an SLS App with a Hub Path gets properly initialized.
    """
    patch.object(ConstServiceHub, 'from_json')
    hub_path = '.hub.path.'
    app = App(hub_path=hub_path)
    ConstServiceHub.from_json.assert_called_with(hub_path)
    assert app.hub is ConstServiceHub.from_json()
示例#11
0
def ws(patch, magic):
    patch.init(Workspace)
    patch.object(ServiceWrapper,
                 "from_json_file",
                 return_value="ConstServiceHub")

    app = App(hub_path=".hub.")
    ws = sls_websocket(app)
    patch.init(ws)
    patch.object(ws, "write_message")
    return ws()
示例#12
0
def test_websocket(patch, magic):
    """
    Tests whether starting a tcp server works.
    """
    patch.init(Workspace)
    patch.object(ServiceWrapper,
                 "from_json_file",
                 return_value="ConstServiceHub")

    patch.init(LanguageServer)
    patch.object(LanguageServer, "start")

    patch.object(SLSApplication, "listen")
    patch.object(tornado.ioloop.IOLoop, "current")

    app = App(hub_path=".hub.")
    app.start_websocket_server(addr=".addr.", port=".port.")

    SLSApplication.listen.assert_called_with(".port.")
    tornado.ioloop.IOLoop.current().start.assert_called()
示例#13
0
def test_init_hub_path(patch):
    """
    Tests that an SLS App with a Hub Path gets properly initialized.
    """
    patch.init(Workspace)
    patch.object(ConstServiceHub, 'from_json', return_value='ConstServiceHub')
    hub_path = '.hub.path.'
    app = App(hub_path=hub_path)
    ConstServiceHub.from_json.assert_called_with(hub_path)
    Workspace.__init__.assert_called_with('.root.',
                                          hub=ConstServiceHub.from_json())
    assert isinstance(app.ws, Workspace)
    assert app.hub == 'ConstServiceHub'
示例#14
0
def test_complete_with_line_column(hub):
    """
    Tests that an SLS App can perform completion.
    """
    app = App(hub=hub)
    result = app.complete(".uri.", "foobar\nhttp foo", line=1, column=1)
    del result[0]["documentation"]
    del result[0]["detail"]
    assert result == [
        {
            "insertTextFormat": 1,
            "label": "http",
            "kind": 2,
            "sortText": "40-http",
            "textEdit": {
                "range": {
                    "start": {"line": 1, "character": 0},
                    "end": {"line": 1, "character": 1},
                },
                "newText": "http",
            },
        }
    ]
示例#15
0
def test_cli_click_line_column(patch, runner, echo, app, options, expected):
    """
    Ensures CLI click with custom line and column works.
    """
    with runner.isolated_filesystem():
        patch.object(json, "dumps")
        text = "foobar"
        with open("my.story", "w") as f:
            f.write(text)
        e = runner.invoke(Cli.main, ["click", "my.story", *options])
        app.click.assert_called_with("|click|", text, **expected)
        json.dumps.assert_called_with(App.click(), indent=2, sort_keys=True)
        click.echo.assert_called_with(json.dumps())
        assert e.exit_code == 0
示例#16
0
文件: cli.py 项目: jayvdb/sls
def test_cli_complete_line_column(patch, runner, echo, app, options, expected):
    """
    Ensures CLI completion with custom line and column works.
    """
    patch.object(json, 'dumps')
    with runner.isolated_filesystem():
        text = 'foobar'
        with open('my.story', 'w') as f:
            f.write(text)
        e = runner.invoke(Cli.main, ['complete', 'my.story', *options])
        App.complete.assert_called_with('|completion|', text, **expected)
        json.dumps.assert_called_with(App.complete(), indent=2, sort_keys=True)
        click.echo.assert_called_with(json.dumps())
        assert e.exit_code == 0
示例#17
0
def test_init_hub_path(patch):
    """
    Tests that an SLS App with a Hub Path gets properly initialized.
    """
    patch.init(Workspace)
    patch.object(ServiceWrapper,
                 "from_json_file",
                 return_value="ConstServiceHub")
    hub_path = ".hub.path."
    app = App(hub_path=hub_path)
    ServiceWrapper.from_json_file.assert_called_with(hub_path)
    Workspace.__init__.assert_called_with(".root.",
                                          hub=ServiceWrapper.from_json_file())
    assert isinstance(app.ws, Workspace)
    assert app.hub == "ConstServiceHub"
示例#18
0
文件: cli.py 项目: jayvdb/sls
def test_cli_complete_hub(patch, runner, echo, app):
    """
    Ensures CLI completion with a custom hub works.
    """
    patch.object(json, 'dumps')
    with runner.isolated_filesystem():
        text = 'foobar'
        with open('my.story', 'w') as f:
            f.write(text)
        with open('my.hub', 'w') as f:
            f.write('Hello World!')
        e = runner.invoke(Cli.main, ['--hub=my.hub', 'complete', 'my.story'])
        App.__init__.assert_called_with(hub_path='my.hub')
        App.complete.assert_called_with('|completion|',
                                        text,
                                        line=None,
                                        column=None)
        json.dumps.assert_called_with(App.complete(), indent=2, sort_keys=True)
        click.echo.assert_called_with(json.dumps())
        assert e.exit_code == 0
示例#19
0
def test_cli_complete_hub(patch, runner, echo, app):
    """
    Ensures CLI completion with a custom hub works.
    """
    with runner.isolated_filesystem():
        patch.object(json, "dumps")
        text = "foobar"
        with open("my.story", "w") as f:
            f.write(text)
        with open("my.hub", "w") as f:
            f.write("Hello World!")
        e = runner.invoke(Cli.main, ["--hub=my.hub", "complete", "my.story"])
        app.__init__.assert_called_with(hub_path="my.hub")
        app.complete.assert_called_with("|completion|",
                                        text,
                                        line=None,
                                        column=None)
        json.dumps.assert_called_with(App.complete(), indent=2, sort_keys=True)
        click.echo.assert_called_with(json.dumps())
        assert e.exit_code == 0
示例#20
0
def test_init(hub):
    """
    Tests that an SLS App gets properly initialized.
    """
    app = App()
    assert app.hub is None
示例#21
0
def run_test_completion(uri, source, expected, patch):
    assert App(hub=hub).complete(uri=uri, text=source) == expected