def test_should_not_fail_for_module_syntax_errors(self):
        source, offset = source_and_offset(
            "class Foo(object):\n"
            "  def bar(self):\n"
            "    foo(_|_"
            "    bar("
            "\n"
            "  def a(self):\n"
            "    pass\n"
            "\n"
            "  def b(self):\n"
            "  pass\n"
            "\n"
            "  def b(self):\n"
            "  pass\n"
            "\n"
            "  def b(self):\n"
            "  pass\n"
            "\n"
            "  def b(self):\n"
            "  pass\n"
            "\n"
            "  def b(self):\n"
            "  pass\n"
        )

        filename = self.project_file("test.py", source)
        self.assertEquals([], self.backend.rpc_get_completions(self.project_root, filename, source, offset))
Beispiel #2
0
    def test_should_fail_for_module_syntax_errors(self):
        source, offset = source_and_offset(
            "class Foo(object):\n"
            "  def bar(self):\n"
            "    foo(_|_"
            "    bar("
            "\n"
            "  def a(self):\n"
            "    pass\n"
            "\n"
            "  def b(self):\n"
            "  pass\n"
            "\n"
            "  def b(self):\n"
            "  pass\n"
            "\n"
            "  def b(self):\n"
            "  pass\n"
            "\n"
            "  def b(self):\n"
            "  pass\n"
            "\n"
            "  def b(self):\n"
            "  pass\n"
        )

        filename = self.project_file("test.py", source)
        message = re.escape("Too many syntax errors in file test.py "
                            "(lines 4, 8, 11, 14, 17, 20)")
        self.assertRaisesRegexp(rpc.Fault, message,
                                self.backend.rpc_get_completions,
                                self.project_root, filename, source,
                                offset)
 def test_should_return_calltip(self):
     filename = self.project_file("test.py", "")
     source, offset = source_and_offset("import threading\n"
                                        "threading.Thread(_|_")
     calltip = self.backend.rpc_get_calltip(self.project_root, filename,
                                            source, offset)
     if compat.PYTHON3:
         self.assertEqual(
             calltip, {
                 "name":
                 "Thread",
                 "params": [
                     "group = None", "target = None", "name = None",
                     "args = ()", "kwargs = None", "daemon = None"
                 ],
                 "index":
                 0
             })
     else:
         self.assertEqual(
             calltip, {
                 "name":
                 "Thread",
                 "params": [
                     "group = None", "target = None", "name = None",
                     "args = ()", "kwargs = None", "verbose = None"
                 ],
                 "index":
                 0
             })
Beispiel #4
0
 def test_should_complete_simple_calls(self):
     source, offset = source_and_offset("o_|_")
     self.assertEqual(
         sorted([
             name for (name, doc) in self.backend.rpc_get_completions(
                 None, None, source, offset)
         ]), sorted(["bject", "ct", "pen", "r", "rd"]))
Beispiel #5
0
    def test_should_fail_for_module_syntax_errors(self):
        source, offset = source_and_offset(
            "class Foo(object):\n"
            "  def bar(self):\n"
            "    foo(_|_"
            "    bar("
            "\n"
            "  def a(self):\n"
            "    pass\n"
            "\n"
            "  def b(self):\n"
            "  pass\n"
            "\n"
            "  def b(self):\n"
            "  pass\n"
            "\n"
            "  def b(self):\n"
            "  pass\n"
            "\n"
            "  def b(self):\n"
            "  pass\n"
            "\n"
            "  def b(self):\n"
            "  pass\n"
        )

        filename = self.project_file("test.py", source)
        message = re.escape("Too many syntax errors in file test.py "
                            "(lines 4, 8, 11, 14, 17, 20)")
        self.assertRaisesRegexp(rpc.Fault, message,
                                self.backend.rpc_get_completions,
                                self.project_root, filename, source,
                                offset)
