コード例 #1
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)
コード例 #2
0
def test_edit_empty(sp, tempfile, setup_edit_patches, cleandir, fake_db,
                    alias_dict):
    """Tests that an alias definition left empty results in the alias being removed.

    This function also tests that the localalias database is deleted after all local aliases have
    been removed.
    """
    edited_cmd_string = ''

    assert os.path.isfile(commands.Command.LOCALALIAS_DB_FILENAME)

    for i, alias in enumerate(alias_dict):
        setup_edit_patches(sp, tempfile, edited_cmd_string)
        cmd = commands.Edit([alias])
        assert len(cmd.alias_dict) == (len(alias_dict) - i)
        cmd()

    assert not os.path.isfile(commands.Command.LOCALALIAS_DB_FILENAME)
コード例 #3
0
ファイル: test_edit.py プロジェクト: xrotwang/localalias
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)
コード例 #4
0
ファイル: test_edit.py プロジェクト: xrotwang/localalias
def edit_cmd(args):
    """Builds and returns 'edit' command."""
    cmd = commands.Edit(args.alias, cmd_args=args.cmd_args, color=args.color)
    return cmd