|
| 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