Beispiel #6
0
 def test_should_return_none_outside_of_all(self):
     filename = self.project_file("test.py", "")
     source, offset = source_and_offset("import thr_|_eading\n")
     calltip = self.backend.rpc_get_calltip(self.project_root,
                                            filename,
                                            source, offset)
     self.assertIsNone(calltip)
 def test_should_find_completion_different_package(self):
     # See issue #74
     self.project_file("project/__init__.py", "")
     source1 = "class Add:\n" "    def add(self, a, b):\n" "        return a + b\n"
     self.project_file("project/add.py", source1)
     source2, offset = source_and_offset(
         "from project.add import Add\n"
         "class Calculator:\n"
         "    def add(self, a, b):\n"
         "        c = Add()\n"
         "        c.ad_|_\n"
     )
     file2 = self.project_file("project/calculator.py", source2)
     proposals = self.backend.rpc_get_completions(self.project_root, file2, source2, offset)
     self.assertEqual(
         proposals,
         [
             {
                 "suffix": "d",
                 "docstring": "add(self, a, b)\n\n",
                 "annotation": "function",
                 "meta": "function: add.Add.add",
             }
         ],
     )
Beispiel #8
0
 def test_should_complete_builtin(self):
     source, offset = source_and_offset("o_|_")
     self.assertEqual(sorted([name for (name, doc) in
                              self.backend.rpc_get_completions(
                                  None, "test.py", source, offset)]),
                      sorted(['SError', 'bject', 'ct', 'pen', 'r',
                              'rd', 'verflowError']))
Beispiel #9
0
    def test_should_return_none_for_module_syntax_errors(self):
        source, offset = source_and_offset(
            "class Foo(object):\n"
            "  def bar(self):\n"
            "    foo(_|_"
            "    bar("
            "\n"
            "  def a(self):\n"
            "    pass\n"
            "\n"
            "  def b(self):\n"
            "  pass\n"
            "\n"
            "  def b(self):\n"
            "  pass\n"
            "\n"
            "  def b(self):\n"
            "  pass\n"
            "\n"
            "  def b(self):\n"
            "  pass\n"
            "\n"
            "  def b(self):\n"
            "  pass\n")

        filename = self.project_file("test.py", source)
        calltip = self.backend.rpc_get_calltip(self.project_root,
                                               filename,
                                               source,
                                               offset)
        self.assertIsNone(calltip)
Beispiel #10
0
 def test_should_complete_builtin(self):
     source, offset = source_and_offset("o_|_")
     self.assertEqual(sorted([name for (name, doc) in
                              self.backend.rpc_get_completions(
                                  None, "test.py", source, offset)]),
                      sorted(['SError', 'bject', 'ct', 'pen', 'r',
                              'rd', 'verflowError']))
Beispiel #11
0
 def test_should_return_none_outside_of_all(self):
     filename = self.project_file("test.py", "")
     source, offset = source_and_offset("import thr_|_eading\n")
     calltip = self.backend.rpc_get_calltip(self.project_root,
                                            filename,
                                            source, offset)
     self.assertIsNone(calltip)
 def test_should_return_location_in_different_file(self):
     source1 = "def test_function(a, b):\n" "    return a + b\n"
     file1 = self.project_file("test1.py", source1)
     source2, offset = source_and_offset("from test1 import test_function\n" "test_funct_|_ion(1, 2)\n")
     file2 = self.project_file("test2.py", source2)
     definition = self.backend.rpc_get_definition(self.project_root, file2, source2, offset)
     self.assertEqual(definition, (file1, 4))
    def test_should_return_none_for_module_syntax_errors(self):
        source, offset = source_and_offset(
            "class Foo(object):\n"
            "  def bar(self):\n"
            "    foo(_|_"
            "    bar("
            "\n"
            "  def a(self):\n"
            "    pass\n"
            "\n"
            "  def b(self):\n"
            "  pass\n"
            "\n"
            "  def b(self):\n"
            "  pass\n"
            "\n"
            "  def b(self):\n"
            "  pass\n"
            "\n"
            "  def b(self):\n"
            "  pass\n"
            "\n"
            "  def b(self):\n"
            "  pass\n"
        )

        filename = self.project_file("test.py", source)
        calltip = self.backend.rpc_get_calltip(self.project_root, filename, source, offset)
        self.assertIsNone(calltip)
