Skip to content

Commit

Permalink
Merge pull request #15 from giannisdoukas/autocomplete
Browse files Browse the repository at this point in the history
fix autocomplete issue
  • Loading branch information
giannisdoukas committed Jul 13, 2020
2 parents 2909ec0 + 40b9575 commit 65769d1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cwlkernel/CWLKernel.py
Expand Up @@ -39,7 +39,7 @@ class CWLKernel(Kernel):
banner = "Common Workflow Language"

_magic_commands: Dict = {}
_auto_complete_engine = AutoCompleteEngine(_magic_commands.keys())
_auto_complete_engine = AutoCompleteEngine(map(lambda m: m.__name__, _magic_commands.values()))

def __init__(self, **kwargs):
super().__init__(**kwargs)
Expand Down
12 changes: 7 additions & 5 deletions tests/test_AutoCompleteEngine.py
Expand Up @@ -8,7 +8,8 @@ class TestAutoCompleteEngine(unittest.TestCase):
maxDiff = None

def test_suggest_magics(self):
auto_complete_engine = AutoCompleteEngine(CWLKernel._magic_commands.keys())
auto_complete_engine = AutoCompleteEngine(map(lambda m: m.__name__, CWLKernel._magic_commands.values()))
magic_commands = set([m.__name__ for m in CWLKernel._magic_commands.values()])
code = "NOT EXISTING CONTENT"
self.assertDictEqual(
{'matches': [], 'cursor_start': len(code) - 1,
Expand All @@ -19,31 +20,31 @@ def test_suggest_magics(self):
code = "% "
suggestion = auto_complete_engine.suggest(code, 1)
self.assertSetEqual(
set(CWLKernel._magic_commands.keys()),
magic_commands,
set(suggestion.pop('matches'))
)
self.assertDictEqual({'cursor_start': 1, 'cursor_end': 1}, suggestion)

code = "% NEW"
suggestion = auto_complete_engine.suggest(code, 5)
self.assertSetEqual(
{c for c in CWLKernel._magic_commands.keys() if c.startswith("new")},
{c.__name__ for c in CWLKernel._magic_commands.values() if c.__name__.startswith("new")},
set(suggestion.pop('matches'))
)
self.assertDictEqual({'cursor_start': 2, 'cursor_end': 5}, suggestion)

code = "% new"
suggestion = auto_complete_engine.suggest(code, 3)
self.assertSetEqual(
{c for c in CWLKernel._magic_commands.keys() if c.startswith("new")},
{c.__name__ for c in CWLKernel._magic_commands.values() if c.__name__.startswith("new")},
set(suggestion.pop('matches'))
)
self.assertDictEqual({'cursor_start': 2, 'cursor_end': 5}, suggestion)

code = "% foo\n% new"
suggestion = auto_complete_engine.suggest(code, 9)
self.assertSetEqual(
{c for c in CWLKernel._magic_commands.keys() if c.startswith("new")},
{c.__name__ for c in CWLKernel._magic_commands.values() if c.__name__.startswith("new")},
set(suggestion.pop('matches'))
)
self.assertDictEqual({'cursor_start': 8, 'cursor_end': 11}, suggestion)
Expand All @@ -68,6 +69,7 @@ def suggester2(query_token, *args, **kwargs):
x for x in ['foo', 'bar', 'foobar']
if x.upper().startswith(query_token.upper())
]

code = "% execute f"
self.assertDictEqual(
{'matches': ['foo', 'foobar'], 'cursor_start': 10,
Expand Down

0 comments on commit 65769d1

Please sign in to comment.