Esempio n. 1
0
 def do_test_setup_ws(self):
     launcher = ensime_launcher.EnsimeLauncher(TestVim())
     from ensime import EnsimeClient, Ensime
     client = EnsimeClient(TestVim(), launcher, "spec/conf")
     client.setup()
     def false_method(what):
         return False
     client.module_exists = false_method
     client.setup()
     ensime = Ensime(TestVim())
     assert(ensime.client_status("spec/conf") == "ready")
Esempio n. 2
0
    def test_ensime_client(self):
        self.test_ensime_launcher()
        from ensime import EnsimeClient
        launcher = ensime_launcher.EnsimeLauncher(TestVim())
        client = EnsimeClient(TestVim(), launcher, "spec/conf")
        assert(not client.module_exists("unexisting_module"))
        assert(client.module_exists("os"))
        client.teardown("/tmp/")
        assert(client.path_start_size("/tmp") is None)
        assert(client.unqueue("/tmp") is None)
        client.queue.put(None)
        assert(client.unqueue("/tmp") is None)
        client.queue.put('{"payload":{"typehint":"blah"}}')
        assert(client.unqueue("/tmp") is None)
        client.setup()
        assert(client.complete() is None)
        notes = [{"line": 0, "col": 0, "beg": 0,
                  "end": 1, "msg": "msg", "file": "file"}]
        client.handle_new_scala_notes_event(notes)
        ensime_launcher.Util.write_file("/tmp/http", "42")
        for typehint in ["NewScalaNotesEvent",
                         "SymbolInfo",
                         "IndexerReadyEvent",
                         "AnalyzerReadyEvent",
                         "BasicTypeInfo",
                         "StringResponse",
                         "CompletionInfoList"]:
            client.handle_payload({
                "typehint": typehint,
                "notes": notes,
                "declPos": {"file": "none"},
                "fullName": "none",
                "text": "none",
                "completions": []})
        client.open_definition = True
        client.handle_payload({
            "typehint": "SymbolInfo",
            "notes": notes,
            "declPos": {"file": "none"},
            "fullName": "none",
            "text": "none",
            "completions": []})
        assert(client.ensime.http_port() == 42)

        class FakeSocket:

            def __init__(self):
                self.first = True

            def recv(self, n):
                if self.first:
                    self.first = False
                    return 'n'
                else:
                    return ''

        client.read_line(FakeSocket())
        assert(client.complete_func('1', "") == 0)
        client.vim.current.window.cursor[1] = 2
        assert(client.complete_func('1', "") == 1)
        client.vim.current.window.cursor[1] = 0
        client.suggests = ["a"]
        assert(client.complete_func(0, "") == ['a'])
        client.suggests = None
        client.complete_timeout = 0.1
        print(client.complete_func(0, ""))
        client.handle_string_response({"text": "lol"})
        client.browse = True
        old_get = os.environ.get

        def new_get(blah):
            return "echo"
        os.environ.get = new_get
        client.handle_string_response({"text": "lol"})
        os.environ.get = old_get
        assert(client.type_check("/tmp") is None)
        assert(client.on_cursor_hold("/tmp") is None)
        assert(client.cursor_moved("/tmp") is None)
        assert(client.get_error_at([0, 0]) is None)
        from ensime import Error
        error = Error("/tmp", "a", 0, 0, 10)
        client.errors.append(error)
        assert(client.get_error_at([0, 0]) == error)
        assert(client.display_error_if_necessary("/tmp") is None)
        client.tell_module_missing("module")
        assert(client.doc_browse(None) is None)
        assert(client.type_check_cmd([]) is None)
        assert(client.type([]) is None)
        assert(client.symbol_at_point_req(None) is None)
        assert(client.symbol(None) is None)
        assert(client.open_declaration(None) is None)
        assert(client.do_no_teardown(None) is None)
        client.ws = True
        assert(client.cursor_moved("") is None)

        class FakeWS:

            def recv(self):
                return ""

            def send(self, blah):
                None
        client.ws = FakeWS()
        client.x = 0

        def once():
            client.x = client.x + 1
            return client.x <= 1
        assert(client.unqueue_poll(once, 0) is None)
        assert(client.send("blah") is None)