Beispiel #14
0
 def test_should_get_docstring(self):
     source, offset = source_and_offset(
         "import threading\nthreading.Thread.join_|_(")
     filename = self.project_file("test.py", source)
     docstring = self.backend.rpc_get_docstring(self.project_root, filename,
                                                source, offset)
     self.assertEqual(docstring, 'Thread.join(self, timeout=None):\n\n')
Beispiel #15
0
 def test_should_find_symbol(self):
     source, offset = source_and_offset("threading.current_th_|_read")
     result = nativebackend.find_symbol_backward(source, offset)
     self.assertEqual(result[0], "current_th")
     self.assertEqual(source[result[1]:result[2]], "current_th")
     result = nativebackend.find_symbol(source, offset)
     self.assertEqual(result[0], "current_thread")
     self.assertEqual(source[result[1]:result[2]], "current_thread")
Beispiel #16
0
 def test_should_return_none_if_outside_of_symbol(self):
     source, offset = source_and_offset("test_function(_|_)\n")
     filename = self.project_file("test.py", source)
     definition = self.backend.rpc_get_definition(self.project_root,
                                                  filename,
                                                  source,
                                                  offset)
     self.assertIsNone(definition)
Beispiel #17
0
 def test_should_return_none_if_location_not_found(self):
     source, offset = source_and_offset("test_f_|_unction()\n")
     filename = self.project_file("test.py", source)
     definition = self.backend.rpc_get_definition(self.project_root,
                                                  filename,
                                                  source,
                                                  offset)
     self.assertIsNone(definition)
Beispiel #18
0
 def test_should_find_symbol(self):
     source, offset = source_and_offset("threading.current_th_|_read")
     result = nativebackend.find_symbol_backward(source, offset)
     self.assertEqual(result[0], "current_th")
     self.assertEqual(source[result[1] : result[2]], "current_th")
     result = nativebackend.find_symbol(source, offset)
     self.assertEqual(result[0], "current_thread")
     self.assertEqual(source[result[1] : result[2]], "current_thread")
Beispiel #19
0
 def test_should_not_complete_for_import(self):
     source, offset = source_and_offset("import foo.Conf_|_")
     filename = self.project_file("test.py", source)
     completions = self.backend.rpc_get_completions(self.project_root,
                                                    filename, source,
                                                    offset)
     self.assertNotEqual(sorted(name for (name, doc) in completions),
                         sorted(["igParser"]))
Beispiel #20
0
 def test_should_return_none_if_outside_of_symbol(self):
     source, offset = source_and_offset("test_function(_|_)\n")
     filename = self.project_file("test.py", source)
     definition = self.backend.rpc_get_definition(self.project_root,
                                                  filename,
                                                  source,
                                                  offset)
     self.assertIsNone(definition)
 def test_should_remove_self_argument(self):
     source, offset = source_and_offset("d = dict()\n" "d.keys(_|_")
     filename = self.project_file("test.py", source)
     calltip = self.backend.rpc_get_calltip(self.project_root, filename, source, offset)
     if compat.PYTHON3:
         self.assertEqual(calltip, "builtins.keys()")
     else:
         self.assertEqual(calltip, "__builtin__.keys()")
 def test_should_not_fail_for_short_module(self):
     # This throws an error in Rope which elpy hopefully catches.
     # See #186
     source, offset = source_and_offset("from .. import foo_|_")
     filename = self.project_file("test.py", source)
     completions = self.backend.rpc_get_completions(self.project_root, filename, source, offset)
     # This is strictly speaking superfluous. Just avoid an error.
     self.assertIsNotNone(completions)
Beispiel #23
0
 def test_should_complete_packages_for_import(self):
     source, offset = source_and_offset("import threading.current_t_|_")
     filename = self.project_file("test.py", source)
     completions = self.backend.rpc_get_completions(self.project_root,
                                                    filename, source,
                                                    offset)
     self.assertEqual(sorted(name for (name, doc) in completions),
                      sorted(["hread"]))
Beispiel #24
0
 def test_should_complete_sys(self):
     source, offset = source_and_offset("import sys\nsys._|_")
     filename = self.project_file("test.py", source)
     completions = self.backend.rpc_get_completions(self.project_root,
                                                    filename,
                                                    source,
                                                    offset)
     self.assertIn('path', [symbol for (symbol, doc) in completions])
