def test_install_lib_fail(tmp_path): set_env(tmp_path) p = Pipis() args = Args(package="requests") with pytest.raises(Exception): p.install(args)
def test_freeze(tmp_path): set_env(tmp_path) p = Pipis() args = Args() p.install(args) freeze = p.freeze(args) assert freeze[0].startswith(f"{args.package}==")
def test_search_inexistant(tmp_path): set_env(tmp_path) p = Pipis() args = Args(query="pipistache") p.install(args) search = p.search(args) assert search == f"Package '{args.query}' not found"
def test_venv_py_path(tmp_path): set_env(tmp_path) p = Pipis() args = Args() venv_py = p._venv_py_path(args.package) assert isinstance(venv_py, str) assert venv_py.startswith(str(tmp_path))
def test_search(tmp_path): set_env(tmp_path) p = Pipis() args = Args() p.install(args) search = p.search(args) assert "not found" not in search assert args.query in search
def test_create_venv(tmp_path): set_env(tmp_path) args = Args() p = Pipis() venv_dir = p._create_venv(package=args.package) assert Path(venv_dir).is_dir() assert Path(venv_dir, "bin", "python").exists() assert Path(venv_dir, "bin", "pip").exists()
def test_install_upgrade(tmp_path): set_env(tmp_path) p = Pipis() args = Args(upgrade=True) p.install(args) venv_dir = p._venv_dir_path(args.package) package_bin = Path(venv_dir, "bin", args.package) assert package_bin.exists()
def test_package_version(tmp_path): set_env(tmp_path) p = Pipis() args = Args() p.install(args) version = p._package_version(args.package) assert isinstance(version, str) assert re.match(r"^\d+(?:\.\d+){1,3}", version)
def test_update(tmp_path): set_env(tmp_path) p = Pipis() args = Args() p.update(args) venv_dir = p._venv_dir_path(args.package) package_bin = Path(venv_dir, "bin", args.package) assert package_bin.exists()
def test_add_dependency(tmp_path): set_env(tmp_path) p = Pipis() args = Args() p.install(args) p._add_dependency(args.package, "abc") req_file = p._add_dependency(args.package, "def") assert Path(req_file).is_file() assert Path(req_file).read_text() == "abc\ndef"
def test_install_input_yes(tmp_path): set_env(tmp_path) p = Pipis() args = Args(yes=False) with mock.patch("builtins.input", return_value="y"): p.install(args) venv_dir = p._venv_dir_path(args.package) package_bin = Path(venv_dir, "bin", args.package) assert package_bin.exists()
def test_uninstall(tmp_path): set_env(tmp_path) p = Pipis() args = Args() p.install(args) p.uninstall(args) venv_dir = p._venv_dir_path(args.package) package_bin = Path(venv_dir, "bin", args.package) assert not package_bin.exists()
def test_uninstall(tmp_path, capsys): set_env(tmp_path) p = Pipis() args = Args() p.install(args) capsys.readouterr() # reset capture sys.argv = ["pipis", "uninstall", "-y", args.package] main() captured = capsys.readouterr() assert captured.out == f"Successfully uninstalled {args.package}\n"
def test_windows_defaults_config(): args = Args() base = os.getenv("APPDATA") path = Path(base, args.package, "data") default_venvs = str(Path(path, "venvs")) default_bin = str(Path(path, "bin")) defaults = {"venvs": default_venvs, "bin": default_bin} p = Pipis() assert isinstance(p.config, dict) assert p.config == defaults
def test_install_dependency(tmp_path): set_env(tmp_path) p = Pipis() args = Args(dependency="black") p.install(args) venv_dir = p._venv_dir_path(args.package) requirements = Path(venv_dir, "requirements.txt").read_text() dep_bin = Path(venv_dir, "bin", "black") assert requirements == "black" assert dep_bin.exists()
def test_search(tmp_path, capsys): set_env(tmp_path) p = Pipis() args = Args() p.install(args) package = "pipis" sys.argv = ["pipis", "search", package] main() captured = capsys.readouterr() assert "not found" not in captured.out assert package in captured.out
def test_search_inexistant(tmp_path, capsys): set_env(tmp_path) p = Pipis() args = Args() p.install(args) capsys.readouterr() # reset capture package = "pipistache" sys.argv = ["pipis", "search", package] main() captured = capsys.readouterr() assert captured.out == f"Package '{package}' not found\n"
def test_linux_defaults_config(): args = Args() home = os.getenv("HOME", "") base = os.getenv("XDG_DATA_HOME", Path(home, ".local", "share")) path = Path(base, args.package) default_venvs = str(Path(path, "venvs")) default_bin = str(Path(path, "bin")) defaults = {"venvs": default_venvs, "bin": default_bin} p = Pipis() assert isinstance(p.config, dict) assert p.config == defaults
def test_package_scripts(tmp_path): set_env(tmp_path) p = Pipis() args = Args() p.install(args) scripts = p._package_scripts(args.package) assert isinstance(scripts, list) for script in scripts: assert Path(script).is_file() assert os.access(script, os.X_OK) assert "bin" in script
def test_linux_defaults_config_paths(): args = Args() sys_base = "/etc" sys_path = str(Path(sys_base, args.package, f"{args.package}.cfg")) user_home = os.getenv("HOME", "") user_base = os.getenv("XDG_CONFIG_HOME", Path(user_home, ".config")) user_path = str(Path(user_base, args.package, f"{args.package}.cfg")) p = Pipis() assert isinstance(p.config_paths, list) assert p.config_paths[0] == sys_path assert p.config_paths[1] == user_path
def test_windows_defaults_config_paths(): args = Args() sys_base = os.getenv("ProgramFiles") sys_path = str( Path(sys_base, args.package, "config", f"{args.package}.cfg")) user_base = user_base = os.getenv("APPDATA") user_path = str( Path(user_base, args.package, "config", f"{args.package}.cfg")) p = Pipis() assert isinstance(p.config_paths, list) assert p.config_paths[0] == sys_path assert p.config_paths[1] == user_path
def test_dist_info(tmp_path): set_env(tmp_path) p = Pipis() args = Args() p.install(args) dist = p._dist_info(args.package) assert hasattr(dist, "location") assert hasattr(dist, "project_name") assert hasattr(dist, "version") assert hasattr(dist, "has_metadata") assert hasattr(dist, "get_metadata_lines") assert hasattr(dist, "get_entry_map")
def test_show_version(tmp_path): p = Pipis() args = Args() message = p.show_version(args) assert message.startswith("pipis version: ")