<commit_before>import pytest

import pip.wheel
import pip.pep425tags

from pkg_resources import parse_version, Distribution
from pip.req import InstallRequirement
from pip.index import (
    InstallationCandidate, PackageFinder, Link, FormatControl,
    fmt_ctl_formats)
from pip.exceptions import (
    BestVersionAlreadyInstalled, DistributionNotFound, InstallationError,
)
from pip.download import PipSession

from mock import Mock, patch


def test_no_mpkg(data):
    """Finder skips zipfiles with "macosx10" in the name."""
    finder = PackageFinder([data.find_links], [], session=PipSession())
    req = InstallRequirement.from_line("pkgwithmpkg")
    found = finder.find_requirement(req, False)

    assert found.url.endswith("pkgwithmpkg-1.0.tar.gz"), found


def test_no_partial_name_match(data):
    """Finder requires the full project name to match, not just beginning."""
    finder = PackageFinder([data.find_links], [], session=PipSession())
    req = InstallRequirement.from_line("gmpy")
    found = finder.find_requirement(req, False)

    assert found.url.endswith("gmpy-1.15.tar.gz"), found


@patch(
    'pip.index.os.path.exists',
    return_value=True  # b/c we only use tilde expanded version if it exists
)
def test_tilde(data):
    """Finder can accept a path with ~ in it and will normalize it."""
    finder = PackageFinder(['~/python-pkgs'], [], session=PipSession())
    req = InstallRequirement.from_line("gmpy")
    with pytest.raises(DistributionNotFound):<commit_msg>monkeypatch os.path.exists over less code<commit_after>import pytest

import pip.wheel
import pip.pep425tags

from pkg_resources import parse_version, Distribution
from pip.req import InstallRequirement
from pip.index import (
    InstallationCandidate, PackageFinder, Link, FormatControl,
    fmt_ctl_formats)
from pip.exceptions import (
    BestVersionAlreadyInstalled, DistributionNotFound, InstallationError,
)
from pip.download import PipSession

from mock import Mock, patch


def test_no_mpkg(data):
    """Finder skips zipfiles with "macosx10" in the name."""
    finder = PackageFinder([data.find_links], [], session=PipSession())
    req = InstallRequirement.from_line("pkgwithmpkg")
    found = finder.find_requirement(req, False)

    assert found.url.endswith("pkgwithmpkg-1.0.tar.gz"), found


def test_no_partial_name_match(data):
    """Finder requires the full project name to match, not just beginning."""
    finder = PackageFinder([data.find_links], [], session=PipSession())
    req = InstallRequirement.from_line("gmpy")
    found = finder.find_requirement(req, False)

    assert found.url.endswith("gmpy-1.15.tar.gz"), found


def test_tilde(data):
    """Finder can accept a path with ~ in it and will normalize it."""
    session = PipSession()
    with patch('pip.index.os.path.exists', return_value=True):
        finder = PackageFinder(['~/python-pkgs'], [], session=session)
    req = InstallRequirement.from_line("gmpy")
    with pytest.raises(DistributionNotFound):
{'fraction_non_alphanumeric': 0.11107404936624417, 'fraction_numerical': 0.0066711140760507, 'mean_word_length': 4.834630350194552, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2612700', 'n_tokens_mistral': 934, 'n_tokens_neox': 906, 'n_words': 229}