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_version(tmp_path, capsys): set_env(tmp_path) sys.argv = ["pipis", "version"] main() captured = capsys.readouterr() assert re.match(r"^pipis version: \d+\.\d+\.\d+", captured.out)
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_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_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_install(tmp_path, capsys): set_env(tmp_path) package = "pipis" sys.argv = ["pipis", "install", "-y", package] main() captured = capsys.readouterr() assert f"Successfully installed {package}" in captured.out
def test_install_dependency(tmp_path, capsys): set_env(tmp_path) package = "pipis" dependency = "flake8" sys.argv = ["pipis", "install", "-y", package, "-d", dependency] main() captured = capsys.readouterr() assert f"Successfully installed {package}" in captured.out
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_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_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_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_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_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_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_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_env_config(tmp_path): set_env(tmp_path) envvars = { "venvs": os.environ["PIPIS_VENVS"], "bin": os.environ["PIPIS_BIN"] } p = Pipis() assert isinstance(p.config, dict) assert p.config == envvars
def test_freeze(tmp_path, capsys): set_env(tmp_path) # install a package before test package = "pipis" sys.argv = ["pipis", "install", "-y", package] main() sys.argv = ["pipis", "freeze"] main() captured = capsys.readouterr() assert f"{package}==" in captured.out
def test_install_version(tmp_path, capsys): set_env(tmp_path) package = "pipis==1.0.0" sys.argv = ["pipis", "install", "-y", package] main() sys.argv = ["pipis", "freeze"] main() captured = capsys.readouterr() assert f"Successfully installed {package}" in captured.out assert package in captured.out
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_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_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_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_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_default_to_environment_action(env_name, default, environ, expected): option_strings = ('-x', '--example') dest = 'example' with helpers.set_env(**environ): action = utils.EnvironmentDefault( env=env_name, default=default, option_strings=option_strings, dest=dest, ) assert action.env == env_name assert action.default == expected
def test_values_from_env(monkeypatch): def none_upload(*args, **kwargs): pass replaced_upload = pretend.call_recorder(none_upload) monkeypatch.setattr(twine.commands.upload, "upload", replaced_upload) testenv = {"TWINE_USERNAME": "******", "TWINE_PASSWORD": "******", "TWINE_CERT": "/foo/bar.crt"} with helpers.set_env(**testenv): cli.dispatch(["upload", "path/to/file"]) upload_settings = replaced_upload.calls[0].args[0] assert "pypipassword" == upload_settings.password assert "pypiuser" == upload_settings.username assert "/foo/bar.crt" == upload_settings.cacert
def test_password_and_username_from_env(monkeypatch): def none_upload(*args, **kwargs): pass replaced_upload = pretend.call_recorder(none_upload) monkeypatch.setattr(twine.commands.upload, "upload", replaced_upload) testenv = {"TWINE_USERNAME": "******", "TWINE_PASSWORD": "******"} with helpers.set_env(**testenv): cli.dispatch(["upload", "path/to/file"]) cli.dispatch(["upload", "path/to/file"]) result_kwargs = replaced_upload.calls[0].kwargs assert "pypipassword" == result_kwargs["password"] assert "pypiuser" == result_kwargs["username"] result_kwargs = replaced_upload.calls[1].kwargs assert None is result_kwargs["password"] assert None is result_kwargs["username"]
def test_values_from_env(monkeypatch): """Test calling main via cli""" def none_register(*args, **settings_kwargs): pass replaced_register = pretend.call_recorder(none_register) monkeypatch.setattr(register, "register", replaced_register) testenv = { "TWINE_USERNAME": "******", "TWINE_PASSWORD": "******", "TWINE_CERT": "/foo/bar.crt", } with helpers.set_env(**testenv): cli.dispatch(["register", helpers.WHEEL_FIXTURE]) register_settings = replaced_register.calls[0].args[0] assert "pypipassword" == register_settings.password assert "pypiuser" == register_settings.username assert "/foo/bar.crt" == register_settings.cacert