##// END OF EJS Templates
[core][tests][completer] Remove nose
Samuel Gaist -
Show More
@@ -11,8 +11,6 b' import unittest'
11
11
12 from contextlib import contextmanager
12 from contextlib import contextmanager
13
13
14 import nose.tools as nt
15
16 from traitlets.config.loader import Config
14 from traitlets.config.loader import Config
17 from IPython import get_ipython
15 from IPython import get_ipython
18 from IPython.core import completer
16 from IPython.core import completer
@@ -27,7 +25,6 b' from IPython.core.completer import ('
27 match_dict_keys,
25 match_dict_keys,
28 _deduplicate_completions,
26 _deduplicate_completions,
29 )
27 )
30 from nose.tools import assert_in, assert_not_in
31
28
32 # -----------------------------------------------------------------------------
29 # -----------------------------------------------------------------------------
33 # Test functions
30 # Test functions
@@ -150,7 +147,7 b' def test_protect_filename():'
150 # run the actual tests
147 # run the actual tests
151 for s1, s2 in pairs:
148 for s1, s2 in pairs:
152 s1p = completer.protect_filename(s1)
149 s1p = completer.protect_filename(s1)
153 nt.assert_equal(s1p, s2)
150 assert s1p == s2
154
151
155
152
156 def check_line_split(splitter, test_specs):
153 def check_line_split(splitter, test_specs):
@@ -158,7 +155,7 b' def check_line_split(splitter, test_specs):'
158 cursor_pos = len(part1)
155 cursor_pos = len(part1)
159 line = part1 + part2
156 line = part1 + part2
160 out = splitter.split_line(line, cursor_pos)
157 out = splitter.split_line(line, cursor_pos)
161 nt.assert_equal(out, split)
158 assert out == split
162
159
163
160
164 def test_line_split():
161 def test_line_split():
@@ -267,8 +264,8 b' class TestCompleter(unittest.TestCase):'
267 # should be thrown and the return value should be a pair of text, list
264 # should be thrown and the return value should be a pair of text, list
268 # values.
265 # values.
269 text, matches = ip.complete(t)
266 text, matches = ip.complete(t)
270 nt.assert_true(isinstance(text, str))
267 self.assertIsInstance(text, str)
271 nt.assert_true(isinstance(matches, list))
268 self.assertIsInstance(matches, list)
272
269
273 def test_latex_completions(self):
270 def test_latex_completions(self):
274 from IPython.core.latex_symbols import latex_symbols
271 from IPython.core.latex_symbols import latex_symbols
@@ -279,16 +276,16 b' class TestCompleter(unittest.TestCase):'
279 keys = random.sample(latex_symbols.keys(), 10)
276 keys = random.sample(latex_symbols.keys(), 10)
280 for k in keys:
277 for k in keys:
281 text, matches = ip.complete(k)
278 text, matches = ip.complete(k)
282 nt.assert_equal(text, k)
279 self.assertEqual(text, k)
283 nt.assert_equal(matches, [latex_symbols[k]])
280 self.assertEqual(matches, [latex_symbols[k]])
284 # Test a more complex line
281 # Test a more complex line
285 text, matches = ip.complete("print(\\alpha")
282 text, matches = ip.complete("print(\\alpha")
286 nt.assert_equal(text, "\\alpha")
283 self.assertEqual(text, "\\alpha")
287 nt.assert_equal(matches[0], latex_symbols["\\alpha"])
284 self.assertEqual(matches[0], latex_symbols["\\alpha"])
288 # Test multiple matching latex symbols
285 # Test multiple matching latex symbols
289 text, matches = ip.complete("\\al")
286 text, matches = ip.complete("\\al")
290 nt.assert_in("\\alpha", matches)
287 self.assertIn("\\alpha", matches)
291 nt.assert_in("\\aleph", matches)
288 self.assertIn("\\aleph", matches)
292
289
293 def test_latex_no_results(self):
290 def test_latex_no_results(self):
294 """
291 """
@@ -296,30 +293,30 b' class TestCompleter(unittest.TestCase):'
296 """
293 """
297 ip = get_ipython()
294 ip = get_ipython()
298 text, matches = ip.Completer.latex_matches("\\really_i_should_match_nothing")
295 text, matches = ip.Completer.latex_matches("\\really_i_should_match_nothing")
299 nt.assert_equal(text, "")
296 self.assertEqual(text, "")
300 nt.assert_equal(matches, ())
297 self.assertEqual(matches, ())
301
298
302 def test_back_latex_completion(self):
299 def test_back_latex_completion(self):
303 ip = get_ipython()
300 ip = get_ipython()
304
301
305 # do not return more than 1 matches for \beta, only the latex one.
302 # do not return more than 1 matches for \beta, only the latex one.
306 name, matches = ip.complete("\\Ξ²")
303 name, matches = ip.complete("\\Ξ²")
307 nt.assert_equal(matches, ['\\beta'])
304 self.assertEqual(matches, ["\\beta"])
308
305
309 def test_back_unicode_completion(self):
306 def test_back_unicode_completion(self):
310 ip = get_ipython()
307 ip = get_ipython()
311
308
312 name, matches = ip.complete("\\β…€")
309 name, matches = ip.complete("\\β…€")
313 nt.assert_equal(matches, ("\\ROMAN NUMERAL FIVE",))
310 self.assertEqual(matches, ("\\ROMAN NUMERAL FIVE",))
314
311
315 def test_forward_unicode_completion(self):
312 def test_forward_unicode_completion(self):
316 ip = get_ipython()
313 ip = get_ipython()
317
314
318 name, matches = ip.complete("\\ROMAN NUMERAL FIVE")
315 name, matches = ip.complete("\\ROMAN NUMERAL FIVE")
319 nt.assert_equal(matches, ["β…€"] ) # This is not a V
316 self.assertEqual(matches, ["β…€"]) # This is not a V
320 nt.assert_equal(matches, ["\u2164"] ) # same as above but explicit.
317 self.assertEqual(matches, ["\u2164"]) # same as above but explicit.
321
318
322 @nt.nottest # now we have a completion for \jmath
319 @unittest.skip("now we have a completion for \jmath")
323 @decorators.knownfailureif(
320 @decorators.knownfailureif(
324 sys.platform == "win32", "Fails if there is a C:\\j... path"
321 sys.platform == "win32", "Fails if there is a C:\\j... path"
325 )
322 )
@@ -329,7 +326,7 b' class TestCompleter(unittest.TestCase):'
329 # single ascii letter that don't have yet completions
326 # single ascii letter that don't have yet completions
330 for letter in "jJ":
327 for letter in "jJ":
331 name, matches = ip.complete("\\" + letter)
328 name, matches = ip.complete("\\" + letter)
332 nt.assert_equal(matches, [])
329 self.assertEqual(matches, [])
333
330
334 class CompletionSplitterTestCase(unittest.TestCase):
331 class CompletionSplitterTestCase(unittest.TestCase):
335 def setUp(self):
332 def setUp(self):
@@ -337,8 +334,8 b' class TestCompleter(unittest.TestCase):'
337
334
338 def test_delim_setting(self):
335 def test_delim_setting(self):
339 self.sp.delims = " "
336 self.sp.delims = " "
340 nt.assert_equal(self.sp.delims, " ")
337 self.assertEqual(self.sp.delims, " ")
341 nt.assert_equal(self.sp._delim_expr, r"[\ ]")
338 self.assertEqual(self.sp._delim_expr, r"[\ ]")
342
339
343 def test_spaces(self):
340 def test_spaces(self):
344 """Test with only spaces as split chars."""
341 """Test with only spaces as split chars."""
@@ -348,19 +345,19 b' class TestCompleter(unittest.TestCase):'
348
345
349 def test_has_open_quotes1(self):
346 def test_has_open_quotes1(self):
350 for s in ["'", "'''", "'hi' '"]:
347 for s in ["'", "'''", "'hi' '"]:
351 nt.assert_equal(completer.has_open_quotes(s), "'")
348 self.assertEqual(completer.has_open_quotes(s), "'")
352
349
353 def test_has_open_quotes2(self):
350 def test_has_open_quotes2(self):
354 for s in ['"', '"""', '"hi" "']:
351 for s in ['"', '"""', '"hi" "']:
355 nt.assert_equal(completer.has_open_quotes(s), '"')
352 self.assertEqual(completer.has_open_quotes(s), '"')
356
353
357 def test_has_open_quotes3(self):
354 def test_has_open_quotes3(self):
358 for s in ["''", "''' '''", "'hi' 'ipython'"]:
355 for s in ["''", "''' '''", "'hi' 'ipython'"]:
359 nt.assert_false(completer.has_open_quotes(s))
356 self.assertFalse(completer.has_open_quotes(s))
360
357
361 def test_has_open_quotes4(self):
358 def test_has_open_quotes4(self):
362 for s in ['""', '""" """', '"hi" "ipython"']:
359 for s in ['""', '""" """', '"hi" "ipython"']:
363 nt.assert_false(completer.has_open_quotes(s))
360 self.assertFalse(completer.has_open_quotes(s))
364
361
365 @decorators.knownfailureif(
362 @decorators.knownfailureif(
366 sys.platform == "win32", "abspath completions fail on Windows"
363 sys.platform == "win32", "abspath completions fail on Windows"
@@ -376,13 +373,13 b' class TestCompleter(unittest.TestCase):'
376
373
377 # Check simple completion
374 # Check simple completion
378 c = ip.complete(prefix)[1]
375 c = ip.complete(prefix)[1]
379 nt.assert_equal(c, names)
376 self.assertEqual(c, names)
380
377
381 # Now check with a function call
378 # Now check with a function call
382 cmd = 'a = f("%s' % prefix
379 cmd = 'a = f("%s' % prefix
383 c = ip.complete(prefix, cmd)[1]
380 c = ip.complete(prefix, cmd)[1]
384 comp = [prefix + s for s in suffixes]
381 comp = [prefix + s for s in suffixes]
385 nt.assert_equal(c, comp)
382 self.assertEqual(c, comp)
386
383
387 def test_local_file_completions(self):
384 def test_local_file_completions(self):
388 ip = get_ipython()
385 ip = get_ipython()
@@ -395,13 +392,13 b' class TestCompleter(unittest.TestCase):'
395
392
396 # Check simple completion
393 # Check simple completion
397 c = ip.complete(prefix)[1]
394 c = ip.complete(prefix)[1]
398 nt.assert_equal(c, names)
395 self.assertEqual(c, names)
399
396
400 # Now check with a function call
397 # Now check with a function call
401 cmd = 'a = f("%s' % prefix
398 cmd = 'a = f("%s' % prefix
402 c = ip.complete(prefix, cmd)[1]
399 c = ip.complete(prefix, cmd)[1]
403 comp = {prefix + s for s in suffixes}
400 comp = {prefix + s for s in suffixes}
404 nt.assert_true(comp.issubset(set(c)))
401 self.assertTrue(comp.issubset(set(c)))
405
402
406 def test_quoted_file_completions(self):
403 def test_quoted_file_completions(self):
407 ip = get_ipython()
404 ip = get_ipython()
@@ -417,21 +414,21 b' class TestCompleter(unittest.TestCase):'
417 c = ip.Completer._complete(
414 c = ip.Completer._complete(
418 cursor_line=0, cursor_pos=len(text), full_text=text
415 cursor_line=0, cursor_pos=len(text), full_text=text
419 )[1]
416 )[1]
420 nt.assert_equal(c, [escaped])
417 self.assertEqual(c, [escaped])
421
418
422 # Double quote requires no escape
419 # Double quote requires no escape
423 text = 'open("foo'
420 text = 'open("foo'
424 c = ip.Completer._complete(
421 c = ip.Completer._complete(
425 cursor_line=0, cursor_pos=len(text), full_text=text
422 cursor_line=0, cursor_pos=len(text), full_text=text
426 )[1]
423 )[1]
427 nt.assert_equal(c, [name])
424 self.assertEqual(c, [name])
428
425
429 # No quote requires an escape
426 # No quote requires an escape
430 text = "%ls foo"
427 text = "%ls foo"
431 c = ip.Completer._complete(
428 c = ip.Completer._complete(
432 cursor_line=0, cursor_pos=len(text), full_text=text
429 cursor_line=0, cursor_pos=len(text), full_text=text
433 )[1]
430 )[1]
434 nt.assert_equal(c, [escaped])
431 self.assertEqual(c, [escaped])
435
432
436 def test_all_completions_dups(self):
433 def test_all_completions_dups(self):
437 """
434 """
@@ -537,18 +534,18 b' class TestCompleter(unittest.TestCase):'
537 ip = get_ipython()
534 ip = get_ipython()
538 ip.ex("a=list(range(5))")
535 ip.ex("a=list(range(5))")
539 _, c = ip.complete(".", line="a[0].")
536 _, c = ip.complete(".", line="a[0].")
540 nt.assert_false(".real" in c, "Shouldn't have completed on a[0]: %s" % c)
537 self.assertFalse(".real" in c, "Shouldn't have completed on a[0]: %s" % c)
541
538
542 def _(line, cursor_pos, expect, message, completion):
539 def _(line, cursor_pos, expect, message, completion):
543 with greedy_completion(), provisionalcompleter():
540 with greedy_completion(), provisionalcompleter():
544 ip.Completer.use_jedi = False
541 ip.Completer.use_jedi = False
545 _, c = ip.complete(".", line=line, cursor_pos=cursor_pos)
542 _, c = ip.complete(".", line=line, cursor_pos=cursor_pos)
546 nt.assert_in(expect, c, message % c)
543 self.assertIn(expect, c, message % c)
547
544
548 ip.Completer.use_jedi = True
545 ip.Completer.use_jedi = True
549 with provisionalcompleter():
546 with provisionalcompleter():
550 completions = ip.Completer.completions(line, cursor_pos)
547 completions = ip.Completer.completions(line, cursor_pos)
551 nt.assert_in(completion, completions)
548 self.assertIn(completion, completions)
552
549
553 with provisionalcompleter():
550 with provisionalcompleter():
554 yield _, "a[0].", 5, "a[0].real", "Should have completed on a[0].: %s", Completion(
551 yield _, "a[0].", 5, "a[0].real", "Should have completed on a[0].: %s", Completion(
@@ -575,13 +572,13 b' class TestCompleter(unittest.TestCase):'
575 with provisionalcompleter():
572 with provisionalcompleter():
576 c.use_jedi = False
573 c.use_jedi = False
577 s, matches = c.complete("ip.")
574 s, matches = c.complete("ip.")
578 nt.assert_in("ip.__str__", matches)
575 self.assertIn("ip.__str__", matches)
579 nt.assert_in("ip._hidden_attr", matches)
576 self.assertIn("ip._hidden_attr", matches)
580
577
581 # c.use_jedi = True
578 # c.use_jedi = True
582 # completions = set(c.completions('ip.', 3))
579 # completions = set(c.completions('ip.', 3))
583 # nt.assert_in(Completion(3, 3, '__str__'), completions)
580 # self.assertIn(Completion(3, 3, '__str__'), completions)
584 # nt.assert_in(Completion(3,3, "_hidden_attr"), completions)
581 # self.assertIn(Completion(3,3, "_hidden_attr"), completions)
585
582
586 cfg = Config()
583 cfg = Config()
587 cfg.IPCompleter.omit__names = 1
584 cfg.IPCompleter.omit__names = 1
@@ -589,13 +586,13 b' class TestCompleter(unittest.TestCase):'
589 with provisionalcompleter():
586 with provisionalcompleter():
590 c.use_jedi = False
587 c.use_jedi = False
591 s, matches = c.complete("ip.")
588 s, matches = c.complete("ip.")
592 nt.assert_not_in("ip.__str__", matches)
589 self.assertNotIn("ip.__str__", matches)
593 # nt.assert_in('ip._hidden_attr', matches)
590 # self.assertIn('ip._hidden_attr', matches)
594
591
595 # c.use_jedi = True
592 # c.use_jedi = True
596 # completions = set(c.completions('ip.', 3))
593 # completions = set(c.completions('ip.', 3))
597 # nt.assert_not_in(Completion(3,3,'__str__'), completions)
594 # self.assertNotIn(Completion(3,3,'__str__'), completions)
598 # nt.assert_in(Completion(3,3, "_hidden_attr"), completions)
595 # self.assertIn(Completion(3,3, "_hidden_attr"), completions)
599
596
600 cfg = Config()
597 cfg = Config()
601 cfg.IPCompleter.omit__names = 2
598 cfg.IPCompleter.omit__names = 2
@@ -603,22 +600,22 b' class TestCompleter(unittest.TestCase):'
603 with provisionalcompleter():
600 with provisionalcompleter():
604 c.use_jedi = False
601 c.use_jedi = False
605 s, matches = c.complete("ip.")
602 s, matches = c.complete("ip.")
606 nt.assert_not_in("ip.__str__", matches)
603 self.assertNotIn("ip.__str__", matches)
607 nt.assert_not_in("ip._hidden_attr", matches)
604 self.assertNotIn("ip._hidden_attr", matches)
608
605
609 # c.use_jedi = True
606 # c.use_jedi = True
610 # completions = set(c.completions('ip.', 3))
607 # completions = set(c.completions('ip.', 3))
611 # nt.assert_not_in(Completion(3,3,'__str__'), completions)
608 # self.assertNotIn(Completion(3,3,'__str__'), completions)
612 # nt.assert_not_in(Completion(3,3, "_hidden_attr"), completions)
609 # self.assertNotIn(Completion(3,3, "_hidden_attr"), completions)
613
610
614 with provisionalcompleter():
611 with provisionalcompleter():
615 c.use_jedi = False
612 c.use_jedi = False
616 s, matches = c.complete("ip._x.")
613 s, matches = c.complete("ip._x.")
617 nt.assert_in("ip._x.keys", matches)
614 self.assertIn("ip._x.keys", matches)
618
615
619 # c.use_jedi = True
616 # c.use_jedi = True
620 # completions = set(c.completions('ip._x.', 6))
617 # completions = set(c.completions('ip._x.', 6))
621 # nt.assert_in(Completion(6,6, "keys"), completions)
618 # self.assertIn(Completion(6,6, "keys"), completions)
622
619
623 del ip._hidden_attr
620 del ip._hidden_attr
624 del ip._x
621 del ip._x
@@ -636,21 +633,21 b' class TestCompleter(unittest.TestCase):'
636 cfg.IPCompleter.limit_to__all__ = False
633 cfg.IPCompleter.limit_to__all__ = False
637 c.update_config(cfg)
634 c.update_config(cfg)
638 s, matches = c.complete("d.")
635 s, matches = c.complete("d.")
639 nt.assert_in("d.x", matches)
636 self.assertIn("d.x", matches)
640
637
641 def test_get__all__entries_ok(self):
638 def test_get__all__entries_ok(self):
642 class A:
639 class A:
643 __all__ = ["x", 1]
640 __all__ = ["x", 1]
644
641
645 words = completer.get__all__entries(A())
642 words = completer.get__all__entries(A())
646 nt.assert_equal(words, ["x"])
643 self.assertEqual(words, ["x"])
647
644
648 def test_get__all__entries_no__all__ok(self):
645 def test_get__all__entries_no__all__ok(self):
649 class A:
646 class A:
650 pass
647 pass
651
648
652 words = completer.get__all__entries(A())
649 words = completer.get__all__entries(A())
653 nt.assert_equal(words, [])
650 self.assertEqual(words, [])
654
651
655 def test_func_kw_completions(self):
652 def test_func_kw_completions(self):
656 ip = get_ipython()
653 ip = get_ipython()
@@ -658,39 +655,39 b' class TestCompleter(unittest.TestCase):'
658 c.use_jedi = False
655 c.use_jedi = False
659 ip.ex("def myfunc(a=1,b=2): return a+b")
656 ip.ex("def myfunc(a=1,b=2): return a+b")
660 s, matches = c.complete(None, "myfunc(1,b")
657 s, matches = c.complete(None, "myfunc(1,b")
661 nt.assert_in("b=", matches)
658 self.assertIn("b=", matches)
662 # Simulate completing with cursor right after b (pos==10):
659 # Simulate completing with cursor right after b (pos==10):
663 s, matches = c.complete(None, "myfunc(1,b)", 10)
660 s, matches = c.complete(None, "myfunc(1,b)", 10)
664 nt.assert_in("b=", matches)
661 self.assertIn("b=", matches)
665 s, matches = c.complete(None, 'myfunc(a="escaped\\")string",b')
662 s, matches = c.complete(None, 'myfunc(a="escaped\\")string",b')
666 nt.assert_in("b=", matches)
663 self.assertIn("b=", matches)
667 # builtin function
664 # builtin function
668 s, matches = c.complete(None, "min(k, k")
665 s, matches = c.complete(None, "min(k, k")
669 nt.assert_in("key=", matches)
666 self.assertIn("key=", matches)
670
667
671 def test_default_arguments_from_docstring(self):
668 def test_default_arguments_from_docstring(self):
672 ip = get_ipython()
669 ip = get_ipython()
673 c = ip.Completer
670 c = ip.Completer
674 kwd = c._default_arguments_from_docstring("min(iterable[, key=func]) -> value")
671 kwd = c._default_arguments_from_docstring("min(iterable[, key=func]) -> value")
675 nt.assert_equal(kwd, ["key"])
672 self.assertEqual(kwd, ["key"])
676 # with cython type etc
673 # with cython type etc
677 kwd = c._default_arguments_from_docstring(
674 kwd = c._default_arguments_from_docstring(
678 "Minuit.migrad(self, int ncall=10000, resume=True, int nsplit=1)\n"
675 "Minuit.migrad(self, int ncall=10000, resume=True, int nsplit=1)\n"
679 )
676 )
680 nt.assert_equal(kwd, ["ncall", "resume", "nsplit"])
677 self.assertEqual(kwd, ["ncall", "resume", "nsplit"])
681 # white spaces
678 # white spaces
682 kwd = c._default_arguments_from_docstring(
679 kwd = c._default_arguments_from_docstring(
683 "\n Minuit.migrad(self, int ncall=10000, resume=True, int nsplit=1)\n"
680 "\n Minuit.migrad(self, int ncall=10000, resume=True, int nsplit=1)\n"
684 )
681 )
685 nt.assert_equal(kwd, ["ncall", "resume", "nsplit"])
682 self.assertEqual(kwd, ["ncall", "resume", "nsplit"])
686
683
687 def test_line_magics(self):
684 def test_line_magics(self):
688 ip = get_ipython()
685 ip = get_ipython()
689 c = ip.Completer
686 c = ip.Completer
690 s, matches = c.complete(None, "lsmag")
687 s, matches = c.complete(None, "lsmag")
691 nt.assert_in("%lsmagic", matches)
688 self.assertIn("%lsmagic", matches)
692 s, matches = c.complete(None, "%lsmag")
689 s, matches = c.complete(None, "%lsmag")
693 nt.assert_in("%lsmagic", matches)
690 self.assertIn("%lsmagic", matches)
694
691
695 def test_cell_magics(self):
692 def test_cell_magics(self):
696 from IPython.core.magic import register_cell_magic
693 from IPython.core.magic import register_cell_magic
@@ -703,9 +700,9 b' class TestCompleter(unittest.TestCase):'
703 c = ip.Completer
700 c = ip.Completer
704
701
705 s, matches = c.complete(None, "_foo_ce")
702 s, matches = c.complete(None, "_foo_ce")
706 nt.assert_in("%%_foo_cellm", matches)
703 self.assertIn("%%_foo_cellm", matches)
707 s, matches = c.complete(None, "%%_foo_ce")
704 s, matches = c.complete(None, "%%_foo_ce")
708 nt.assert_in("%%_foo_cellm", matches)
705 self.assertIn("%%_foo_cellm", matches)
709
706
710 def test_line_cell_magics(self):
707 def test_line_cell_magics(self):
711 from IPython.core.magic import register_line_cell_magic
708 from IPython.core.magic import register_line_cell_magic
@@ -722,14 +719,14 b' class TestCompleter(unittest.TestCase):'
722 # and this will show a difference if the same name is both a line and cell
719 # and this will show a difference if the same name is both a line and cell
723 # magic.
720 # magic.
724 s, matches = c.complete(None, "_bar_ce")
721 s, matches = c.complete(None, "_bar_ce")
725 nt.assert_in("%_bar_cellm", matches)
722 self.assertIn("%_bar_cellm", matches)
726 nt.assert_in("%%_bar_cellm", matches)
723 self.assertIn("%%_bar_cellm", matches)
727 s, matches = c.complete(None, "%_bar_ce")
724 s, matches = c.complete(None, "%_bar_ce")
728 nt.assert_in("%_bar_cellm", matches)
725 self.assertIn("%_bar_cellm", matches)
729 nt.assert_in("%%_bar_cellm", matches)
726 self.assertIn("%%_bar_cellm", matches)
730 s, matches = c.complete(None, "%%_bar_ce")
727 s, matches = c.complete(None, "%%_bar_ce")
731 nt.assert_not_in("%_bar_cellm", matches)
728 self.assertNotIn("%_bar_cellm", matches)
732 nt.assert_in("%%_bar_cellm", matches)
729 self.assertIn("%%_bar_cellm", matches)
733
730
734 def test_magic_completion_order(self):
731 def test_magic_completion_order(self):
735 ip = get_ipython()
732 ip = get_ipython()
@@ -737,7 +734,7 b' class TestCompleter(unittest.TestCase):'
737
734
738 # Test ordering of line and cell magics.
735 # Test ordering of line and cell magics.
739 text, matches = c.complete("timeit")
736 text, matches = c.complete("timeit")
740 nt.assert_equal(matches, ["%timeit", "%%timeit"])
737 self.assertEqual(matches, ["%timeit", "%%timeit"])
741
738
742 def test_magic_completion_shadowing(self):
739 def test_magic_completion_shadowing(self):
743 ip = get_ipython()
740 ip = get_ipython()
@@ -746,18 +743,18 b' class TestCompleter(unittest.TestCase):'
746
743
747 # Before importing matplotlib, %matplotlib magic should be the only option.
744 # Before importing matplotlib, %matplotlib magic should be the only option.
748 text, matches = c.complete("mat")
745 text, matches = c.complete("mat")
749 nt.assert_equal(matches, ["%matplotlib"])
746 self.assertEqual(matches, ["%matplotlib"])
750
747
751 # The newly introduced name should shadow the magic.
748 # The newly introduced name should shadow the magic.
752 ip.run_cell("matplotlib = 1")
749 ip.run_cell("matplotlib = 1")
753 text, matches = c.complete("mat")
750 text, matches = c.complete("mat")
754 nt.assert_equal(matches, ["matplotlib"])
751 self.assertEqual(matches, ["matplotlib"])
755
752
756 # After removing matplotlib from namespace, the magic should again be
753 # After removing matplotlib from namespace, the magic should again be
757 # the only option.
754 # the only option.
758 del ip.user_ns["matplotlib"]
755 del ip.user_ns["matplotlib"]
759 text, matches = c.complete("mat")
756 text, matches = c.complete("mat")
760 nt.assert_equal(matches, ["%matplotlib"])
757 self.assertEqual(matches, ["%matplotlib"])
761
758
762 def test_magic_completion_shadowing_explicit(self):
759 def test_magic_completion_shadowing_explicit(self):
763 """
760 """
@@ -769,62 +766,62 b' class TestCompleter(unittest.TestCase):'
769
766
770 # Before importing matplotlib, %matplotlib magic should be the only option.
767 # Before importing matplotlib, %matplotlib magic should be the only option.
771 text, matches = c.complete("%mat")
768 text, matches = c.complete("%mat")
772 nt.assert_equal(matches, ["%matplotlib"])
769 self.assertEqual(matches, ["%matplotlib"])
773
770
774 ip.run_cell("matplotlib = 1")
771 ip.run_cell("matplotlib = 1")
775
772
776 # After removing matplotlib from namespace, the magic should still be
773 # After removing matplotlib from namespace, the magic should still be
777 # the only option.
774 # the only option.
778 text, matches = c.complete("%mat")
775 text, matches = c.complete("%mat")
779 nt.assert_equal(matches, ["%matplotlib"])
776 self.assertEqual(matches, ["%matplotlib"])
780
777
781 def test_magic_config(self):
778 def test_magic_config(self):
782 ip = get_ipython()
779 ip = get_ipython()
783 c = ip.Completer
780 c = ip.Completer
784
781
785 s, matches = c.complete(None, "conf")
782 s, matches = c.complete(None, "conf")
786 nt.assert_in("%config", matches)
783 self.assertIn("%config", matches)
787 s, matches = c.complete(None, "conf")
784 s, matches = c.complete(None, "conf")
788 nt.assert_not_in("AliasManager", matches)
785 self.assertNotIn("AliasManager", matches)
789 s, matches = c.complete(None, "config ")
786 s, matches = c.complete(None, "config ")
790 nt.assert_in("AliasManager", matches)
787 self.assertIn("AliasManager", matches)
791 s, matches = c.complete(None, "%config ")
788 s, matches = c.complete(None, "%config ")
792 nt.assert_in("AliasManager", matches)
789 self.assertIn("AliasManager", matches)
793 s, matches = c.complete(None, "config Ali")
790 s, matches = c.complete(None, "config Ali")
794 nt.assert_list_equal(["AliasManager"], matches)
791 self.assertListEqual(["AliasManager"], matches)
795 s, matches = c.complete(None, "%config Ali")
792 s, matches = c.complete(None, "%config Ali")
796 nt.assert_list_equal(["AliasManager"], matches)
793 self.assertListEqual(["AliasManager"], matches)
797 s, matches = c.complete(None, "config AliasManager")
794 s, matches = c.complete(None, "config AliasManager")
798 nt.assert_list_equal(["AliasManager"], matches)
795 self.assertListEqual(["AliasManager"], matches)
799 s, matches = c.complete(None, "%config AliasManager")
796 s, matches = c.complete(None, "%config AliasManager")
800 nt.assert_list_equal(["AliasManager"], matches)
797 self.assertListEqual(["AliasManager"], matches)
801 s, matches = c.complete(None, "config AliasManager.")
798 s, matches = c.complete(None, "config AliasManager.")
802 nt.assert_in("AliasManager.default_aliases", matches)
799 self.assertIn("AliasManager.default_aliases", matches)
803 s, matches = c.complete(None, "%config AliasManager.")
800 s, matches = c.complete(None, "%config AliasManager.")
804 nt.assert_in("AliasManager.default_aliases", matches)
801 self.assertIn("AliasManager.default_aliases", matches)
805 s, matches = c.complete(None, "config AliasManager.de")
802 s, matches = c.complete(None, "config AliasManager.de")
806 nt.assert_list_equal(["AliasManager.default_aliases"], matches)
803 self.assertListEqual(["AliasManager.default_aliases"], matches)
807 s, matches = c.complete(None, "config AliasManager.de")
804 s, matches = c.complete(None, "config AliasManager.de")
808 nt.assert_list_equal(["AliasManager.default_aliases"], matches)
805 self.assertListEqual(["AliasManager.default_aliases"], matches)
809
806
810 def test_magic_color(self):
807 def test_magic_color(self):
811 ip = get_ipython()
808 ip = get_ipython()
812 c = ip.Completer
809 c = ip.Completer
813
810
814 s, matches = c.complete(None, "colo")
811 s, matches = c.complete(None, "colo")
815 nt.assert_in("%colors", matches)
812 self.assertIn("%colors", matches)
816 s, matches = c.complete(None, "colo")
813 s, matches = c.complete(None, "colo")
817 nt.assert_not_in("NoColor", matches)
814 self.assertNotIn("NoColor", matches)
818 s, matches = c.complete(None, "%colors") # No trailing space
815 s, matches = c.complete(None, "%colors") # No trailing space
819 nt.assert_not_in("NoColor", matches)
816 self.assertNotIn("NoColor", matches)
820 s, matches = c.complete(None, "colors ")
817 s, matches = c.complete(None, "colors ")
821 nt.assert_in("NoColor", matches)
818 self.assertIn("NoColor", matches)
822 s, matches = c.complete(None, "%colors ")
819 s, matches = c.complete(None, "%colors ")
823 nt.assert_in("NoColor", matches)
820 self.assertIn("NoColor", matches)
824 s, matches = c.complete(None, "colors NoCo")
821 s, matches = c.complete(None, "colors NoCo")
825 nt.assert_list_equal(["NoColor"], matches)
822 self.assertListEqual(["NoColor"], matches)
826 s, matches = c.complete(None, "%colors NoCo")
823 s, matches = c.complete(None, "%colors NoCo")
827 nt.assert_list_equal(["NoColor"], matches)
824 self.assertListEqual(["NoColor"], matches)
828
825
829 def test_match_dict_keys(self):
826 def test_match_dict_keys(self):
830 """
827 """
@@ -884,34 +881,34 b' class TestCompleter(unittest.TestCase):'
884
881
885 # check completion at different stages
882 # check completion at different stages
886 _, matches = complete(line_buffer="d[")
883 _, matches = complete(line_buffer="d[")
887 nt.assert_in("'abc'", matches)
884 self.assertIn("'abc'", matches)
888 nt.assert_not_in("'abc']", matches)
885 self.assertNotIn("'abc']", matches)
889
886
890 _, matches = complete(line_buffer="d['")
887 _, matches = complete(line_buffer="d['")
891 nt.assert_in("abc", matches)
888 self.assertIn("abc", matches)
892 nt.assert_not_in("abc']", matches)
889 self.assertNotIn("abc']", matches)
893
890
894 _, matches = complete(line_buffer="d['a")
891 _, matches = complete(line_buffer="d['a")
895 nt.assert_in("abc", matches)
892 self.assertIn("abc", matches)
896 nt.assert_not_in("abc']", matches)
893 self.assertNotIn("abc']", matches)
897
894
898 # check use of different quoting
895 # check use of different quoting
899 _, matches = complete(line_buffer='d["')
896 _, matches = complete(line_buffer='d["')
900 nt.assert_in("abc", matches)
897 self.assertIn("abc", matches)
901 nt.assert_not_in('abc"]', matches)
898 self.assertNotIn('abc"]', matches)
902
899
903 _, matches = complete(line_buffer='d["a')
900 _, matches = complete(line_buffer='d["a')
904 nt.assert_in("abc", matches)
901 self.assertIn("abc", matches)
905 nt.assert_not_in('abc"]', matches)
902 self.assertNotIn('abc"]', matches)
906
903
907 # check sensitivity to following context
904 # check sensitivity to following context
908 _, matches = complete(line_buffer="d[]", cursor_pos=2)
905 _, matches = complete(line_buffer="d[]", cursor_pos=2)
909 nt.assert_in("'abc'", matches)
906 self.assertIn("'abc'", matches)
910
907
911 _, matches = complete(line_buffer="d['']", cursor_pos=3)
908 _, matches = complete(line_buffer="d['']", cursor_pos=3)
912 nt.assert_in("abc", matches)
909 self.assertIn("abc", matches)
913 nt.assert_not_in("abc'", matches)
910 self.assertNotIn("abc'", matches)
914 nt.assert_not_in("abc']", matches)
911 self.assertNotIn("abc']", matches)
915
912
916 # check multiple solutions are correctly returned and that noise is not
913 # check multiple solutions are correctly returned and that noise is not
917 ip.user_ns["d"] = {
914 ip.user_ns["d"] = {
@@ -925,111 +922,110 b' class TestCompleter(unittest.TestCase):'
925 }
922 }
926
923
927 _, matches = complete(line_buffer="d['a")
924 _, matches = complete(line_buffer="d['a")
928 nt.assert_in("abc", matches)
925 self.assertIn("abc", matches)
929 nt.assert_in("abd", matches)
926 self.assertIn("abd", matches)
930 nt.assert_not_in("bad", matches)
927 self.assertNotIn("bad", matches)
931 nt.assert_not_in("abe", matches)
928 self.assertNotIn("abe", matches)
932 nt.assert_not_in("abf", matches)
929 self.assertNotIn("abf", matches)
933 assert not any(m.endswith(("]", '"', "'")) for m in matches), matches
930 assert not any(m.endswith(("]", '"', "'")) for m in matches), matches
934
931
935 # check escaping and whitespace
932 # check escaping and whitespace
936 ip.user_ns["d"] = {"a\nb": None, "a'b": None, 'a"b': None, "a word": None}
933 ip.user_ns["d"] = {"a\nb": None, "a'b": None, 'a"b': None, "a word": None}
937 _, matches = complete(line_buffer="d['a")
934 _, matches = complete(line_buffer="d['a")
938 nt.assert_in("a\\nb", matches)
935 self.assertIn("a\\nb", matches)
939 nt.assert_in("a\\'b", matches)
936 self.assertIn("a\\'b", matches)
940 nt.assert_in('a"b', matches)
937 self.assertIn('a"b', matches)
941 nt.assert_in("a word", matches)
938 self.assertIn("a word", matches)
942 assert not any(m.endswith(("]", '"', "'")) for m in matches), matches
939 assert not any(m.endswith(("]", '"', "'")) for m in matches), matches
943
940
944 # - can complete on non-initial word of the string
941 # - can complete on non-initial word of the string
945 _, matches = complete(line_buffer="d['a w")
942 _, matches = complete(line_buffer="d['a w")
946 nt.assert_in("word", matches)
943 self.assertIn("word", matches)
947
944
948 # - understands quote escaping
945 # - understands quote escaping
949 _, matches = complete(line_buffer="d['a\\'")
946 _, matches = complete(line_buffer="d['a\\'")
950 nt.assert_in("b", matches)
947 self.assertIn("b", matches)
951
948
952 # - default quoting should work like repr
949 # - default quoting should work like repr
953 _, matches = complete(line_buffer="d[")
950 _, matches = complete(line_buffer="d[")
954 nt.assert_in('"a\'b"', matches)
951 self.assertIn('"a\'b"', matches)
955
952
956 # - when opening quote with ", possible to match with unescaped apostrophe
953 # - when opening quote with ", possible to match with unescaped apostrophe
957 _, matches = complete(line_buffer="d[\"a'")
954 _, matches = complete(line_buffer="d[\"a'")
958 nt.assert_in("b", matches)
955 self.assertIn("b", matches)
959
956
960 # need to not split at delims that readline won't split at
957 # need to not split at delims that readline won't split at
961 if "-" not in ip.Completer.splitter.delims:
958 if "-" not in ip.Completer.splitter.delims:
962 ip.user_ns["d"] = {"before-after": None}
959 ip.user_ns["d"] = {"before-after": None}
963 _, matches = complete(line_buffer="d['before-af")
960 _, matches = complete(line_buffer="d['before-af")
964 nt.assert_in("before-after", matches)
961 self.assertIn("before-after", matches)
965
962
966 # check completion on tuple-of-string keys at different stage - on first key
963 # check completion on tuple-of-string keys at different stage - on first key
967 ip.user_ns["d"] = {('foo', 'bar'): None}
964 ip.user_ns["d"] = {('foo', 'bar'): None}
968 _, matches = complete(line_buffer="d[")
965 _, matches = complete(line_buffer="d[")
969 nt.assert_in("'foo'", matches)
966 self.assertIn("'foo'", matches)
970 nt.assert_not_in("'foo']", matches)
967 self.assertNotIn("'foo']", matches)
971 nt.assert_not_in("'bar'", matches)
968 self.assertNotIn("'bar'", matches)
972 nt.assert_not_in("foo", matches)
969 self.assertNotIn("foo", matches)
973 nt.assert_not_in("bar", matches)
970 self.assertNotIn("bar", matches)
974
971
975 # - match the prefix
972 # - match the prefix
976 _, matches = complete(line_buffer="d['f")
973 _, matches = complete(line_buffer="d['f")
977 nt.assert_in("foo", matches)
974 self.assertIn("foo", matches)
978 nt.assert_not_in("foo']", matches)
975 self.assertNotIn("foo']", matches)
979 nt.assert_not_in("foo\"]", matches)
976 self.assertNotIn('foo"]', matches)
980 _, matches = complete(line_buffer="d['foo")
977 _, matches = complete(line_buffer="d['foo")
981 nt.assert_in("foo", matches)
978 self.assertIn("foo", matches)
982
979
983 # - can complete on second key
980 # - can complete on second key
984 _, matches = complete(line_buffer="d['foo', ")
981 _, matches = complete(line_buffer="d['foo', ")
985 nt.assert_in("'bar'", matches)
982 self.assertIn("'bar'", matches)
986 _, matches = complete(line_buffer="d['foo', 'b")
983 _, matches = complete(line_buffer="d['foo', 'b")
987 nt.assert_in("bar", matches)
984 self.assertIn("bar", matches)
988 nt.assert_not_in("foo", matches)
985 self.assertNotIn("foo", matches)
989
986
990 # - does not propose missing keys
987 # - does not propose missing keys
991 _, matches = complete(line_buffer="d['foo', 'f")
988 _, matches = complete(line_buffer="d['foo', 'f")
992 nt.assert_not_in("bar", matches)
989 self.assertNotIn("bar", matches)
993 nt.assert_not_in("foo", matches)
990 self.assertNotIn("foo", matches)
994
991
995 # check sensitivity to following context
992 # check sensitivity to following context
996 _, matches = complete(line_buffer="d['foo',]", cursor_pos=8)
993 _, matches = complete(line_buffer="d['foo',]", cursor_pos=8)
997 nt.assert_in("'bar'", matches)
994 self.assertIn("'bar'", matches)
998 nt.assert_not_in("bar", matches)
995 self.assertNotIn("bar", matches)
999 nt.assert_not_in("'foo'", matches)
996 self.assertNotIn("'foo'", matches)
1000 nt.assert_not_in("foo", matches)
997 self.assertNotIn("foo", matches)
1001
998
1002 _, matches = complete(line_buffer="d['']", cursor_pos=3)
999 _, matches = complete(line_buffer="d['']", cursor_pos=3)
1003 nt.assert_in("foo", matches)
1000 self.assertIn("foo", matches)
1004 assert not any(m.endswith(("]", '"', "'")) for m in matches), matches
1001 assert not any(m.endswith(("]", '"', "'")) for m in matches), matches
1005
1002
1006 _, matches = complete(line_buffer='d[""]', cursor_pos=3)
1003 _, matches = complete(line_buffer='d[""]', cursor_pos=3)
1007 nt.assert_in("foo", matches)
1004 self.assertIn("foo", matches)
1008 assert not any(m.endswith(("]", '"', "'")) for m in matches), matches
1005 assert not any(m.endswith(("]", '"', "'")) for m in matches), matches
1009
1006
1010 _, matches = complete(line_buffer='d["foo","]', cursor_pos=9)
1007 _, matches = complete(line_buffer='d["foo","]', cursor_pos=9)
1011 nt.assert_in("bar", matches)
1008 self.assertIn("bar", matches)
1012 assert not any(m.endswith(("]", '"', "'")) for m in matches), matches
1009 assert not any(m.endswith(("]", '"', "'")) for m in matches), matches
1013
1010
1014 _, matches = complete(line_buffer='d["foo",]', cursor_pos=8)
1011 _, matches = complete(line_buffer='d["foo",]', cursor_pos=8)
1015 nt.assert_in("'bar'", matches)
1012 self.assertIn("'bar'", matches)
1016 nt.assert_not_in("bar", matches)
1013 self.assertNotIn("bar", matches)
1017
1014
1018 # Can complete with longer tuple keys
1015 # Can complete with longer tuple keys
1019 ip.user_ns["d"] = {('foo', 'bar', 'foobar'): None}
1016 ip.user_ns["d"] = {('foo', 'bar', 'foobar'): None}
1020
1017
1021 # - can complete second key
1018 # - can complete second key
1022 _, matches = complete(line_buffer="d['foo', 'b")
1019 _, matches = complete(line_buffer="d['foo', 'b")
1023 nt.assert_in('bar', matches)
1020 self.assertIn("bar", matches)
1024 nt.assert_not_in('foo', matches)
1021 self.assertNotIn("foo", matches)
1025 nt.assert_not_in('foobar', matches)
1022 self.assertNotIn("foobar", matches)
1026
1023
1027 # - can complete third key
1024 # - can complete third key
1028 _, matches = complete(line_buffer="d['foo', 'bar', 'fo")
1025 _, matches = complete(line_buffer="d['foo', 'bar', 'fo")
1029 nt.assert_in('foobar', matches)
1026 self.assertIn("foobar", matches)
1030 nt.assert_not_in('foo', matches)
1027 self.assertNotIn("foo", matches)
1031 nt.assert_not_in('bar', matches)
1028 self.assertNotIn("bar", matches)
1032
1033
1029
1034 def test_dict_key_completion_contexts(self):
1030 def test_dict_key_completion_contexts(self):
1035 """Test expression contexts in which dict key completion occurs"""
1031 """Test expression contexts in which dict key completion occurs"""
@@ -1046,16 +1042,16 b' class TestCompleter(unittest.TestCase):'
1046
1042
1047 def assert_no_completion(**kwargs):
1043 def assert_no_completion(**kwargs):
1048 _, matches = complete(**kwargs)
1044 _, matches = complete(**kwargs)
1049 nt.assert_not_in("abc", matches)
1045 self.assertNotIn("abc", matches)
1050 nt.assert_not_in("abc'", matches)
1046 self.assertNotIn("abc'", matches)
1051 nt.assert_not_in("abc']", matches)
1047 self.assertNotIn("abc']", matches)
1052 nt.assert_not_in("'abc'", matches)
1048 self.assertNotIn("'abc'", matches)
1053 nt.assert_not_in("'abc']", matches)
1049 self.assertNotIn("'abc']", matches)
1054
1050
1055 def assert_completion(**kwargs):
1051 def assert_completion(**kwargs):
1056 _, matches = complete(**kwargs)
1052 _, matches = complete(**kwargs)
1057 nt.assert_in("'abc'", matches)
1053 self.assertIn("'abc'", matches)
1058 nt.assert_not_in("'abc']", matches)
1054 self.assertNotIn("'abc']", matches)
1059
1055
1060 # no completion after string closed, even if reopened
1056 # no completion after string closed, even if reopened
1061 assert_no_completion(line_buffer="d['a'")
1057 assert_no_completion(line_buffer="d['a'")
@@ -1071,7 +1067,7 b' class TestCompleter(unittest.TestCase):'
1071 # greedy flag
1067 # greedy flag
1072 def assert_completion(**kwargs):
1068 def assert_completion(**kwargs):
1073 _, matches = complete(**kwargs)
1069 _, matches = complete(**kwargs)
1074 nt.assert_in("get()['abc']", matches)
1070 self.assertIn("get()['abc']", matches)
1075
1071
1076 assert_no_completion(line_buffer="get()[")
1072 assert_no_completion(line_buffer="get()[")
1077 with greedy_completion():
1073 with greedy_completion():
@@ -1089,25 +1085,25 b' class TestCompleter(unittest.TestCase):'
1089 ip.user_ns["d"] = {"abc": None, b"abd": None}
1085 ip.user_ns["d"] = {"abc": None, b"abd": None}
1090
1086
1091 _, matches = complete(line_buffer="d[")
1087 _, matches = complete(line_buffer="d[")
1092 nt.assert_in("'abc'", matches)
1088 self.assertIn("'abc'", matches)
1093 nt.assert_in("b'abd'", matches)
1089 self.assertIn("b'abd'", matches)
1094
1090
1095 if False: # not currently implemented
1091 if False: # not currently implemented
1096 _, matches = complete(line_buffer="d[b")
1092 _, matches = complete(line_buffer="d[b")
1097 nt.assert_in("b'abd'", matches)
1093 self.assertIn("b'abd'", matches)
1098 nt.assert_not_in("b'abc'", matches)
1094 self.assertNotIn("b'abc'", matches)
1099
1095
1100 _, matches = complete(line_buffer="d[b'")
1096 _, matches = complete(line_buffer="d[b'")
1101 nt.assert_in("abd", matches)
1097 self.assertIn("abd", matches)
1102 nt.assert_not_in("abc", matches)
1098 self.assertNotIn("abc", matches)
1103
1099
1104 _, matches = complete(line_buffer="d[B'")
1100 _, matches = complete(line_buffer="d[B'")
1105 nt.assert_in("abd", matches)
1101 self.assertIn("abd", matches)
1106 nt.assert_not_in("abc", matches)
1102 self.assertNotIn("abc", matches)
1107
1103
1108 _, matches = complete(line_buffer="d['")
1104 _, matches = complete(line_buffer="d['")
1109 nt.assert_in("abc", matches)
1105 self.assertIn("abc", matches)
1110 nt.assert_not_in("abd", matches)
1106 self.assertNotIn("abd", matches)
1111
1107
1112 def test_dict_key_completion_unicode_py3(self):
1108 def test_dict_key_completion_unicode_py3(self):
1113 """Test handling of unicode in dict key completion"""
1109 """Test handling of unicode in dict key completion"""
@@ -1120,20 +1116,20 b' class TestCompleter(unittest.TestCase):'
1120 if sys.platform != "win32":
1116 if sys.platform != "win32":
1121 # Known failure on Windows
1117 # Known failure on Windows
1122 _, matches = complete(line_buffer="d['a\\u05d0")
1118 _, matches = complete(line_buffer="d['a\\u05d0")
1123 nt.assert_in("u05d0", matches) # tokenized after \\
1119 self.assertIn("u05d0", matches) # tokenized after \\
1124
1120
1125 # query using character
1121 # query using character
1126 _, matches = complete(line_buffer="d['a\u05d0")
1122 _, matches = complete(line_buffer="d['a\u05d0")
1127 nt.assert_in("a\u05d0", matches)
1123 self.assertIn("a\u05d0", matches)
1128
1124
1129 with greedy_completion():
1125 with greedy_completion():
1130 # query using escape
1126 # query using escape
1131 _, matches = complete(line_buffer="d['a\\u05d0")
1127 _, matches = complete(line_buffer="d['a\\u05d0")
1132 nt.assert_in("d['a\\u05d0']", matches) # tokenized after \\
1128 self.assertIn("d['a\\u05d0']", matches) # tokenized after \\
1133
1129
1134 # query using character
1130 # query using character
1135 _, matches = complete(line_buffer="d['a\u05d0")
1131 _, matches = complete(line_buffer="d['a\u05d0")
1136 nt.assert_in("d['a\u05d0']", matches)
1132 self.assertIn("d['a\u05d0']", matches)
1137
1133
1138 @dec.skip_without("numpy")
1134 @dec.skip_without("numpy")
1139 def test_struct_array_key_completion(self):
1135 def test_struct_array_key_completion(self):
@@ -1144,8 +1140,8 b' class TestCompleter(unittest.TestCase):'
1144 complete = ip.Completer.complete
1140 complete = ip.Completer.complete
1145 ip.user_ns["d"] = numpy.array([], dtype=[("hello", "f"), ("world", "f")])
1141 ip.user_ns["d"] = numpy.array([], dtype=[("hello", "f"), ("world", "f")])
1146 _, matches = complete(line_buffer="d['")
1142 _, matches = complete(line_buffer="d['")
1147 nt.assert_in("hello", matches)
1143 self.assertIn("hello", matches)
1148 nt.assert_in("world", matches)
1144 self.assertIn("world", matches)
1149 # complete on the numpy struct itself
1145 # complete on the numpy struct itself
1150 dt = numpy.dtype(
1146 dt = numpy.dtype(
1151 [("my_head", [("my_dt", ">u4"), ("my_df", ">u4")]), ("my_data", ">f4", 5)]
1147 [("my_head", [("my_dt", ">u4"), ("my_df", ">u4")]), ("my_data", ">f4", 5)]
@@ -1153,14 +1149,14 b' class TestCompleter(unittest.TestCase):'
1153 x = numpy.zeros(2, dtype=dt)
1149 x = numpy.zeros(2, dtype=dt)
1154 ip.user_ns["d"] = x[1]
1150 ip.user_ns["d"] = x[1]
1155 _, matches = complete(line_buffer="d['")
1151 _, matches = complete(line_buffer="d['")
1156 nt.assert_in("my_head", matches)
1152 self.assertIn("my_head", matches)
1157 nt.assert_in("my_data", matches)
1153 self.assertIn("my_data", matches)
1158 # complete on a nested level
1154 # complete on a nested level
1159 with greedy_completion():
1155 with greedy_completion():
1160 ip.user_ns["d"] = numpy.zeros(2, dtype=dt)
1156 ip.user_ns["d"] = numpy.zeros(2, dtype=dt)
1161 _, matches = complete(line_buffer="d[1]['my_head']['")
1157 _, matches = complete(line_buffer="d[1]['my_head']['")
1162 nt.assert_true(any(["my_dt" in m for m in matches]))
1158 self.assertTrue(any(["my_dt" in m for m in matches]))
1163 nt.assert_true(any(["my_df" in m for m in matches]))
1159 self.assertTrue(any(["my_df" in m for m in matches]))
1164
1160
1165 @dec.skip_without("pandas")
1161 @dec.skip_without("pandas")
1166 def test_dataframe_key_completion(self):
1162 def test_dataframe_key_completion(self):
@@ -1171,8 +1167,8 b' class TestCompleter(unittest.TestCase):'
1171 complete = ip.Completer.complete
1167 complete = ip.Completer.complete
1172 ip.user_ns["d"] = pandas.DataFrame({"hello": [1], "world": [2]})
1168 ip.user_ns["d"] = pandas.DataFrame({"hello": [1], "world": [2]})
1173 _, matches = complete(line_buffer="d['")
1169 _, matches = complete(line_buffer="d['")
1174 nt.assert_in("hello", matches)
1170 self.assertIn("hello", matches)
1175 nt.assert_in("world", matches)
1171 self.assertIn("world", matches)
1176
1172
1177 def test_dict_key_completion_invalids(self):
1173 def test_dict_key_completion_invalids(self):
1178 """Smoke test cases dict key completion can't handle"""
1174 """Smoke test cases dict key completion can't handle"""
@@ -1197,8 +1193,8 b' class TestCompleter(unittest.TestCase):'
1197 ip.user_ns["key_completable"] = KeyCompletable(["qwerty", "qwick"])
1193 ip.user_ns["key_completable"] = KeyCompletable(["qwerty", "qwick"])
1198
1194
1199 _, matches = ip.Completer.complete(line_buffer="key_completable['qw")
1195 _, matches = ip.Completer.complete(line_buffer="key_completable['qw")
1200 nt.assert_in("qwerty", matches)
1196 self.assertIn("qwerty", matches)
1201 nt.assert_in("qwick", matches)
1197 self.assertIn("qwick", matches)
1202
1198
1203 def test_class_key_completion(self):
1199 def test_class_key_completion(self):
1204 ip = get_ipython()
1200 ip = get_ipython()
@@ -1207,8 +1203,8 b' class TestCompleter(unittest.TestCase):'
1207 ip.user_ns["named_instance_class"] = NamedInstanceClass
1203 ip.user_ns["named_instance_class"] = NamedInstanceClass
1208
1204
1209 _, matches = ip.Completer.complete(line_buffer="named_instance_class['qw")
1205 _, matches = ip.Completer.complete(line_buffer="named_instance_class['qw")
1210 nt.assert_in("qwerty", matches)
1206 self.assertIn("qwerty", matches)
1211 nt.assert_in("qwick", matches)
1207 self.assertIn("qwick", matches)
1212
1208
1213 def test_tryimport(self):
1209 def test_tryimport(self):
1214 """
1210 """
@@ -1221,27 +1217,27 b' class TestCompleter(unittest.TestCase):'
1221 def test_aimport_module_completer(self):
1217 def test_aimport_module_completer(self):
1222 ip = get_ipython()
1218 ip = get_ipython()
1223 _, matches = ip.complete("i", "%aimport i")
1219 _, matches = ip.complete("i", "%aimport i")
1224 nt.assert_in("io", matches)
1220 self.assertIn("io", matches)
1225 nt.assert_not_in("int", matches)
1221 self.assertNotIn("int", matches)
1226
1222
1227 def test_nested_import_module_completer(self):
1223 def test_nested_import_module_completer(self):
1228 ip = get_ipython()
1224 ip = get_ipython()
1229 _, matches = ip.complete(None, "import IPython.co", 17)
1225 _, matches = ip.complete(None, "import IPython.co", 17)
1230 nt.assert_in("IPython.core", matches)
1226 self.assertIn("IPython.core", matches)
1231 nt.assert_not_in("import IPython.core", matches)
1227 self.assertNotIn("import IPython.core", matches)
1232 nt.assert_not_in("IPython.display", matches)
1228 self.assertNotIn("IPython.display", matches)
1233
1229
1234 def test_import_module_completer(self):
1230 def test_import_module_completer(self):
1235 ip = get_ipython()
1231 ip = get_ipython()
1236 _, matches = ip.complete("i", "import i")
1232 _, matches = ip.complete("i", "import i")
1237 nt.assert_in("io", matches)
1233 self.assertIn("io", matches)
1238 nt.assert_not_in("int", matches)
1234 self.assertNotIn("int", matches)
1239
1235
1240 def test_from_module_completer(self):
1236 def test_from_module_completer(self):
1241 ip = get_ipython()
1237 ip = get_ipython()
1242 _, matches = ip.complete("B", "from io import B", 16)
1238 _, matches = ip.complete("B", "from io import B", 16)
1243 nt.assert_in("BytesIO", matches)
1239 self.assertIn("BytesIO", matches)
1244 nt.assert_not_in("BaseException", matches)
1240 self.assertNotIn("BaseException", matches)
1245
1241
1246 def test_snake_case_completion(self):
1242 def test_snake_case_completion(self):
1247 ip = get_ipython()
1243 ip = get_ipython()
@@ -1249,8 +1245,8 b' class TestCompleter(unittest.TestCase):'
1249 ip.user_ns["some_three"] = 3
1245 ip.user_ns["some_three"] = 3
1250 ip.user_ns["some_four"] = 4
1246 ip.user_ns["some_four"] = 4
1251 _, matches = ip.complete("s_", "print(s_f")
1247 _, matches = ip.complete("s_", "print(s_f")
1252 nt.assert_in("some_three", matches)
1248 self.assertIn("some_three", matches)
1253 nt.assert_in("some_four", matches)
1249 self.assertIn("some_four", matches)
1254
1250
1255 def test_mix_terms(self):
1251 def test_mix_terms(self):
1256 ip = get_ipython()
1252 ip = get_ipython()
@@ -1274,5 +1270,5 b' class TestCompleter(unittest.TestCase):'
1274 )
1270 )
1275 )
1271 )
1276 _, matches = ip.complete(None, "test.meth(")
1272 _, matches = ip.complete(None, "test.meth(")
1277 nt.assert_in("meth_arg1=", matches)
1273 self.assertIn("meth_arg1=", matches)
1278 nt.assert_not_in("meth2_arg1=", matches)
1274 self.assertNotIn("meth2_arg1=", matches)
General Comments 0
You need to be logged in to leave comments. Login now