Exemplo 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)
Exemplo 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}==")
Exemplo 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"
Exemplo n.º 4
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()
Exemplo 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
Exemplo n.º 6
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)
Exemplo n.º 7
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()
Exemplo n.º 8
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()
Exemplo n.º 9
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"
Exemplo n.º 10
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"
Exemplo n.º 11
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()
Exemplo n.º 12
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
Exemplo n.º 13
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"
Exemplo n.º 14
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
Exemplo n.º 15
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")