Ejemplo n.º 1
0
def test_omit__names():
    # also happens to test IPCompleter as a configurable
    ip = get_ipython()
    ip._hidden_attr = 1
    ip._x = {}
    c = ip.Completer
    ip.ex('ip=get_ipython()')
    cfg = Config()
    cfg.IPCompleter.omit__names = 0
    c.update_config(cfg)
    with provisionalcompleter():
        s,matches = c.complete('ip.')
        completions = set(c.completions('ip.', 3))

        nt.assert_in('ip.__str__', matches)
        nt.assert_in(Completion(3, 3, '__str__'), completions)
        
        nt.assert_in('ip._hidden_attr', matches)
        nt.assert_in(Completion(3,3, "_hidden_attr"), completions)


    cfg = Config()
    cfg.IPCompleter.omit__names = 1
    c.update_config(cfg)
    with provisionalcompleter():
        s,matches = c.complete('ip.')
        completions = set(c.completions('ip.', 3))

        nt.assert_not_in('ip.__str__', matches)
        nt.assert_not_in(Completion(3,3,'__str__'), completions)

        # nt.assert_in('ip._hidden_attr', matches)
        nt.assert_in(Completion(3,3, "_hidden_attr"), completions)

    cfg = Config()
    cfg.IPCompleter.omit__names = 2
    c.update_config(cfg)
    with provisionalcompleter():
        s,matches = c.complete('ip.')
        completions = set(c.completions('ip.', 3))

        nt.assert_not_in('ip.__str__', matches)
        nt.assert_not_in(Completion(3,3,'__str__'), completions)

        nt.assert_not_in('ip._hidden_attr', matches)
        nt.assert_not_in(Completion(3,3, "_hidden_attr"), completions)

    with provisionalcompleter():
        s,matches = c.complete('ip._x.')
        completions = set(c.completions('ip._x.', 6))

        nt.assert_in('ip._x.keys', matches)
        nt.assert_in(Completion(6,6, "keys"), completions)

    del ip._hidden_attr
    del ip._x
Ejemplo n.º 2
0
def test_omit__names():
    # also happens to test IPCompleter as a configurable
    ip = get_ipython()
    ip._hidden_attr = 1
    ip._x = {}
    c = ip.Completer
    ip.ex('ip=get_ipython()')
    cfg = Config()
    cfg.IPCompleter.omit__names = 0
    c.update_config(cfg)
    with provisionalcompleter():
        s, matches = c.complete('ip.')
        completions = set(c.completions('ip.', 3))

        nt.assert_in('ip.__str__', matches)
        nt.assert_in(Completion(3, 3, '__str__'), completions)

        nt.assert_in('ip._hidden_attr', matches)
        nt.assert_in(Completion(3, 3, "_hidden_attr"), completions)

    cfg = Config()
    cfg.IPCompleter.omit__names = 1
    c.update_config(cfg)
    with provisionalcompleter():
        s, matches = c.complete('ip.')
        completions = set(c.completions('ip.', 3))

        nt.assert_not_in('ip.__str__', matches)
        nt.assert_not_in(Completion(3, 3, '__str__'), completions)

        # nt.assert_in('ip._hidden_attr', matches)
        nt.assert_in(Completion(3, 3, "_hidden_attr"), completions)

    cfg = Config()
    cfg.IPCompleter.omit__names = 2
    c.update_config(cfg)
    with provisionalcompleter():
        s, matches = c.complete('ip.')
        completions = set(c.completions('ip.', 3))

        nt.assert_not_in('ip.__str__', matches)
        nt.assert_not_in(Completion(3, 3, '__str__'), completions)

        nt.assert_not_in('ip._hidden_attr', matches)
        nt.assert_not_in(Completion(3, 3, "_hidden_attr"), completions)

    with provisionalcompleter():
        s, matches = c.complete('ip._x.')
        completions = set(c.completions('ip._x.', 6))

        nt.assert_in('ip._x.keys', matches)
        nt.assert_in(Completion(6, 6, "keys"), completions)

    del ip._hidden_attr
    del ip._x
Ejemplo n.º 3
0
def test_greedy_completions():
    """
    Test the capability of the Greedy completer. 

    Most of the test here do not really show off the greedy completer, for proof
    each of the text bellow now pass with Jedi. The greedy completer is capable of more. 

    See the :any:`test_dict_key_completion_contexts`

    """
    ip = get_ipython()
    ip.ex('a=list(range(5))')
    _,c = ip.complete('.',line='a[0].')
    nt.assert_false('.real' in c,
                    "Shouldn't have completed on a[0]: %s"%c)
    with greedy_completion(), provisionalcompleter():
        def _(line, cursor_pos, expect, message, completion):
            _,c = ip.complete('.', line=line, cursor_pos=cursor_pos)
            with provisionalcompleter():
                completions = ip.Completer.completions(line, cursor_pos)
            nt.assert_in(expect, c, message%c)
            nt.assert_in(completion, completions)

        yield _, 'a[0].', 5, 'a[0].real', "Should have completed on a[0].: %s", Completion(5,5, 'real')
        yield _, 'a[0].r', 6, 'a[0].real', "Should have completed on a[0].r: %s", Completion(5,6, 'real')

        if sys.version_info > (3, 4):
            yield _, 'a[0].from_', 10, 'a[0].from_bytes', "Should have completed on a[0].from_: %s", Completion(5, 10, 'from_bytes')
