示例#1
0
def test_complete_attribute():
    compl = Completer({'a': None}, ConfigForTest)
    assert compl.attr_matches('a.') == ['a.__']
    matches = compl.attr_matches('a.__')
    assert 'a.__class__' not in matches
    assert '__class__' in matches
    assert compl.attr_matches('a.__class') == ['a.__class__']
示例#2
0
def test_autocomplete():
    class A:
        aaa = None
        abc_1 = None
        abc_2 = None
        abc_3 = None
        bbb = None

    compl = Completer({'A': A}, ConfigForTest)
    #
    # in this case, we want to display all attributes which start with
    # 'a'. MOREOVER, we also include a space to prevent readline to
    # automatically insert the common prefix (which will the the ANSI escape
    # sequence if we use colors)
    matches = compl.attr_matches('A.a')
    assert sorted(matches) == [' ', 'aaa', 'abc_1', 'abc_2', 'abc_3']
    #
    # IF there is an actual common prefix, we return just it, so that readline
    # will insert it into place
    matches = compl.attr_matches('A.ab')
    assert matches == ['A.abc_']
    #
    # finally, at the next TAB, we display again all the completions available
    # for this common prefix. Agai, we insert a spurious space to prevent the
    # automatic completion of ANSI sequences
    matches = compl.attr_matches('A.abc_')
    assert sorted(matches) == [' ', 'abc_1', 'abc_2', 'abc_3']
示例#3
0
def test_complete_with_indexer():
    compl = Completer({'lst': [None, 2, 3]}, ConfigForTest)
    assert compl.attr_matches('lst[0].') == ['lst[0].__']
    matches = compl.attr_matches('lst[0].__')
    assert 'lst[0].__class__' not in matches
    assert '__class__' in matches
    assert compl.attr_matches('lst[0].__class') == ['lst[0].__class__']
示例#4
0
def test_complete_attribute_prefix():
    class C(object):
        attr = 1
        _attr = 2
        __attr__attr = 3
    compl = Completer({'a': C}, ConfigForTest)
    assert compl.attr_matches('a.') == ['attr', 'mro']
    assert compl.attr_matches('a._') == ['_C__attr__attr', '_attr']
    matches = compl.attr_matches('a.__')
    assert 'a.__class__' not in matches
    assert '__class__' in matches
    assert compl.attr_matches('a.__class') == ['a.__class__']

    compl = Completer({'a': None}, ConfigForTest)
    assert compl.attr_matches('a._') == ['a.__']
示例#5
0
def test_does_not_color_single_match():
    class obj:
        msgs = []

    compl = Completer({'obj': obj}, ColorConfig)
    matches = compl.attr_matches('obj.msgs')
    assert matches == ['obj.msgs']
示例#6
0
def test_unicode_in___dir__():
    class Foo(object):
        def __dir__(self):
            return [u'hello', 'world']

    compl = Completer({'a': Foo()}, ConfigForTest)
    matches = compl.attr_matches('a.')
    assert matches == ['hello', 'world']
    assert type(matches[0]) is str
示例#7
0
def test_complete_attribute_colored():
    compl = Completer({'a': 42}, ColorConfig)
    matches = compl.attr_matches('a.__')
    assert len(matches) > 2
    expected_part = Color.set('31', '__class__')
    for match in matches:
        if expected_part in match:
            break
    else:
        assert False
    assert ' ' in matches
示例#8
0
def test_complete_attribute_colored():
    compl = Completer({'a': 42}, ColorConfig)
    matches = compl.attr_matches('a.__')
    assert len(matches) > 2
    expected_color = compl.config.color_by_type.get(type(compl.__class__))
    assert expected_color == '35;01'
    expected_part = Color.set(expected_color, '__class__')
    for match in matches:
        if expected_part in match:
            break
    else:
        assert False, matches
    assert ' ' in matches
示例#9
0
def test_complete_attribute_colored():
    class ColorConfig(DefaultConfig):
        use_colors = True
        color_by_type = {type: '31'}

    compl = Completer({'a': 42}, ColorConfig)
    matches = compl.attr_matches('a.__')
    for match in matches:
        if Color.set('31', '__class__') in match:
            break
    else:
        assert False
    assert ' ' in matches
示例#10
0
def test_complete_function_skipped():
    compl = Completer({'str': str}, ConfigForTest)
    assert compl.attr_matches('str.split().') == []
示例#11
0
def test_complete_invalid_attr():
    compl = Completer({'str': str}, ConfigForTest)
    assert compl.attr_matches('str.xx') == []
示例#12
0
def test_complete_exception():
    compl = Completer({}, ConfigForTest)
    assert compl.attr_matches('xxx.') == []