Beispiel #25
0
 def test_should_autoimport(self):
     source, offset = source_and_offset(
         "import threading\nthreading.T_|_mumble mumble")
     self.assertEqual(sorted([name for (name, doc) in
                              self.backend.rpc_get_completions(
                                  None, "test.py", source, offset)]),
                      sorted(['hread', 'hread',
                              'hreadError', 'imer']))
Beispiel #26
0
 def test_should_find_variable_definition(self):
     source, offset = source_and_offset("SOME_VALUE = 1\n"
                                        "\n"
                                        "variable = _|_SOME_VALUE\n")
     filename = self.project_file("test.py", source)
     self.assertEqual(
         self.backend.rpc_get_definition(self.project_root, filename,
                                         source, offset), (filename, 0))
Beispiel #27
0
 def test_should_return_none_if_location_not_found(self):
     source, offset = source_and_offset("test_f_|_unction()\n")
     filename = self.project_file("test.py", source)
     definition = self.backend.rpc_get_definition(self.project_root,
                                                  filename,
                                                  source,
                                                  offset)
     self.assertIsNone(definition)
Beispiel #28
0
 def test_should_return_definition_location_different_file(self):
     source1 = ("def test_function(a, b):\n" "    return a + b\n")
     file1 = self.project_file("test1.py", source1)
     source2, offset = source_and_offset("from test1 import test_function\n"
                                         "test_function_|_(1, 2)\n")
     file2 = self.project_file("test2.py", source2)
     location = self.backend.rpc_get_definition(self.project_root, file2,
                                                source2, offset)
     self.assertEqual(location, (file1, 0))
Beispiel #29
0
 def test_should_return_none_for_bad_identifier(self):
     source, offset = source_and_offset(
         "froblgoo(_|_")
     filename = self.project_file("test.py", source)
     calltip = self.backend.rpc_get_calltip(self.project_root,
                                            filename,
                                            source,
                                            offset)
     self.assertIsNone(calltip)
Beispiel #30
0
 def test_should_return_none_for_bad_identifier(self):
     source, offset = source_and_offset(
         "froblgoo_|_(\n")
     filename = self.project_file("test.py", source)
     docstring = self.backend.rpc_get_docstring(self.project_root,
                                                filename,
                                                source,
                                                offset)
     self.assertIsNone(docstring)
 def test_should_complete_top_level_modules_for_import(self):
     source, offset = source_and_offset("import multi_|_")
     filename = self.project_file("test.py", source)
     completions = self.backend.rpc_get_completions(self.project_root, filename, source, offset)
     if compat.PYTHON3:
         expected = ["processing"]
     else:
         expected = ["file", "processing"]
     self.assertEqual(sorted([cand["suffix"] for cand in completions]), sorted(expected))
Beispiel #32
0
 def test_should_return_none_for_bad_identifier(self):
     source, offset = source_and_offset(
         "froblgoo_|_(\n")
     filename = self.project_file("test.py", source)
     docstring = self.backend.rpc_get_docstring(self.project_root,
                                                filename,
                                                source,
                                                offset)
     self.assertIsNone(docstring)
Beispiel #33
0
 def test_should_return_none_if_file_does_not_exist(self):
     source, offset = source_and_offset("def foo():\n"
                                        "    pass\n"
                                        "\n"
                                        "fo_|_o()\n")
     self.assertIsNone(
         self.backend.rpc_get_definition(
             self.project_root, self.project_root + "/doesnotexist.py",
             source, offset))
 def test_should_get_calltip_at_closing_paren(self):
     source, offset = source_and_offset("import threading\nthreading.Thread(_|_)")
     filename = self.project_file("test.py", source)
     calltip = self.backend.rpc_get_calltip(self.project_root, filename, source, offset)
     if compat.PYTHON3:
         expected = "threading.Thread(group=None, target=None, " "name=None, args=(), kwargs=None, daemon=None, *)"
     else:
         expected = "threading.Thread(group=None, target=None, " "name=None, args=(), kwargs=None, verbose=None)"
     self.assertEqual(calltip, expected)
