File: test_cachedir_tag.py

package info (click to toggle)
python-virtualenv 20.33.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,124 kB
  • sloc: python: 10,907; sh: 160; ansic: 61; csh: 47; makefile: 8
file content (32 lines) | stat: -rw-r--r-- 1,192 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from __future__ import annotations

import shutil
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

# gtar => gnu-tar on macOS
TAR = next((target for target in ("gtar", "tar") if shutil.which(target)), None)


def compatible_is_tar_present() -> bool:
    return TAR and "--exclude-caches" in check_output(args=[TAR, "--help"], text=True, encoding="utf-8")


@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(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, encoding="utf-8", cwd=tmp_path)
    assert tar_result.stdout == ".venv/\n.venv/CACHEDIR.TAG\n"
    assert tar_result.stderr == f"{TAR}: .venv/: contains a cache directory tag CACHEDIR.TAG; contents not dumped\n"