Skip to content

Commit

Permalink
Unit tests for jedi get_docstring.
Browse files Browse the repository at this point in the history
Also, do not fail if the code is malformed.
  • Loading branch information
jorgenschaefer committed Feb 5, 2015
1 parent 9db4d3b commit a6251df
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
7 changes: 5 additions & 2 deletions elpy/jedibackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,11 @@ def rpc_get_docstring(self, filename, source, offset):
path=filename, encoding='utf-8',
re_raise=jedi.NotFoundError)
except jedi.NotFoundError:
return ''
return locations[-1].docstring()
return None
if locations:
return locations[-1].docstring()
else:
return None

def rpc_get_definition(self, filename, source, offset):
line, column = pos_to_linecol(source, offset)
Expand Down
2 changes: 1 addition & 1 deletion elpy/tests/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ def first_line(s):
return s[:s.index("\n")]

self.assertEqual(first_line(docstring),
'Thread.join(self, timeout=None):')
self.THREAD_JOIN_DOCSTRING)

def test_should_return_none_for_bad_identifier(self):
source, offset = source_and_offset(
Expand Down
6 changes: 6 additions & 0 deletions elpy/tests/test_jedibackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from elpy.tests.support import RPCGetCompletionsTests
from elpy.tests.support import RPCGetCompletionDocstringTests
from elpy.tests.support import RPCGetCompletionLocationTests
from elpy.tests.support import RPCGetDocstringTests
from elpy.tests.support import RPCGetDefinitionTests
from elpy.tests.support import RPCGetCalltipTests
from elpy.tests.support import RPCGetUsagesTests
Expand Down Expand Up @@ -43,6 +44,11 @@ class TestRPCGetCompletionLocation(RPCGetCompletionLocationTests,
pass


class TestRPCGetDocstring(RPCGetDocstringTests,
JediBackendTestCase):
THREAD_JOIN_DOCSTRING = 'join(self, timeout = None)'


class TestRPCGetDefinition(RPCGetDefinitionTests,
JediBackendTestCase):
pass
Expand Down
2 changes: 1 addition & 1 deletion elpy/tests/test_ropebackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class TestRPCGetCalltip(RPCGetCalltipTests,
class TestRPCGetDocstring(RPCGetDocstringTests,
ShouldCallValidateTest,
RopeBackendTestCase):
pass
THREAD_JOIN_DOCSTRING = 'Thread.join(self, timeout=None):'


class TestGetPythonProjectFiles(RopeBackendTestCase):
Expand Down

0 comments on commit a6251df

Please sign in to comment.