Skip to content

Commit

Permalink
Fix tests for python2.7
Browse files Browse the repository at this point in the history
  • Loading branch information
galaunay committed Sep 27, 2020
1 parent 05712a3 commit b39b31a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
5 changes: 4 additions & 1 deletion elpy/jedibackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,10 @@ def rpc_get_definition_jedi16(self, filename, source, offset):
or locations[0].module_name == '__builtin__')
):
locations = run_with_debug(jedi, 'goto_assignments',
code=source, line=line,
source=source, line=line,
column=column,
path=filename,
encoding='utf-8',
environment=self.environment)
if not locations:
return None
Expand Down Expand Up @@ -334,6 +335,8 @@ def rpc_get_oneline_docstring(self, filename, source, offset):
if defi.name not in
["str", "int", "float", "bool", "tuple",
"list", "dict"]]
if len(definitions) == 0:
return None
definition = definitions[0]
# Get name
if definition.type in ['function', 'class']:
Expand Down
1 change: 1 addition & 0 deletions elpy/tests/test_jedibackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ def test_should_not_fail_if_module_path_is_none(self, Script):
]
script = Script.return_value
script.goto_definitions.return_value = locations
script.goto_assignments.return_value = locations

location = self.rpc("", "", 0)

Expand Down
20 changes: 7 additions & 13 deletions elpy/tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,20 @@ def setUp(self):


class BackendCallTestCase(ServerTestCase):
def assert_calls_backend(self, method, add_kwargs={}):
def assert_calls_backend(self, method, add_args=[], add_kwargs={}):
with mock.patch("elpy.server.get_source") as get_source:
with mock.patch.object(self.srv, "backend") as backend:
get_source.return_value = "transformed source"

getattr(self.srv, method)("filename", "source", "offset",
*add_args,
**add_kwargs)

get_source.assert_called_with("source")
getattr(backend, method).assert_called_with(
"filename", "transformed source", "offset",
*[add_kwargs[key] for key in add_kwargs.keys()]
*add_args,
**add_kwargs
)


Expand Down Expand Up @@ -218,7 +220,7 @@ def test_should_handle_no_backend(self):
class TestRPCGetRenameDiff(BackendCallTestCase):
def test_should_call_backend(self):
self.assert_calls_backend("rpc_get_rename_diff",
add_kwargs={'new_name': 'new_name'})
add_args=['new_name'])

def test_should_handle_no_backend(self):
self.srv.backend = None
Expand All @@ -229,11 +231,7 @@ def test_should_handle_no_backend(self):
class TestRPCGetExtract_VariableDiff(BackendCallTestCase):
def test_should_call_backend(self):
self.assert_calls_backend("rpc_get_extract_variable_diff",
add_kwargs={'new_name': 'name',
'line_beg': 12,
'line_end': 13,
'col_beg': 3,
'col_end': 5})
add_args=['name', 12, 13, 3, 5])

def test_should_handle_no_backend(self):
self.srv.backend = None
Expand All @@ -244,11 +242,7 @@ def test_should_handle_no_backend(self):
class TestRPCGetExtract_FunctionDiff(BackendCallTestCase):
def test_should_call_backend(self):
self.assert_calls_backend("rpc_get_extract_function_diff",
add_kwargs={'new_name': 'name',
'line_beg': 12,
'line_end': 13,
'col_beg': 3,
'col_end': 5})
add_args=['name', 12, 13, 3, 5])


def test_should_handle_no_backend(self):
Expand Down

0 comments on commit b39b31a

Please sign in to comment.