1
1
import pytest
2
- from awsshell .autocomplete import AWSCLICompleter
2
+ from awsshell .autocomplete import AWSCLIModelCompleter
3
3
4
4
@pytest .fixture
5
5
def index_data ():
@@ -14,19 +14,19 @@ def index_data():
14
14
15
15
def test_completes_service_names (index_data ):
16
16
index_data ['aws' ]['commands' ] = ['first' , 'second' ]
17
- completer = AWSCLICompleter (index_data )
17
+ completer = AWSCLIModelCompleter (index_data )
18
18
assert completer .autocomplete ('fi' ) == ['first' ]
19
19
20
20
21
21
def test_completes_multiple_service_names (index_data ):
22
22
index_data ['aws' ]['commands' ] = ['abc' , 'acd' , 'b' ]
23
- completer = AWSCLICompleter (index_data )
23
+ completer = AWSCLIModelCompleter (index_data )
24
24
assert completer .autocomplete ('a' ) == ['abc' , 'acd' ]
25
25
26
26
27
27
def test_no_completion (index_data ):
28
28
index_data ['aws' ]['commands' ] = ['foo' , 'bar' ]
29
- completer = AWSCLICompleter (index_data )
29
+ completer = AWSCLIModelCompleter (index_data )
30
30
assert completer .autocomplete ('baz' ) == []
31
31
32
32
@@ -39,7 +39,7 @@ def test_can_complete_subcommands(index_data):
39
39
'children' : {},
40
40
}
41
41
}
42
- completer = AWSCLICompleter (index_data )
42
+ completer = AWSCLIModelCompleter (index_data )
43
43
# The completer tracks state to optimize lookups,
44
44
# so we simulate exactly how it's called.
45
45
completer .autocomplete ('e' )
@@ -61,7 +61,7 @@ def test_everything_completed_on_space(index_data):
61
61
'children' : {},
62
62
}
63
63
}
64
- completer = AWSCLICompleter (index_data )
64
+ completer = AWSCLIModelCompleter (index_data )
65
65
completer .autocomplete ('e' )
66
66
completer .autocomplete ('ec' )
67
67
completer .autocomplete ('ec2' )
@@ -71,13 +71,13 @@ def test_everything_completed_on_space(index_data):
71
71
72
72
def test_autocomplete_top_leve_services_on_space (index_data ):
73
73
index_data ['aws' ]['commands' ] = ['first' , 'second' ]
74
- completer = AWSCLICompleter (index_data )
74
+ completer = AWSCLIModelCompleter (index_data )
75
75
assert completer .autocomplete (' ' ) == ['first' , 'second' ]
76
76
77
77
78
78
def test_reset_auto_complete (index_data ):
79
79
index_data ['aws' ]['commands' ] = ['first' , 'second' ]
80
- completer = AWSCLICompleter (index_data )
80
+ completer = AWSCLIModelCompleter (index_data )
81
81
completer .autocomplete ('f' )
82
82
completer .autocomplete ('fi' )
83
83
completer .autocomplete ('fir' )
@@ -95,7 +95,7 @@ def test_reset_after_subcommand_completion(index_data):
95
95
'children' : {},
96
96
}
97
97
}
98
- completer = AWSCLICompleter (index_data )
98
+ completer = AWSCLIModelCompleter (index_data )
99
99
# The completer tracks state to optimize lookups,
100
100
# so we simulate exactly how it's called.
101
101
completer .autocomplete ('e' )
@@ -127,7 +127,7 @@ def test_can_handle_entire_line_deleted(index_data):
127
127
'children' : {},
128
128
}
129
129
}
130
- completer = AWSCLICompleter (index_data )
130
+ completer = AWSCLIModelCompleter (index_data )
131
131
c = completer .autocomplete
132
132
c ('e' )
133
133
c ('ec' )
@@ -145,7 +145,7 @@ def test_can_handle_entire_line_deleted(index_data):
145
145
146
146
def test_autocompletes_argument_names (index_data ):
147
147
index_data ['aws' ]['arguments' ] = ['--query' , '--debug' ]
148
- completer = AWSCLICompleter (index_data )
148
+ completer = AWSCLIModelCompleter (index_data )
149
149
# These should only appear once in the output. So we need
150
150
# to know if we're a top level argument or not.
151
151
assert completer .autocomplete ('-' ) == ['--query' , '--debug' ]
@@ -162,7 +162,7 @@ def test_autocompletes_global_and_service_args(index_data):
162
162
'children' : {},
163
163
}
164
164
}
165
- completer = AWSCLICompleter (index_data )
165
+ completer = AWSCLIModelCompleter (index_data )
166
166
c = completer .autocomplete
167
167
c ('e' )
168
168
c ('ec' )
@@ -184,10 +184,10 @@ def test_can_mix_options_and_commands(index_data):
184
184
'children' : {},
185
185
}
186
186
}
187
- completer = AWSCLICompleter (index_data )
187
+ completer = AWSCLIModelCompleter (index_data )
188
188
c = completer .autocomplete
189
189
partial_cmd = 'ec2 --no-validate-ssl'
190
- for i in range (len (partial_cmd )):
190
+ for i in range (1 , len (partial_cmd )):
191
191
c (partial_cmd [:i ])
192
192
193
193
assert c ('ec2 --no-validate-ssl ' ) == ['create-tags' , 'describe-instances' ]
@@ -209,12 +209,46 @@ def test_only_change_context_when_in_index(index_data):
209
209
'arguments' : [],
210
210
}
211
211
}
212
- completer = AWSCLICompleter (index_data )
212
+ completer = AWSCLIModelCompleter (index_data )
213
213
c = completer .autocomplete
214
214
partial_cmd = 'ec2 --region us-west-2'
215
- for i in range (len (partial_cmd )):
215
+ for i in range (1 , len (partial_cmd )):
216
216
c (partial_cmd [:i ])
217
217
218
218
# We should ignore "us-west-2" because it's not a child
219
219
# of ec2.
220
220
assert c ('ec2 --region us-west-2 ' ) == ['create-tags' , 'describe-instances' ]
221
+
222
+
223
+ def test_can_handle_skips_in_completion (index_data ):
224
+ # Normally, completion is always requested char by char.
225
+ # Typing "ec2 describe-inst"
226
+ # will subsequent calls to the autocompleter:
227
+ # 'e', 'ec', 'ec2', 'ec2 ', 'ec2 d', 'ec2 de' ... all the way
228
+ # up to 'ec2 describe-inst'.
229
+ # However, the autocompleter should gracefully handle when there's
230
+ # skips, so two subsequent calls are 'ec' and then 'ec2 describe-ta',
231
+ # the autocompleter should still do the right thing. The tradeoff
232
+ # will just be that this case will be slower than the common case
233
+ # of char by char additions.
234
+ index_data ['aws' ]['commands' ] = ['ec2' ]
235
+ index_data ['aws' ]['children' ] = {
236
+ 'ec2' : {
237
+ 'commands' : ['create-tags' , 'describe-instances' ],
238
+ 'argument_metadata' : {},
239
+ 'arguments' : [],
240
+ 'children' : {
241
+ 'create-tags' : {
242
+ 'argument_metadata' : {
243
+ '--resources' : {'example' : '' , 'minidoc' : 'foo' },
244
+ '--tags' : {'example' : 'bar' , 'minidoc' : 'baz' },
245
+ },
246
+ 'arguments' : ['--resources' , '--tags' ],
247
+ }
248
+ },
249
+ }
250
+ }
251
+ completer = AWSCLIModelCompleter (index_data )
252
+ c = completer .autocomplete
253
+ result = c ('ec2 create-ta' )
254
+ assert result == ['create-tags' ]
0 commit comments