Ejemplo n.º 4
0
 def _test_complete(reason, s, comp, start=None, end=None):
     l = len(s)
     start = start if start is not None else l
     end = end if end is not None else l
     with provisionalcompleter():
         completions = set(ip.Completer.completions(s, l))
         assert_in(Completion(start, end, comp), completions, reason)
Ejemplo n.º 5
0
def test_greedy_completions():
    """
    Test the capability of the Greedy completer. 

    Most of the test here do not really show off the greedy completer, for proof
    each of the text bellow now pass with Jedi. The greedy completer is capable of more. 

    See the :any:`test_dict_key_completion_contexts`

    """
    ip = get_ipython()
    ip.ex('a=list(range(5))')
    _, c = ip.complete('.', line='a[0].')
    nt.assert_false('.real' in c, "Shouldn't have completed on a[0]: %s" % c)
    with greedy_completion(), provisionalcompleter():

        def _(line, cursor_pos, expect, message, completion):
            _, c = ip.complete('.', line=line, cursor_pos=cursor_pos)
            with provisionalcompleter():
                completions = ip.Completer.completions(line, cursor_pos)
            nt.assert_in(expect, c, message % c)
            nt.assert_in(completion, completions)

        yield _, 'a[0].', 5, 'a[0].real', "Should have completed on a[0].: %s", Completion(
            5, 5, 'real')
        yield _, 'a[0].r', 6, 'a[0].real', "Should have completed on a[0].r: %s", Completion(
            5, 6, 'real')

        if sys.version_info > (3, 4):
            yield _, 'a[0].from_', 10, 'a[0].from_bytes', "Should have completed on a[0].from_: %s", Completion(
                5, 10, 'from_bytes')
Ejemplo n.º 6
0
 def _test_complete(reason, s, comp, start=None, end=None):
     l = len(s)
     start = start if start is not None else l
     end = end if end is not None else l
     with provisionalcompleter():
         completions = set(ip.Completer.completions(s, l))
         assert_in(Completion(start, end, comp), completions, reason)
Ejemplo n.º 7
0
def test_completion_have_signature():
    """
    Lets make sure jedi is capable of pulling out the signature of the function we are completing.
    """
    ip = get_ipython()
    with provisionalcompleter():
        completions = ip.Completer.completions('ope', 3)
        c = next(completions)  # should be `open`
    assert 'file' in c.signature, "Signature of function was not found by completer"
    assert 'encoding' in c.signature, "Signature of function was not found by completer"
Ejemplo n.º 8
0
def test_completion_have_signature():
    """
    Lets make sure jedi is capable of pulling out the signature of the function we are completing.
    """
    ip = get_ipython()
    with provisionalcompleter():
        completions = ip.Completer.completions('ope', 3)
        c = next(completions)  # should be `open`
    assert 'file' in c.signature, "Signature of function was not found by completer"
    assert 'encoding' in c.signature, "Signature of function was not found by completer"
Ejemplo n.º 9
0
def test_deduplicate_completions():
    """
    Test that completions are correctly deduplicated (even if ranges are not the same)
    """
    ip = get_ipython()
    ip.ex(textwrap.dedent('''
    class Z:
        zoo = 1
    '''))
    with provisionalcompleter():
        l = list(_deduplicate_completions('Z.z', ip.Completer.completions('Z.z', 3)))

    assert len(l) == 1, 'Completions (Z.z<tab>) correctly deduplicate: %s ' % l
    assert l[0].text == 'zoo'  # and not `it.accumulate`
Ejemplo n.º 10
0
def test_deduplicate_completions():
    """
    Test that completions are correctly deduplicated (even if ranges are not the same)
    """
    ip = get_ipython()
    ip.ex(textwrap.dedent('''
    class Z:
        zoo = 1
    '''))
    with provisionalcompleter():
        l = list(
            _deduplicate_completions('Z.z', ip.Completer.completions('Z.z',
                                                                     3)))

    assert len(l) == 1, 'Completions (Z.z<tab>) correctly deduplicate: %s ' % l
    assert l[0].text == 'zoo'  # and not `it.accumulate`
Ejemplo n.º 11
0
 def _(line, cursor_pos, expect, message, completion):
     _,c = ip.complete('.', line=line, cursor_pos=cursor_pos)
     with provisionalcompleter():
         completions = ip.Completer.completions(line, cursor_pos)
     nt.assert_in(expect, c, message%c)
     nt.assert_in(completion, completions)
Ejemplo n.º 12
0
 def _test_not_complete(reason, s, comp):
     l = len(s)
     with provisionalcompleter():
         completions = set(ip.Completer.completions(s, l))
         assert_not_in(Completion(l, l, comp), completions, reason)
Ejemplo n.º 13
0
 def _(line, cursor_pos, expect, message, completion):
     _, c = ip.complete('.', line=line, cursor_pos=cursor_pos)
     with provisionalcompleter():
         completions = ip.Completer.completions(line, cursor_pos)
     nt.assert_in(expect, c, message % c)
     nt.assert_in(completion, completions)
Ejemplo n.º 14
0
 def _test_not_complete(reason, s, comp):
     l = len(s)
     with provisionalcompleter():
         completions = set(ip.Completer.completions(s, l))
         assert_not_in(Completion(l, l, comp), completions, reason)