Skip to content

Commit

Permalink
Proposed fix for do_inspect
Browse files Browse the repository at this point in the history
  • Loading branch information
Doug Blank committed Sep 7, 2014
1 parent 7781576 commit 332117c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
18 changes: 14 additions & 4 deletions jupyter_kernel/magickernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,13 +261,23 @@ def do_inspect(self, code, cursor_pos, detail_level=0):
if cursor_pos > len(code):
return

if len(code) > 1 and code[cursor_pos - 1] == '(':
if cursor_pos == len(code):
cursor_position = len(code) - 1

# skip over non-interesting characters:
while (cursor_pos - 1 > 0 and
code[cursor_pos - 1] in self.split_characters):
cursor_pos -= 1

self.log.debug(code)
content = {'status': 'aborted', 'data': {}, 'found': False}
# include only interesting characters:
start = cursor_pos
while (start - 1 >= 0 and
code[start - 1] not in self.split_characters):
start -= 1

docstring = self.get_help_on(code[:cursor_pos], detail_level)
partial = code[start:cursor_pos]
content = {'status': 'aborted', 'data': {}, 'found': False}
docstring = self.get_help_on(partial, detail_level)

if docstring:
content["data"] = {"text/plain": docstring}
Expand Down
25 changes: 13 additions & 12 deletions jupyter_kernel/tests/test_magickernel.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import re
from jupyter_kernel.tests.utils import get_kernel, get_log_text


Expand Down Expand Up @@ -111,20 +112,20 @@ def do_execute_direct(self, code):
message = resp['payload'][0]['data']['text/plain']
assert "Sorry, no help is available on 'dir?'." == message, message

comp = kernel.parse_code('dir', 0, len('dir'))
assert (comp["start"] == 0 and
comp["end"] == 3 and
comp["obj"] == "dir"), comp
content = kernel.do_inspect('dir', len('dir'))
message = content["data"]["text/plain"]
match = re.match("Sorry, no help is available on '(.*)'", message)
assert match.groups()[0] == "dir", message + " for 'dir'"

comp = kernel.parse_code('len(dir', 0, len('len(dir'))
assert (comp["start"] == 4 and
comp["end"] == 7 and
comp["obj"] == "dir"), comp
content = kernel.do_inspect('len(dir', len('len(dir'))
message = content["data"]["text/plain"]
match = re.match("Sorry, no help is available on '(.*)'", message)
assert match.groups()[0] == "dir", message + " for 'len(dir'"

comp = kernel.parse_code('(dir', 0, len('(dir'))
assert (comp["start"] == 1 and
comp["end"] == 4 and
comp["obj"] == "dir"), comp
content = kernel.do_inspect('(dir', len('(dir'))
message = content["data"]["text/plain"]
match = re.match("Sorry, no help is available on '(.*)'", message)
assert match.groups()[0] == "dir", message + " for '(dir'"

def teardown():
if os.path.exists("TEST.txt"):
Expand Down

0 comments on commit 332117c

Please sign in to comment.