Skip to content

Commit

Permalink
Testing: add git to PATH (#930)
Browse files Browse the repository at this point in the history
* Testing: add git to PATH

* Add support for Windows

* Add support for Windows

* Fix linting

* Allow to add more utils in the future

* Remove `util_filename`

* Update tests/conftest.py

Co-authored-by: Tzu-ping Chung <[email protected]>

---------

Co-authored-by: Tzu-ping Chung <[email protected]>
  • Loading branch information
dukecat0 and uranusjr authored Jun 30, 2023
1 parent 868f1ea commit 6959f93
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
32 changes: 26 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import shutil
import subprocess
import sys
from pathlib import Path
Expand Down Expand Up @@ -40,7 +41,9 @@ def pytest_configure(config):
config.option.markexpr = new_markexpr


def pipx_temp_env_helper(pipx_shared_dir, tmp_path, monkeypatch, request):
def pipx_temp_env_helper(
pipx_shared_dir, tmp_path, monkeypatch, request, utils_temp_dir
):
home_dir = Path(tmp_path) / "subdir" / "pipxhome"
bin_dir = Path(tmp_path) / "otherdir" / "pipxbindir"

Expand All @@ -59,7 +62,7 @@ def pipx_temp_env_helper(pipx_shared_dir, tmp_path, monkeypatch, request):
# which make tests fail (e.g. on Github ansible apps exist in /usr/bin)
monkeypatch.setenv("PATH_ORIG", str(bin_dir) + os.pathsep + os.getenv("PATH"))
monkeypatch.setenv("PATH_TEST", str(bin_dir))
monkeypatch.setenv("PATH", str(bin_dir))
monkeypatch.setenv("PATH", str(bin_dir) + os.pathsep + str(utils_temp_dir))
# On Windows, monkeypatch pipx.commands.common._can_symlink_cache to
# indicate that constants.LOCAL_BIN_DIR cannot use symlinks, even if
# we're running as administrator and symlinks are actually possible.
Expand Down Expand Up @@ -133,8 +136,23 @@ def pipx_session_shared_dir(tmp_path_factory):
return tmp_path_factory.mktemp("session_shareddir")


@pytest.fixture(scope="session")
def utils_temp_dir(tmp_path_factory):
tmp_path = tmp_path_factory.mktemp("session_utilstempdir")
utils = ["git"]
for util in utils:
util_path = Path(shutil.which(util))
try:
(tmp_path / util_path.name).symlink_to(util_path)
except FileExistsError:
pass
return tmp_path


@pytest.fixture
def pipx_temp_env(tmp_path, monkeypatch, pipx_session_shared_dir, request):
def pipx_temp_env(
tmp_path, monkeypatch, pipx_session_shared_dir, request, utils_temp_dir
):
"""Sets up temporary paths for pipx to install into.
Shared libs are setup once per session, all other pipx dirs, constants are
Expand All @@ -143,11 +161,13 @@ def pipx_temp_env(tmp_path, monkeypatch, pipx_session_shared_dir, request):
Also adds environment variables as necessary to make pip installations
seamless.
"""
pipx_temp_env_helper(pipx_session_shared_dir, tmp_path, monkeypatch, request)
pipx_temp_env_helper(
pipx_session_shared_dir, tmp_path, monkeypatch, request, utils_temp_dir
)


@pytest.fixture
def pipx_ultra_temp_env(tmp_path, monkeypatch, request):
def pipx_ultra_temp_env(tmp_path, monkeypatch, request, utils_temp_dir):
"""Sets up temporary paths for pipx to install into.
Fully temporary environment, every test function starts as if pipx has
Expand All @@ -157,4 +177,4 @@ def pipx_ultra_temp_env(tmp_path, monkeypatch, request):
seamless.
"""
shared_dir = Path(tmp_path) / "shareddir"
pipx_temp_env_helper(shared_dir, tmp_path, monkeypatch, request)
pipx_temp_env_helper(shared_dir, tmp_path, monkeypatch, request, utils_temp_dir)
3 changes: 1 addition & 2 deletions tests/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,10 @@ def test_install_tricky_packages(
install_package(capsys, pipx_temp_env, caplog, package_spec, package_name)


# TODO: Add git+... spec when git is in binpath of tests (Issue #303)
@pytest.mark.parametrize(
"package_name, package_spec",
[
# ("nox", "git+https://github.com/cs01/nox.git@5ea70723e9e6"),
("pycowsay", "git+https://github.com/cs01/pycowsay.git@master"),
("pylint", PKG["pylint"]["spec"]),
("nox", "https://github.com/wntrblm/nox/archive/2022.1.7.zip"),
],
Expand Down
1 change: 0 additions & 1 deletion tests/test_package_specifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ def test_fix_package_name(package_spec_in, package_name, package_spec_out):
assert fix_package_name(package_spec_in, package_name) == package_spec_out


# TODO: Make sure git+ works with tests, correct in test_install as well
@pytest.mark.parametrize(
"package_spec_in,package_or_url_correct,valid_spec",
[
Expand Down

0 comments on commit 6959f93

Please sign in to comment.