Beispiel #35
0
 def test_should_return_none_for_bad_identifier(self):
     source, offset = source_and_offset(
         "froblgoo(_|_")
     filename = self.project_file("test.py", source)
     calltip = self.backend.rpc_get_calltip(self.project_root,
                                            filename,
                                            source,
                                            offset)
     self.assertIsNone(calltip)
Beispiel #36
0
 def test_should_not_complete_for_import(self):
     source, offset = source_and_offset("import foo.Conf_|_")
     filename = self.project_file("test.py", source)
     completions = self.backend.rpc_get_completions(self.project_root,
                                                    filename,
                                                    source,
                                                    offset)
     self.assertNotEqual(sorted(name for (name, doc) in completions),
                         sorted(["igParser"]))
 def test_should_remove_package_prefix(self):
     source, offset = source_and_offset("import multiprocessing\n" "q = multiprocessing.Queue()\n" "q.qsize(_|_")
     filename = self.project_file("test.py", source)
     calltip = self.backend.rpc_get_calltip(self.project_root, filename, source, offset)
     if compat.PYTHON3 and calltip is None:
         # Bug in Rope in Python 3.4, apparently
         self.assertIsNone(calltip)
     else:
         self.assertEqual(calltip, "Queue.qsize()")
Beispiel #38
0
 def test_should_complete_top_level_modules_for_import(self):
     source, offset = source_and_offset("import multi_|_")
     filename = self.project_file("test.py", source)
     completions = self.backend.rpc_get_completions(self.project_root,
                                                    filename,
                                                    source,
                                                    offset)
     self.assertEqual(sorted(name for (name, doc) in completions),
                      sorted(["file", "processing"]))
Beispiel #39
0
 def test_should_complete_packages_for_import(self):
     source, offset = source_and_offset("import threading.current_t_|_")
     filename = self.project_file("test.py", source)
     completions = self.backend.rpc_get_completions(self.project_root,
                                                    filename,
                                                    source,
                                                    offset)
     self.assertEqual(sorted(name for (name, doc) in completions),
                      sorted(["hread"]))
Beispiel #40
0
 def test_should_not_fail_for_bad_indentation(self):
     source, offset = source_and_offset(
         "def foo():\n"
         "       print 23_|_\n"
         "      print 17\n")
     filename = self.project_file("test.py", source)
     self.assertEquals([],
                       self.backend.rpc_get_completions
                       (self.project_root, filename, source, offset))
    def test_should_get_docstring(self):
        source, offset = source_and_offset("import threading\nthreading.Thread.join_|_(")
        filename = self.project_file("test.py", source)
        docstring = self.backend.rpc_get_docstring(self.project_root, filename, source, offset)

        def first_line(s):
            return s[: s.index("\n")]

        self.assertEqual(first_line(docstring), "Thread.join(self, timeout=None):")
    def test_should_get_docstring(self):
        filename = self.project_file("test.py", "")
        source, offset = source_and_offset("import threading\nthreading.Thread.join_|_(")
        docstring = self.backend.rpc_get_docstring(self.project_root, filename, source, offset)

        import pydoc

        wanted = pydoc.render_doc("threading.Thread.join", "Elpy Pydoc Documentation for %s", False)
        self.assertEqual(docstring, wanted)
Beispiel #43
0
 def test_should_get_docstring(self):
     source, offset = source_and_offset(
         "import threading\nthreading.Thread.join_|_(")
     filename = self.project_file("test.py", source)
     docstring = self.backend.rpc_get_docstring(self.project_root,
                                                filename,
                                                source,
                                                offset)
     self.assertEqual(docstring,
                      'Thread.join(self, timeout=None):\n\n')
    def test_should_return_uses_in_other_file(self):
        file1 = self.project_file("file1.py", "")
        file2 = self.project_file("file2.py", "\n\n\n\n\nx = 5")
        source, offset = source_and_offset("import file2\n" "file2._|_x\n")

        usages = self.backend.rpc_get_usages(self.project_root, file1, source, offset)

        self.assertEqual(
            usages, [{"name": "x", "filename": file1, "offset": 19}, {"name": "x", "filename": file2, "offset": 5}]
        )
