MCPcopy Index your code
hub / github.com/ipython/ipython / test_greedy_completions

Method test_greedy_completions

tests/test_completer.py:596–702  ·  view source on GitHub ↗

Test the capability of the Greedy completer. Most of the test here does not really show off the greedy completer, for proof each of the text below now pass with Jedi. The greedy completer is capable of more. See the :any:`test_dict_key_completion_contexts`

(self)

Source from the content-addressed store, hash-verified

594 reason="Parso does not yet parse 3.13",
595 )
596 def test_greedy_completions(self):
597 """
598 Test the capability of the Greedy completer.
599
600 Most of the test here does not really show off the greedy completer, for proof
601 each of the text below now pass with Jedi. The greedy completer is capable of more.
602
603 See the :any:`test_dict_key_completion_contexts`
604
605 """
606 ip = get_ipython()
607 ip.ex("a=list(range(5))")
608 ip.ex("b,c = 1, 1.2")
609 ip.ex("d = {'a b': str}")
610 ip.ex("x=y='a'")
611 _, c = ip.complete(".", line="a[0].")
612 self.assertFalse(".real" in c, "Shouldn't have completed on a[0]: %s" % c)
613
614 def _(line, cursor_pos, expect, message, completion):
615 with greedy_completion(), provisionalcompleter():
616 ip.Completer.use_jedi = False
617 _, c = ip.complete(".", line=line, cursor_pos=cursor_pos)
618 self.assertIn(expect, c, message % c)
619
620 ip.Completer.use_jedi = True
621 with provisionalcompleter():
622 completions = ip.Completer.completions(line, cursor_pos)
623 self.assertIn(completion, list(completions))
624
625 with provisionalcompleter():
626 _(
627 "a[0].",
628 5,
629 ".real",
630 "Should have completed on a[0].: %s",
631 Completion(5, 5, "real"),
632 )
633 _(
634 "a[0].r",
635 6,
636 ".real",
637 "Should have completed on a[0].r: %s",
638 Completion(5, 6, "real"),
639 )
640 _(
641 "a[0].from_",
642 10,
643 ".from_bytes",
644 "Should have completed on a[0].from_: %s",
645 Completion(5, 10, "from_bytes"),
646 )
647 _(
648 "assert str.star",
649 14,
650 ".startswith",
651 "Should have completed on `assert str.star`: %s",
652 Completion(11, 14, "startswith"),
653 )

Callers

nothing calls this directly

Calls 5

get_ipythonFunction · 0.90
provisionalcompleterFunction · 0.90
CompletionClass · 0.90
exMethod · 0.80
completeMethod · 0.45

Tested by

no test coverage detected