##// END OF EJS Templates
Fix bugs in completer.py with incompletely-implemented property....
Fernando Perez -
Show More
@@ -178,11 +178,14 b' def compress_user(path, tilde_expand, tilde_val):'
178 178 else:
179 179 return path
180 180
181
181 182 class Bunch(object): pass
182 183
184
183 185 DELIMS = ' \t\n`!@#$^&*()=+[{]}\\|;:\'",<>?'
184 186 GREEDY_DELIMS = ' \r\n'
185 187
188
186 189 class CompletionSplitter(object):
187 190 """An object to split an input line in a manner similar to readline.
188 191
@@ -194,7 +197,7 b' class CompletionSplitter(object):'
194 197
195 198 What characters are used as splitting delimiters can be controlled by
196 199 setting the `delims` attribute (this is a property that internally
197 automatically builds the necessary """
200 automatically builds the necessary regular expression)"""
198 201
199 202 # Private interface
200 203
@@ -212,19 +215,21 b' class CompletionSplitter(object):'
212 215
213 216 def __init__(self, delims=None):
214 217 delims = CompletionSplitter._delims if delims is None else delims
215 self.set_delims(delims)
218 self.delims = delims
216 219
217 def set_delims(self, delims):
220 @property
221 def delims(self):
222 """Return the string of delimiter characters."""
223 return self._delims
224
225 @delims.setter
226 def delims(self, delims):
218 227 """Set the delimiters for line splitting."""
219 228 expr = '[' + ''.join('\\'+ c for c in delims) + ']'
220 229 self._delim_re = re.compile(expr)
221 230 self._delims = delims
222 231 self._delim_expr = expr
223 232
224 def get_delims(self):
225 """Return the string of delimiter characters."""
226 return self._delims
227
228 233 def split_line(self, line, cursor_pos=None):
229 234 """Split a line of text with a cursor at the given position.
230 235 """
@@ -377,7 +382,7 b' class Completer(Configurable):'
377 382 def get__all__entries(obj):
378 383 """returns the strings in the __all__ attribute"""
379 384 try:
380 words = getattr(obj,'__all__')
385 words = getattr(obj, '__all__')
381 386 except:
382 387 return []
383 388
@@ -390,12 +395,12 b' class IPCompleter(Completer):'
390 395 def _greedy_changed(self, name, old, new):
391 396 """update the splitter and readline delims when greedy is changed"""
392 397 if new:
393 self.splitter.set_delims(GREEDY_DELIMS)
398 self.splitter.delims = GREEDY_DELIMS
394 399 else:
395 self.splitter.set_delims(DELIMS)
400 self.splitter.delims = DELIMS
396 401
397 402 if self.readline:
398 self.readline.set_completer_delims(self.splitter.get_delims())
403 self.readline.set_completer_delims(self.splitter.delims)
399 404
400 405 merge_completions = CBool(True, config=True,
401 406 help="""Whether to merge completion results into a single list
@@ -821,7 +826,7 b' class IPCompleter(Completer):'
821 826
822 827 self.line_buffer = line_buffer
823 828 self.text_until_cursor = self.line_buffer[:cursor_pos]
824 #io.rprint('\nCOMP2 %r %r %r' % (text, line_buffer, cursor_pos)) # dbg
829 #io.rprint('COMP2 %r %r %r' % (text, line_buffer, cursor_pos)) # dbg
825 830
826 831 # Start with a clean slate of completions
827 832 self.matches[:] = []
@@ -119,8 +119,8 b' class CompletionSplitterTestCase(unittest.TestCase):'
119 119 self.sp = completer.CompletionSplitter()
120 120
121 121 def test_delim_setting(self):
122 self.sp.set_delims(' ')
123 nt.assert_equal(self.sp.get_delims(), ' ')
122 self.sp.delims = ' '
123 nt.assert_equal(self.sp.delims, ' ')
124 124 nt.assert_equal(self.sp._delim_expr, '[\ ]')
125 125
126 126 def test_spaces(self):
@@ -202,13 +202,18 b' def test_local_file_completions():'
202 202
203 203 def test_greedy_completions():
204 204 ip = get_ipython()
205 ip.Completer.greedy = False
206 ip.ex('a=range(5)')
207 _,c = ip.complete('.',line='a[0].')
208 nt.assert_false('a[0].real' in c, "Shouldn't have completed on a[0]: %s"%c)
209 ip.Completer.greedy = True
210 _,c = ip.complete('.',line='a[0].')
211 nt.assert_true('a[0].real' in c, "Should have completed on a[0]: %s"%c)
205 greedy_original = ip.Completer.greedy
206 try:
207 ip.Completer.greedy = False
208 ip.ex('a=range(5)')
209 _,c = ip.complete('.',line='a[0].')
210 nt.assert_false('a[0].real' in c,
211 "Shouldn't have completed on a[0]: %s"%c)
212 ip.Completer.greedy = True
213 _,c = ip.complete('.',line='a[0].')
214 nt.assert_true('a[0].real' in c, "Should have completed on a[0]: %s"%c)
215 finally:
216 ip.Completer.greedy = greedy_original
212 217
213 218
214 219 def test_omit__names():
@@ -280,7 +285,8 b' def test_func_kw_completions():'
280 285 ip = get_ipython()
281 286 c = ip.Completer
282 287 ip.ex('def myfunc(a=1,b=2): return a+b')
283 s, matches = c.complete(None,'myfunc(1,b')
284 nt.assert_true('b=' in matches)
285 s, matches = c.complete(None,'myfunc(1,b)',10)#cursor is right after b
286 nt.assert_true('b=' in matches)
288 s, matches = c.complete(None, 'myfunc(1,b')
289 nt.assert_in('b=', matches)
290 # Simulate completing with cursor right after b (pos==10):
291 s, matches = c.complete(None,'myfunc(1,b)', 10)
292 nt.assert_in('b=', matches)
General Comments 0
You need to be logged in to leave comments. Login now