Beispiel #45
0
 def test_should_return_definition_location_same_file(self):
     source, offset = source_and_offset("import threading\n"
                                        "def test_function(a, b):\n"
                                        "    return a + b\n"
                                        "\n"
                                        "test_func_|_tion(\n")
     filename = self.project_file("test.py", source)
     self.assertEqual(
         self.backend.rpc_get_definition(self.project_root, filename,
                                         source, offset), (filename, 17))
Beispiel #46
0
 def test_should_return_calltip(self):
     filename = self.project_file("test.py", "")
     source, offset = source_and_offset("import threading\n"
                                        "threading.Thread(_|_")
     calltip = self.backend.rpc_get_calltip(self.project_root,
                                            filename,
                                            source, offset)
     self.assertEqual(calltip,
                      "Thread(group=None, target=None, name=None, "
                      "args=(), kwargs=None, verbose=None)")
Beispiel #47
0
 def test_should_find_variable_definition(self):
     source, offset = source_and_offset("SOME_VALUE = 1\n"
                                        "\n"
                                        "variable = _|_SOME_VALUE\n")
     filename = self.project_file("test.py", source)
     self.assertEqual(self.backend.rpc_get_definition(self.project_root,
                                                      filename,
                                                      source,
                                                      offset),
                      (filename, 0))
    def test_should_find_with_trailing_text(self):
        source, offset = source_and_offset("import threading\nthreading.T_|_mumble mumble")
        if compat.PYTHON3:
            expected = ["hread", "hreadError", "IMEOUT_MAX", "imer"]
        else:
            expected = ["hread", "hread", "hreadError", "imer"]

        got = [cand["suffix"] for cand in self.backend.rpc_get_completions(None, "test.py", source, offset)]

        self.assertEqual(sorted(got), sorted(expected))
Beispiel #49
0
    def test_should_get_docstring(self):
        filename = self.project_file("test.py", "")
        source, offset = source_and_offset(
            "import threading\nthreading.Thread.join_|_(")
        docstring = self.backend.rpc_get_docstring(self.project_root, filename,
                                                   source, offset)

        import pydoc
        wanted = pydoc.render_doc("threading.Thread.join",
                                  "Elpy Pydoc Documentation for %s", False)
        self.assertEqual(docstring, wanted)
Beispiel #50
0
 def test_should_return_completions(self):
     source, offset = source_and_offset("import multiprocessing\n"
                                        "multiprocessing.P_|_")
     filename = self.project_file("test.py", source)
     completions = self.backend.rpc_get_completions(self.project_root,
                                                    filename, source,
                                                    offset)
     self.assertEqual(sorted(name for (name, doc) in completions),
                      sorted(["ool", "rocess", "ipe", "rocessError"]))
     self.assertIn("Returns a process pool object",
                   dict(completions)['ool'])
Beispiel #51
0
 def test_should_find_with_trailing_text(self):
     source, offset = source_and_offset(
         "import threading\nthreading.T_|_mumble mumble")
     if compat.PYTHON3:
         expected = ["hread", "hreadError", "IMEOUT_MAX", "imer"]
     else:
         expected = ["hread", "hread", "hreadError", "imer"]
     self.assertEqual(sorted([name for (name, doc) in
                              self.backend.rpc_get_completions(
                                  None, "test.py", source, offset)]),
                      sorted(expected))
Beispiel #52
0
 def test_should_fail_for_bad_indentation(self):
     source, offset = source_and_offset(
         "def foo():\n"
         "       print 23_|_\n"
         "      print 17\n")
     filename = self.project_file("test.py", source)
     with self.assertRaises(rpc.Fault):
         self.backend.rpc_get_completions(self.project_root,
                                          filename,
                                          source,
                                          offset)
Beispiel #53
0
 def test_should_not_fail_for_short_module(self):
     # This throws an error in Rope which elpy hopefully catches.
     # See #186
     source, offset = source_and_offset("from .. import foo_|_")
     filename = self.project_file("test.py", source)
     completions = self.backend.rpc_get_completions(self.project_root,
                                                    filename,
                                                    source,
                                                    offset)
     # This is strictly speaking superfluous. Just avoid an error.
     self.assertIsNotNone(completions)
