Esempio n. 1
0
def test_install_lib_fail(tmp_path):
    set_env(tmp_path)

    p = Pipis()
    args = Args(package="requests")

    with pytest.raises(Exception):
        p.install(args)
Esempio n. 2
0
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}==")
Esempio n. 3
0
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"
Esempio n. 4
0
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))
Esempio n. 5
0
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
Esempio n. 6
0
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()
Esempio n. 7
0
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()
Esempio n. 8
0
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)
Esempio n. 9
0
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()
Esempio n. 10
0
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"
Esempio n. 11
0
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()
Esempio n. 12
0
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()
Esempio n. 13
0
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"
Esempio n. 14
0
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
Esempio n. 15
0
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()
Esempio n. 16
0
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
Esempio n. 17
0
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"
Esempio n. 18
0
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
Esempio n. 19
0
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
Esempio n. 20
0
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
Esempio n. 21
0
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
Esempio n. 22
0
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")
Esempio n. 23
0
def test_show_version(tmp_path):
    p = Pipis()
    args = Args()
    message = p.show_version(args)

    assert message.startswith("pipis version: ")