Skip to content

Commit fd22e54

Browse files
committed
Moved CompletionIndex.load_completions call from init.
Moving this out is more modular, as CompletionIndex() is created in two places in the source: main and lexer (possible refactor TODO item). It's also called once in the tests. This change also simplifies testing as we can more easily substitute a mock function, although this could also probably be achieved with a mock side effect.
1 parent 5adca9e commit fd22e54

File tree

3 files changed

+2
-1
lines changed

3 files changed

+2
-1
lines changed

awsshell/index/completion.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ def __init__(self, cache_dir=DEFAULT_CACHE_DIR, fslayer=None):
4949
self.subcommands = []
5050
self.global_opts = []
5151
self.args_opts = set()
52-
self.load_completions()
5352

5453
def load_index(self, version_string):
5554
"""Load the completion index for a given CLI version.

awsshell/lexer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class ShellLexer(RegexLexer):
3232
pygments highlighting.
3333
"""
3434
completion_index = CompletionIndex()
35+
completion_index.load_completions()
3536
tokens = {
3637
'root': [
3738
# ec2, s3, elb...

tests/unit/test_load_completions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def setUp(self):
3636
'{"commands": [], "arguments": ["--baz"]}}}}}}'
3737
)
3838
self.completion_index.load_index = lambda x: DATA
39+
self.completion_index.load_completions()
3940

4041
def test_load_completions(self):
4142
assert self.completion_index.commands == [

0 commit comments

Comments
 (0)