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_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)
Exemplo n.º 3
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))
Exemplo n.º 4
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.º 5
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.º 6
0
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
Exemplo n.º 7
0
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
Exemplo n.º 8
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.º 9
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.º 10
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.º 11
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()
Exemplo n.º 12
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()
Exemplo n.º 13
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.º 14
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.º 15
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.º 16
0
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
Exemplo n.º 17
0
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
Exemplo n.º 18
0
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
Exemplo n.º 19
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.º 20
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.º 21
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.º 22
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.º 23
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.º 24
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")
Exemplo n.º 25
0
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
Exemplo n.º 26
0
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
Exemplo n.º 27
0
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
Exemplo n.º 28
0
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"]
Exemplo n.º 29
0
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