def test_update_local_package_forced(tmp_path): home_dir = create_pearl_home(tmp_path) hooks_sh_script = """ pre_update() {{ return 11 }} post_update() {{ return 12 }} """.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) update_package(pearl_env, package, args=PackageArgs(False, 0, force=True)) with pytest.raises(HookFunctionError): update_package(pearl_env, package, args=PackageArgs(False, 0, force=False)) assert (home_dir / 'packages/repo-test/pkg-test/pearl-config/hooks.sh').is_file()
def test_update_package_git_url_changed(tmp_path): home_dir = create_pearl_home(tmp_path) builder = PackageTestBuilder(home_dir) builder.add_git_package( "", is_installed=True, url='https://github.com/new-pkg', git_url='https://github.com/pkg', ) packages = builder.build() package = packages['repo-test']['pkg-test'] pearl_env = create_pearl_env(home_dir, packages) with mock.patch(_MODULE_UNDER_TEST + ".run_pearl_bash") as run_mock, \ mock.patch(_MODULE_UNDER_TEST + ".remove_package") as remove_mock, \ mock.patch(_MODULE_UNDER_TEST + ".install_package") as install_mock: update_package(pearl_env, package, PackageArgs()) expected_calls = [ mock.call(mock.ANY, pearl_env, enable_errexit=True, enable_xtrace=False, input=None), mock.call(f'\nupdate_git_repo {tmp_path}/home/packages/repo-test/pkg-test "" true\n', pearl_env, input=None), mock.call(mock.ANY, pearl_env, enable_errexit=True, enable_xtrace=False, input=None) ] run_mock.assert_has_calls(expected_calls) assert remove_mock.call_count == 1 assert install_mock.call_count == 1
def test_update_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): update_package(pearl_env, package, PackageArgs())
def test_update_package_git_url_not_changed(tmp_path): home_dir = create_pearl_home(tmp_path) builder = PackageTestBuilder(home_dir) builder.add_git_package("", is_installed=True) packages = builder.build() package = packages['repo-test']['pkg-test'] pearl_env = create_pearl_env(home_dir, packages) with mock.patch(_MODULE_UNDER_TEST + ".run_pearl_bash") as run_mock: out_process = namedtuple('OutProcess', ['stdout'])(package.url) run_mock.return_value = out_process update_package(pearl_env, package, PackageArgs()) assert run_mock.call_count == 4
def test_update_package_git_url_not_changed(tmp_path): home_dir = create_pearl_home(tmp_path) builder = PackageTestBuilder(home_dir) builder.add_git_package("", is_installed=True) packages = builder.build() package = packages['repo-test']['pkg-test'] pearl_env = create_pearl_env(home_dir, packages) with mock.patch(_MODULE_UNDER_TEST + ".run_pearl_bash"), \ mock.patch(_MODULE_UNDER_TEST + ".remove_package") as remove_mock, \ mock.patch(_MODULE_UNDER_TEST + ".install_package") as install_mock: update_package(pearl_env, package, PackageArgs()) assert remove_mock.call_count == 0 assert install_mock.call_count == 0
def test_update_package_raise_hook(tmp_path): home_dir = create_pearl_home(tmp_path) hooks_sh_script = """ pre_update() {{ 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): update_package(pearl_env, package, PackageArgs())
def test_update_local_package(tmp_path): home_dir = create_pearl_home(tmp_path) hooks_sh_script = """ pre_update() {{ 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 }} post_update() {{ echo $PWD > hotexamples_com/result2 echo $PEARL_HOME >> hotexamples_com/result2 echo $PEARL_PKGDIR >> hotexamples_com/result2 echo $PEARL_PKGVARDIR >> hotexamples_com/result2 echo $PEARL_PKGNAME >> hotexamples_com/result2 echo $PEARL_PKGREPONAME >> hotexamples_com/result2 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) update_package(pearl_env, package, PackageArgs(verbose=2)) assert (home_dir / 'packages/repo-test/pkg-test/pearl-config/hooks.sh').is_file() 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 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 / 'result2').read_text() == expected_result
def test_update_local_package_no_confirm(tmp_path): home_dir = create_pearl_home(tmp_path) hooks_sh_script = """ pre_update() {{ 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 }} post_update() {{ if ask "Are you sure?" "N" then echo "YES" > hotexamples_com/result2 else echo "NO" > hotexamples_com/result2 fi local choice=$(choose "What?" "orange" "apple" "banana" "orange") echo "$choice" >> hotexamples_com/result2 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) update_package(pearl_env, package, PackageArgs(no_confirm=True, verbose=False)) assert (home_dir / 'result').read_text() == "YES\nbanana\n" assert (home_dir / 'result2').read_text() == "NO\norange\n"
def test_update_package_git_url_changed(tmp_path): home_dir = create_pearl_home(tmp_path) builder = PackageTestBuilder(home_dir) builder.add_git_package("", is_installed=True) packages = builder.build() package = packages['repo-test']['pkg-test'] pearl_env = create_pearl_env(home_dir, packages) with mock.patch(_MODULE_UNDER_TEST + ".run_pearl_bash") as run_mock, \ mock.patch(_MODULE_UNDER_TEST + ".ask") as ask_mock, \ mock.patch(_MODULE_UNDER_TEST + ".remove_package") as remove_mock, \ mock.patch(_MODULE_UNDER_TEST + ".install_package") as install_mock: out_process = namedtuple('OutProcess', ['stdout'])('https://github.com/package') run_mock.return_value = out_process ask_mock.return_value = False update_package(pearl_env, package, PackageArgs()) assert ask_mock.call_count == 1 assert remove_mock.call_count == 0 assert install_mock.call_count == 0 assert run_mock.call_count == 4 with mock.patch(_MODULE_UNDER_TEST + ".run_pearl_bash") as run_mock, \ mock.patch(_MODULE_UNDER_TEST + ".ask") as ask_mock, \ mock.patch(_MODULE_UNDER_TEST + ".remove_package") as remove_mock, \ mock.patch(_MODULE_UNDER_TEST + ".install_package") as install_mock: out_process = namedtuple('OutProcess', ['stdout'])('https://github.com/package') run_mock.return_value = out_process ask_mock.return_value = True update_package(pearl_env, package, PackageArgs()) assert ask_mock.call_count == 1 assert remove_mock.call_count == 1 assert install_mock.call_count == 1 assert run_mock.call_count == 4