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