Пример #1
0
def test_edit(edit_alias, cleandir, fake_db, edit_cmd):
    """Tests edit command."""
    edited_cmd_string = 'TEST COMMAND STRING'
    edit_alias.return_value = edited_cmd_string
    edit_cmd()
    loaded_aliases = shared.load_aliases()
    assert loaded_aliases[edit_cmd.alias] == edited_cmd_string
Пример #2
0
def test_add(edit_alias, cleandir, add_cmd, alias_dict):
    """Tests add command."""
    alias_cmd_string = alias_dict[add_cmd.alias]
    edit_alias.return_value = alias_cmd_string
    add_cmd()

    loaded_aliases = shared.load_aliases()
    assert loaded_aliases == {add_cmd.alias: alias_cmd_string}
    assert len(loaded_aliases) == 1
Пример #3
0
def test_add(sp, tempfile, setup_edit_patches, cleandir, add_cmd, alias_dict):
    """Tests add command."""
    alias_cmd_string = alias_dict[add_cmd.alias]
    setup_edit_patches(sp, tempfile, alias_cmd_string)
    add_cmd()

    loaded_aliases = shared.load_aliases()
    assert loaded_aliases == {add_cmd.alias: alias_cmd_string}
    assert len(loaded_aliases) == 1
Пример #4
0
def test_edit(sp, tempfile, setup_edit_patches, cleandir, fake_db, edit_cmd):
    """Tests edit command."""
    edited_cmd_string = 'TEST COMMAND STRING'
    setup_edit_patches(sp, tempfile, edited_cmd_string)

    edit_cmd()

    loaded_aliases = shared.load_aliases()
    assert loaded_aliases[edit_cmd.alias] == '{} "$@"'.format(
        edited_cmd_string)
Пример #5
0
def test_edit_format(sp, tempfile, setup_edit_patches, cleandir, fake_db,
                     alias_dict):
    """Tests that the edit command reformats command strings when needed."""
    edited_cmd_string = 'EDITED CMD STRING'

    setup_edit_patches(sp, tempfile, edited_cmd_string)

    some_alias = list(alias_dict.keys())[0]
    cmd = commands.Edit([some_alias])
    cmd()

    loaded_aliases = shared.load_aliases()
    assert loaded_aliases[some_alias] == '{} "$@"'.format(edited_cmd_string)
Пример #6
0
def test_rename_overwrite(getch, y_or_n, cleandir, fake_db, alias_dict):
    """Test that rename overwrites existing function names properly."""
    getch.side_effect = lambda x: y_or_n
    fnames = [name for name in alias_dict]
    OLD, NEW = fnames[0], fnames[1]
    cmd = commands.Rename([OLD, NEW])
    cmd()

    loaded_aliases = shared.load_aliases()
    if y_or_n == "y":
        cmd_string = alias_dict[OLD]
    else:
        cmd_string = alias_dict[NEW]

    assert loaded_aliases[NEW] == cmd_string
Пример #7
0
def test_edit_format(sp, tempfile, cleandir, fake_db, alias_dict):
    """Tests that the edit command reformats command strings when needed."""
    edited_cmd_string = 'EDITED CMD STRING'

    tmpfilename = '/tmp/test_edit_format.txt'
    with open(tmpfilename, 'w') as f:
        f.write(edited_cmd_string)

    fileMock = mock.Mock(name='fileMock')
    fileMock.name = tmpfilename
    tempfile.NamedTemporaryFile = mock.Mock()
    tempfile.NamedTemporaryFile.return_value = fileMock

    some_alias = list(alias_dict.keys())[0]
    edit_cmd = commands.Edit(some_alias)
    edit_cmd()

    loaded_aliases = shared.load_aliases()
    assert loaded_aliases[some_alias] == '{} $@'.format(edited_cmd_string)
Пример #8
0
def test_rename(cleandir, fake_db, rename_cmd, alias_dict):
    """Test rename command."""
    old_cmd_string = alias_dict[rename_cmd.alias]
    rename_cmd()
    loaded_aliases = shared.load_aliases()
    assert loaded_aliases[rename_cmd.args[0]] == old_cmd_string
Пример #9
0
def test_remove(cleandir, fake_db, remove_cmd):
    """Tests remove command."""
    remove_cmd()
    loaded_aliases = shared.load_aliases()
    assert remove_cmd.alias not in loaded_aliases