Beispiel #54
0
 def test_should_return_none_for_bad_indentation(self):
     source, offset = source_and_offset(
         "def foo():\n"
         "       _|_print 23\n"
         "      print 17\n")
     filename = self.project_file("test.py", source)
     calltip = self.backend.rpc_get_calltip(self.project_root,
                                            filename,
                                            source,
                                            offset)
     self.assertIsNone(calltip)
Beispiel #55
0
 def test_should_complete_top_level_modules_for_import(self):
     source, offset = source_and_offset("import multi_|_")
     filename = self.project_file("test.py", source)
     completions = self.backend.rpc_get_completions(self.project_root,
                                                    filename, source,
                                                    offset)
     if compat.PYTHON3:
         expected = ["processing"]
     else:
         expected = ["file", "processing"]
     self.assertEqual(sorted(name for (name, doc) in completions),
                      sorted(expected))
Beispiel #56
0
 def test_should_get_calltip_even_after_parens(self):
     source, offset = source_and_offset(
         "import threading\nthreading.Thread(foo()_|_")
     filename = self.project_file("test.py", source)
     calltip = self.backend.rpc_get_calltip(self.project_root, filename,
                                            source, offset)
     if compat.PYTHON3:
         expected = ("threading.Thread.__init__(group=None, target=None, "
                     "name=None, args=(), kwargs=None, daemon=None, *)")
     else:
         expected = ("threading.Thread.__init__(group=None, target=None, "
                     "name=None, args=(), kwargs=None, verbose=None)")
     self.assertEqual(calltip, expected)
Beispiel #57
0
    def test_should_get_docstring(self):
        source, offset = source_and_offset(
            "import threading\nthreading.Thread.join_|_(")
        filename = self.project_file("test.py", source)
        docstring = self.backend.rpc_get_docstring(self.project_root,
                                                   filename,
                                                   source,
                                                   offset)

        def first_line(s):
            return s[:s.index("\n")]

        self.assertEqual(first_line(docstring),
                         'Thread.join(self, timeout=None):')
Beispiel #58
0
 def test_should_return_calltip(self):
     filename = self.project_file("test.py", "")
     source, offset = source_and_offset("import threading\n"
                                        "threading.Thread(_|_")
     calltip = self.backend.rpc_get_calltip(self.project_root,
                                            filename,
                                            source, offset)
     if compat.PYTHON3:
         self.assertEqual(calltip,
                          "Thread(group=None, target=None, name=None, "
                          "args=(), kwargs=None, daemon=None)")
     else:
         self.assertEqual(calltip,
                          "Thread(group=None, target=None, name=None, "
                          "args=(), kwargs=None, verbose=None)")
Beispiel #59
0
 def test_should_find_completion_different_package(self):
     # See issue #74
     self.project_file("project/__init__.py", "")
     source1 = ("class Add:\n"
                "    def add(self, a, b):\n"
                "        return a + b\n")
     self.project_file("project/add.py", source1)
     source2, offset = source_and_offset("from project.add import Add\n"
                                         "class Calculator:\n"
                                         "    def add(self, a, b):\n"
                                         "        c = Add()\n"
                                         "        c.ad_|_\n")
     file2 = self.project_file("project/calculator.py", source2)
     proposals = self.backend.rpc_get_completions(self.project_root, file2,
                                                  source2, offset)
     self.assertEqual(proposals, [['d', 'add(self, a, b)\n\n']])
Beispiel #60
0
 def test_should_return_definition_location_different_package(self):
     # See issue #74
     self.project_file("project/__init__.py", "")
     source1 = ("class Add:\n"
                "    def add(self, a, b):\n"
                "        return a + b\n")
     file1 = self.project_file("project/add.py", source1)
     source2, offset = source_and_offset(
         "from project.add import Add\n"
         "class Calculator:\n"
         "    def add(self, a, b):\n"
         "        return Add_|_().add(a, b)\n")
     file2 = self.project_file("project/calculator.py", source2)
     location = self.backend.rpc_get_definition(self.project_root, file2,
                                                source2, offset)
     self.assertEqual(location, (file1, 0))