Skip to content

Commit a682697

Browse files
committed
Add test_ipyext.py and fix a bug in julia_completer
1 parent e3fc606 commit a682697

2 files changed

Lines changed: 52 additions & 1 deletion

File tree

src/replhelper/ipyext.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def _unregister_key_bindings():
1212

1313

1414
def julia_completer(julia, self, event):
15-
pos = event.line.find("Main.eval")
15+
pos = event.text_until_cursor.find("Main.eval")
1616
if pos < 0:
1717
return []
1818
pos += len("Main.eval('") # pos: beginning of Julia code
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import pytest
2+
3+
from ..ipyext import julia_completer
4+
5+
try:
6+
from types import SimpleNamespace
7+
except ImportError:
8+
from argparse import Namespace as SimpleNamespace
9+
10+
try:
11+
string_types = (unicode, str)
12+
except NameError:
13+
string_types = (str,)
14+
15+
16+
def make_event(line, text_until_cursor=None, symbol=""):
17+
if text_until_cursor is None:
18+
text_until_cursor = line
19+
return SimpleNamespace(
20+
line=line,
21+
text_until_cursor=text_until_cursor,
22+
symbol=symbol,
23+
)
24+
25+
26+
completable_events = [
27+
make_event('Main.eval("'),
28+
make_event('Main.eval("Base.'),
29+
]
30+
31+
uncompletable_events = [
32+
make_event(''),
33+
make_event('Main.eval("', text_until_cursor="Main.e"),
34+
]
35+
36+
37+
@pytest.mark.parametrize("event", completable_events)
38+
def test_completable_events(julia, event):
39+
dummy_ipython = None
40+
completions = julia_completer(julia, dummy_ipython, event)
41+
assert isinstance(completions, list)
42+
assert completions
43+
assert set(map(type, completions)) == set(string_types)
44+
45+
46+
@pytest.mark.parametrize("event", uncompletable_events)
47+
def test_uncompletable_events(julia, event):
48+
dummy_ipython = None
49+
completions = julia_completer(julia, dummy_ipython, event)
50+
assert isinstance(completions, list)
51+
assert not completions

0 commit comments

Comments
 (0)