Esempio n. 1
0
def test_remove(tmp_path):
    (tmp_path / 'home/.config/fish').mkdir(parents=True)

    pearl_env = mock.Mock()
    pearl_env.home = (tmp_path / 'pearlhome')
    pearl_env.home.mkdir(parents=True)

    (tmp_path / 'home/.bashrc').write_text(
        "source {}/boot/sh/pearl.sh\n".format(pearl_env.home))
    (tmp_path / 'home/.zshrc').write_text(
        "source {}/boot/sh/pearl.sh\n".format(pearl_env.home))
    (tmp_path / 'home/.config/fish/config.fish').write_text(
        "source {}/boot/fish/pearl.fish\n".format(pearl_env.home))
    (tmp_path / 'home/.vimrc').write_text(
        "source {}/boot/vim/pearl.vim\n".format(pearl_env.home))
    (tmp_path / 'home/.emacs').write_text(
        "(load-file \"{}/boot/emacs/pearl.el\")\n".format(pearl_env.home))

    pearl_env.packages = {}

    with mock.patch(_MODULE_UNDER_TEST + '.os') as os_mock, \
            mock.patch('builtins.input') as input_mock:
        os_mock.environ = {'HOME': str(tmp_path / 'home')}
        input_mock.return_value = 'Y'
        remove_pearl(pearl_env, SysArgs())

        assert not pearl_env.home.exists()

        assert (tmp_path / 'home/.bashrc').read_text() == ""
        assert (tmp_path / 'home/.zshrc').read_text() == ""
        assert (tmp_path / 'home/.config/fish/config.fish').read_text() == ""
        assert (tmp_path / 'home/.vimrc').read_text() == ""
        assert (tmp_path / 'home/.emacs').read_text() == ""
Esempio n. 2
0
def _pearl(pearl_env: PearlEnvironment, args):
    command = PearlCommand.from_string(args.command)
    if hasattr(args, 'packages'):
        args.packages = _extract_packages(pearl_env, command, args)

    if command == PearlCommand.INIT:
        syst.init_pearl(pearl_env, args)
    elif command == PearlCommand.INSTALL:
        pack.install_packages(pearl_env, args)
    elif command == PearlCommand.UPDATE:
        if not args.packages:
            syst.update_pearl(pearl_env, args)
        else:
            pack.update_packages(pearl_env, args)
    elif command == PearlCommand.REMOVE:
        if not args.packages:
            syst.remove_pearl(pearl_env, args)
        else:
            pack.remove_packages(pearl_env, args)
    elif command == PearlCommand.EMERGE:
        pack.emerge_packages(pearl_env, args)
    elif command == PearlCommand.INFO:
        pack.info_packages(pearl_env, args)
    elif command == PearlCommand.LIST:
        pack.list_packages(pearl_env, args)
    elif command == PearlCommand.SEARCH:
        pack.list_packages(pearl_env, args)
    elif command == PearlCommand.CREATE:
        pack.create_package(pearl_env, args)
    else:
        raise ValueError(
            'No command specified. Run "pearl --help" for list of commands.')
Esempio n. 3
0
def test_remove_no_confirm(tmp_path):
    (tmp_path / 'home/.config/fish').mkdir(parents=True)

    pearl_env = mock.Mock()
    pearl_env.home = (tmp_path / 'pearlhome')
    pearl_env.home.mkdir(parents=True)

    (tmp_path / 'home/.bashrc').write_text(
        "source {}/boot/sh/pearl.sh\n".format(pearl_env.home))
    (tmp_path / 'home/.zshrc').write_text(
        "source {}/boot/sh/pearl.sh\n".format(pearl_env.home))
    (tmp_path / 'home/.config/fish/config.fish').write_text(
        "source {}/boot/fish/pearl.fish\n".format(pearl_env.home))
    (tmp_path / 'home/.vimrc').write_text(
        "source {}/boot/vim/pearl.vim\n".format(pearl_env.home))
    (tmp_path / 'home/.emacs').write_text(
        "(load-file \"{}/boot/emacs/pearl.el\")\n".format(pearl_env.home))

    pearl_env.packages = {}

    with mock.patch(_MODULE_UNDER_TEST + '.os') as os_mock:
        os_mock.environ = {'HOME': str(tmp_path / 'home')}
        remove_pearl(pearl_env, args=SysArgs(no_confirm=True, verbose=0))

        assert pearl_env.home.exists()

        assert (tmp_path / 'home/.bashrc').read_text() == \
            "source {}/boot/sh/pearl.sh\n".format(pearl_env.home)
        assert (tmp_path / 'home/.zshrc').read_text() == \
            "source {}/boot/sh/pearl.sh\n".format(pearl_env.home)
        assert (tmp_path / 'home/.config/fish/config.fish').read_text() == \
            "source {}/boot/fish/pearl.fish\n".format(pearl_env.home)
        assert (tmp_path / 'home/.vimrc').read_text() == \
            "source {}/boot/vim/pearl.vim\n".format(pearl_env.home)
        assert (tmp_path / 'home/.emacs').read_text() == \
            "(load-file \"{}/boot/emacs/pearl.el\")\n".format(pearl_env.home)