Beispiel #1
0
def test_remove_package_no_confirm(tmp_path):
    home_dir = create_pearl_home(tmp_path)

    hooks_sh_script = """
    pre_remove() {{
        if ask "Are you sure?" "Y"
        then
            echo "YES" > hotexamples_com/result
        else
            echo "NO" > hotexamples_com/result
        fi

        local choice=$(choose "What?" "banana" "apple" "banana" "orange")
        echo "$choice" >> hotexamples_com/result
        return 0
    }}
    """.format(homedir=home_dir)

    builder = PackageTestBuilder(home_dir)
    builder.add_local_package(tmp_path, hooks_sh_script, is_installed=True)
    packages = builder.build()
    package = packages['repo-test']['pkg-test']

    pearl_env = create_pearl_env(home_dir, packages)

    remove_package(pearl_env, package, PackageArgs(no_confirm=True, verbose=False))

    assert (home_dir / 'result').read_text() == "YES\nbanana\n"
Beispiel #2
0
def test_remove_package(tmp_path):
    home_dir = create_pearl_home(tmp_path)

    hooks_sh_script = """
    pre_remove() {{
        echo $PWD > hotexamples_com/result
        echo $PEARL_HOME >> hotexamples_com/result
        echo $PEARL_PKGDIR >> hotexamples_com/result
        echo $PEARL_PKGVARDIR >> hotexamples_com/result
        echo $PEARL_PKGNAME >> hotexamples_com/result
        echo $PEARL_PKGREPONAME >> hotexamples_com/result
        return 0
    }}
    """.format(homedir=home_dir)

    builder = PackageTestBuilder(home_dir)
    builder.add_local_package(tmp_path, hooks_sh_script, is_installed=True)
    packages = builder.build()
    package = packages['repo-test']['pkg-test']

    pearl_env = create_pearl_env(home_dir, packages)

    remove_package(pearl_env, package, PackageArgs(verbose=2))

    assert not (home_dir / 'packages/repo-test/pkg-test/').exists()

    expected_result = """{}\n{}\n{}\n{}\n{}\n{}\n""".format(
        package.dir, home_dir,
        package.dir, package.vardir, package.name, package.repo_name
    )
    assert (home_dir / 'result').read_text() == expected_result
Beispiel #3
0
def test_remove_package_not_installed(tmp_path):
    home_dir = create_pearl_home(tmp_path)

    builder = PackageTestBuilder(home_dir)
    builder.add_local_package(tmp_path, "", is_installed=False)
    packages = builder.build()
    package = packages['repo-test']['pkg-test']
    pearl_env = create_pearl_env(home_dir, packages)

    with pytest.raises(PackageNotInstalledError):
        remove_package(pearl_env, package, PackageArgs())
Beispiel #4
0
def test_remove_package_raise_hook(tmp_path):
    home_dir = create_pearl_home(tmp_path)
    hooks_sh_script = """
    pre_remove() {{
        command-notfound
        return 0
    }}
    """

    builder = PackageTestBuilder(home_dir)
    builder.add_local_package(tmp_path, hooks_sh_script, is_installed=True)
    packages = builder.build()
    package = packages['repo-test']['pkg-test']
    pearl_env = create_pearl_env(home_dir, packages)

    with pytest.raises(HookFunctionError):
        remove_package(pearl_env, package, PackageArgs())
Beispiel #5
0
def test_remove_package_forced(tmp_path):
    home_dir = create_pearl_home(tmp_path)

    hooks_sh_script = """
    pre_remove() {{
        return 11
    }}
    """.format(homedir=home_dir)

    builder = PackageTestBuilder(home_dir)
    builder.add_local_package(tmp_path, hooks_sh_script, is_installed=True)
    packages = builder.build()
    package = packages['repo-test']['pkg-test']

    pearl_env = create_pearl_env(home_dir, packages)

    remove_package(pearl_env, package, args=PackageArgs(False, 0, force=True))

    assert not (home_dir / 'packages/repo-test/pkg-test/').exists()