<commit_before>import json
import os
from pathlib import Path
from venv import EnvBuilder

from tests.lib import PipTestEnvironment, TestData


def test_python_interpreter(
    script: PipTestEnvironment,
    tmpdir: Path,
    shared_data: TestData,
) -> None:
    env_path = os.fsdecode(tmpdir / "venv")
    env = EnvBuilder(with_pip=False)
    env.create(env_path)

    result = script.pip("--python", env_path, "list", "--format=json")
    assert json.loads(result.stdout) == []
    script.pip(
        "--python",
        env_path,
        "install",
        "-f",
        shared_data.find_links,
        "--no-index",
        "simplewheel==1.0",
    )
    result = script.pip("--python", env_path, "list", "--format=json")
    assert json.loads(result.stdout) == [{"name": "simplewheel", "version": "1.0"}]
    script.pip("--python", env_path, "uninstall", "simplewheel", "--yes")
    result = script.pip("--python", env_path, "list", "--format=json")
    assert json.loads(result.stdout) == []<commit_msg>Fix test to cater for packages leaked into venv<commit_after>import json
import os
from pathlib import Path
from venv import EnvBuilder

from tests.lib import PipTestEnvironment, TestData


def test_python_interpreter(
    script: PipTestEnvironment,
    tmpdir: Path,
    shared_data: TestData,
) -> None:
    env_path = os.fspath(tmpdir / "venv")
    env = EnvBuilder(with_pip=False)
    env.create(env_path)

    result = script.pip("--python", env_path, "list", "--format=json")
    before = json.loads(result.stdout)

    # Ideally we would assert that before==[], but there's a problem in CI
    # that means this isn't true. See https://github.com/pypa/pip/pull/11326
    # for details.

    script.pip(
        "--python",
        env_path,
        "install",
        "-f",
        shared_data.find_links,
        "--no-index",
        "simplewheel==1.0",
    )

    result = script.pip("--python", env_path, "list", "--format=json")
    installed = json.loads(result.stdout)
    assert {"name": "simplewheel", "version": "1.0"} in installed

    script.pip("--python", env_path, "uninstall", "simplewheel", "--yes")
    result = script.pip("--python", env_path, "list", "--format=json")
    assert json.loads(result.stdout) == before
{'fraction_non_alphanumeric': 0.15712383488681758, 'fraction_numerical': 0.005770084332001775, 'mean_word_length': 3.0833333333333335, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3418155', 'n_tokens_mistral': 745, 'n_tokens_neox': 724, 'n_words': 173}