Ejemplo n.º 1
0
def test_fuzzy_no_prefix():
    # search by distance, no common prefix with any command
    cmd_mgr = CommandManager('cliff.fuzzy')
    app = App('test', '1.0', cmd_mgr)
    cmd_mgr.add_command('user', utils.TestCommand)
    matches = app.get_fuzzy_matches('uesr')
    assert matches == ['user']
Ejemplo n.º 2
0
def test_fuzzy_no_prefix():
    # search by distance, no common prefix with any command
    cmd_mgr = CommandManager('cliff.fuzzy')
    app = App('test', '1.0', cmd_mgr)
    cmd_mgr.add_command('user', utils.TestCommand)
    matches = app.get_fuzzy_matches('uesr')
    assert matches == ['user']
Ejemplo n.º 3
0
def test_fuzzy_same_distance():
    # searched string has the same distance to all commands
    cmd_mgr = CommandManager('cliff.fuzzy')
    app = App('test', '1.0', cmd_mgr)
    cmd_mgr.add_command('user', utils.TestCommand)
    for cmd in cmd_mgr.commands.keys():
        assert damerau_levenshtein('node', cmd, COST) == 8
    matches = app.get_fuzzy_matches('node')
    assert matches == ['complete', 'help', 'user']
Ejemplo n.º 4
0
def test_fuzzy_common_prefix():
    # searched string is a prefix of all commands
    cmd_mgr = CommandManager('cliff.fuzzy')
    app = App('test', '1.0', cmd_mgr)
    cmd_mgr.commands = {}
    cmd_mgr.add_command('user list', utils.TestCommand)
    cmd_mgr.add_command('user show', utils.TestCommand)
    matches = app.get_fuzzy_matches('user')
    assert matches == ['user list', 'user show']
Ejemplo n.º 5
0
def test_fuzzy_same_distance():
    # searched string has the same distance to all commands
    cmd_mgr = CommandManager('cliff.fuzzy')
    app = App('test', '1.0', cmd_mgr)
    cmd_mgr.add_command('user', utils.TestCommand)
    for cmd in cmd_mgr.commands.keys():
        assert damerau_levenshtein('node', cmd, COST) == 8
    matches = app.get_fuzzy_matches('node')
    assert matches == ['complete', 'help', 'user']
Ejemplo n.º 6
0
def test_fuzzy_common_prefix():
    # searched string is a prefix of all commands
    cmd_mgr = CommandManager('cliff.fuzzy')
    app = App('test', '1.0', cmd_mgr)
    cmd_mgr.commands = {}
    cmd_mgr.add_command('user list', utils.TestCommand)
    cmd_mgr.add_command('user show', utils.TestCommand)
    matches = app.get_fuzzy_matches('user')
    assert matches == ['user list', 'user show']
Ejemplo n.º 7
0
def test_fuzzy_no_commands():
    cmd_mgr = CommandManager('cliff.fuzzy')
    app = App('test', '1.0', cmd_mgr)
    cmd_mgr.commands = {}
    matches = app.get_fuzzy_matches('foo')
    assert matches == []
Ejemplo n.º 8
0
def test_fuzzy_no_commands():
    cmd_mgr = CommandManager('cliff.fuzzy')
    app = App('test', '1.0', cmd_mgr)
    cmd_mgr.commands = {}
    matches = app.get_fuzzy_matches('foo')
    assert matches == []