<commit_before>import os
import shutil
import tempfile

from pkg_resources import Distribution
from mock import Mock, patch
from nose.tools import assert_equal, assert_raises
from pip.exceptions import PreviousBuildDirError
from pip.index import PackageFinder
from pip.log import logger
from pip.req import (InstallRequirement, RequirementSet, parse_editable,
                     Requirements, parse_requirements)
from tests.lib import path_to_url, assert_raises_regexp, find_links, tests_data


class TestRequirementSet(object):
    """RequirementSet tests"""

    def setup(self):
        logger.consumers = [(logger.NOTIFY, Mock())]
        self.tempdir = tempfile.mkdtemp()

    def teardown(self):
        logger.consumers = []
        shutil.rmtree(self.tempdir, ignore_errors=True)

    def basic_reqset(self):
        return RequirementSet(
            build_dir=os.path.join(self.tempdir, 'build'),
            src_dir=os.path.join(self.tempdir, 'src'),
            download_dir=None,
            download_cache=os.path.join(self.tempdir, 'download_cache')
            )

    def test_no_reuse_existing_build_dir(self):
        """Test prepare_files raise exception with previous build dir"""

        build_dir = os.path.join(self.tempdir, 'build', 'simple')
        os.makedirs(build_dir)
        open(os.path.join(build_dir, "setup.py"), 'w')
        reqset = self.basic_reqset()
        req = InstallRequirement.from_line('simple')
        reqset.add_requirement(req)
        finder = PackageFinder([find_links], [])
        assert_raises_regexp(
            PreviousBuildDirError,
            "pip can't proceed with [\s\S]*%s[\s\S]*%s" % (req, build_dir),
            reqset.prepare_files,
            finder
            )<commit_msg>fix regexp for windows paths<commit_after>import os
import shutil
import tempfile

from pkg_resources import Distribution
from mock import Mock, patch
from nose.tools import assert_equal, assert_raises
from pip.exceptions import PreviousBuildDirError
from pip.index import PackageFinder
from pip.log import logger
from pip.req import (InstallRequirement, RequirementSet, parse_editable,
                     Requirements, parse_requirements)
from tests.lib import path_to_url, assert_raises_regexp, find_links, tests_data


class TestRequirementSet(object):
    """RequirementSet tests"""

    def setup(self):
        logger.consumers = [(logger.NOTIFY, Mock())]
        self.tempdir = tempfile.mkdtemp()

    def teardown(self):
        logger.consumers = []
        shutil.rmtree(self.tempdir, ignore_errors=True)

    def basic_reqset(self):
        return RequirementSet(
            build_dir=os.path.join(self.tempdir, 'build'),
            src_dir=os.path.join(self.tempdir, 'src'),
            download_dir=None,
            download_cache=os.path.join(self.tempdir, 'download_cache')
            )

    def test_no_reuse_existing_build_dir(self):
        """Test prepare_files raise exception with previous build dir"""

        build_dir = os.path.join(self.tempdir, 'build', 'simple')
        os.makedirs(build_dir)
        open(os.path.join(build_dir, "setup.py"), 'w')
        reqset = self.basic_reqset()
        req = InstallRequirement.from_line('simple')
        reqset.add_requirement(req)
        finder = PackageFinder([find_links], [])
        assert_raises_regexp(
            PreviousBuildDirError,
            "pip can't proceed with [\s\S]*%s[\s\S]*%s" % (req, build_dir.replace('\\', '\\\\')),
            reqset.prepare_files,
            finder
            )
{'fraction_non_alphanumeric': 0.10517387616624257, 'fraction_numerical': 0.0, 'mean_word_length': 2.9708193041526374, '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': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4702633', 'n_tokens_mistral': 1075, 'n_tokens_neox': 1044, 'n_words': 224}