-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Bernát Gábor <bgabor8@bloomberg.net>
- Loading branch information
1 parent
b7df639
commit 4613919
Showing
4 changed files
with
24 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
write CACHEDIR.TAG file on creation - by "user:`neilramsay` | ||
Write CACHEDIR.TAG file on creation - by "user:`neilramsay`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,32 @@ | ||
from __future__ import annotations | ||
|
||
import shutil | ||
import subprocess | ||
import sys | ||
from subprocess import check_output, run | ||
from typing import TYPE_CHECKING | ||
|
||
import pytest | ||
|
||
from virtualenv import cli_run | ||
|
||
if TYPE_CHECKING: | ||
from pathlib import Path | ||
|
||
@pytest.fixture(scope="session") | ||
def tar_test_env(tmp_path_factory): | ||
base_path = tmp_path_factory.mktemp("tar-cachedir-test") | ||
cli_run(["--activators", "", "--without-pip", str(base_path / ".venv")]) | ||
yield base_path | ||
shutil.rmtree(str(base_path)) | ||
# gtar => gnu-tar on macOS | ||
TAR = next((target for target in ("gtar", "tar") if shutil.which(target)), None) | ||
|
||
|
||
def compatible_is_tar_present() -> bool: | ||
try: | ||
tar_result = subprocess.run(args=["tar", "--help"], capture_output=True, encoding="utf-8") | ||
return tar_result.stdout.find("--exclude-caches") > -1 | ||
except FileNotFoundError: | ||
return False | ||
return TAR and "--exclude-caches" in check_output(args=[TAR, "--help"], text=True) | ||
|
||
|
||
@pytest.mark.skipif(sys.platform == "win32", reason="Windows does not have tar") | ||
@pytest.mark.skipif(not compatible_is_tar_present(), reason="Compatible tar is not installed") | ||
def test_cachedir_tag_ignored_by_tag(tar_test_env): # noqa: ARG001 | ||
tar_result = subprocess.run( | ||
args=["tar", "--create", "--file", "/dev/null", "--exclude-caches", "--verbose", ".venv"], | ||
capture_output=True, | ||
encoding="utf-8", | ||
) | ||
def test_cachedir_tag_ignored_by_tag(tmp_path: Path) -> None: | ||
venv = tmp_path / ".venv" | ||
cli_run(["--activators", "", "--without-pip", str(venv)]) | ||
|
||
args = [TAR, "--create", "--file", "/dev/null", "--exclude-caches", "--verbose", venv.name] | ||
tar_result = run(args=args, capture_output=True, text=True, cwd=tmp_path) | ||
assert tar_result.stdout == ".venv/\n.venv/CACHEDIR.TAG\n" | ||
assert tar_result.stderr == "tar: .venv/: contains a cache directory tag CACHEDIR.TAG; contents not dumped\n" | ||
assert tar_result.stderr == f"{TAR}: .venv/: contains a cache directory tag CACHEDIR.TAG; contents not dumped\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters