<commit_before>import unittest
from piptools.datastructures import SpecSet, Spec, ConflictError


class TestSpecSet(unittest.TestCase):
    def test_adding_spec(self):
        """Adding a spec to a set."""
        specset = SpecSet()

        specset.add_spec('foo')
        specset.add_spec('foo')

        self.assertItemsEqual(list(specset),
                              [Spec.from_line('foo')])

        # If we now add a 'foo' spec from a specific source, they're not
        # considered equal
        spec = Spec.from_line('foo', source='bar==1.2.4')
        specset.add_spec(spec)

        self.assertItemsEqual(list(specset),
                              [spec, Spec.from_line('foo')])

    def test_adding_multiple_specs(self):
        """Adding multiple specs to a set."""
        specset = SpecSet()

        specset.add_spec('Django>=1.3')
        assert 'Django>=1.3' in list(map(str, specset))

        specset.add_spec('django-pipeline')
        self.assertItemsEqual(['Django>=1.3', 'django-pipeline'], list(map(str, specset)))

        specset.add_spec('Django<1.4')
        self.assertItemsEqual(['Django>=1.3', 'django-pipeline', 'Django<1.4'], list(map(str, specset)))

    def test_explode(self):
        """Exploding a spec list into specs of max one predicate."""
        specset = SpecSet()

        specset.add_spec('Django>=1.3,<1.4')
        specset.add_spec('Django>=1.3.2,<1.5')

        self.assertItemsEqual(
            ['Django>=1.3', 'Django>=1.3.2', 'Django<1.4', 'Django<1.5'],
            list(map(str, specset.explode('Django'))))

    def test_normalizing_combines(self):
        """Normalizing combines predicates to a single Spec."""
        specset = SpecSet()

        specset.add_spec('Django>=1.3')
        specset.add_spec('Django<1.4')
        specset.add_spec('Django>=1.3.2')
        specset.add_spec('Django<1.3.99')

        normalized = str(specset.normalize())
        assert 'django<1.3.99,>=1.3.2' in normalized

        specset.add_spec('Django<=1.3.2')
        normalized = specset.normalize()

        assert 'django==1.3.2' in list(map(str, normalized))

    def test_normalizing_drops_obsoletes(self):
        """Normalizing combines predicates to a single Spec."""
        specset = SpecSet()

        specset.add_spec('Django')
        specset.add_spec('Django<1.4')
<commit_msg>Deprecate assertItemsEqual in favor of assertCountEqual.<commit_after>import unittest

import six

from piptools.datastructures import ConflictError, Spec, SpecSet


class UnitTestPython3CompatMixin(object):
    def assertCountEqual(self, first, second, msg=None):
        if six.PY2:
            return self.assertItemsEqual(first, second, msg)
        return self.assertCountEqual(first, second, msg)


class TestSpecSet(unittest.TestCase, UnitTestPython3CompatMixin):
    def test_adding_spec(self):
        """Adding a spec to a set."""
        specset = SpecSet()

        specset.add_spec('foo')
        specset.add_spec('foo')

        self.assertCountEqual(list(specset),
                              [Spec.from_line('foo')])

        # If we now add a 'foo' spec from a specific source, they're not
        # considered equal
        spec = Spec.from_line('foo', source='bar==1.2.4')
        specset.add_spec(spec)

        self.assertCountEqual(list(specset),
                              [spec, Spec.from_line('foo')])

    def test_adding_multiple_specs(self):
        """Adding multiple specs to a set."""
        specset = SpecSet()

        specset.add_spec('Django>=1.3')
        assert 'Django>=1.3' in list(map(str, specset))

        specset.add_spec('django-pipeline')
        self.assertCountEqual(['Django>=1.3', 'django-pipeline'], list(map(str, specset)))

        specset.add_spec('Django<1.4')
        self.assertCountEqual(['Django>=1.3', 'django-pipeline', 'Django<1.4'], list(map(str, specset)))

    def test_explode(self):
        """Exploding a spec list into specs of max one predicate."""
        specset = SpecSet()

        specset.add_spec('Django>=1.3,<1.4')
        specset.add_spec('Django>=1.3.2,<1.5')

        self.assertCountEqual(
            ['Django>=1.3', 'Django>=1.3.2', 'Django<1.4', 'Django<1.5'],
            list(map(str, specset.explode('Django'))))

    def test_normalizing_combines(self):
        """Normalizing combines predicates to a single Spec."""
        specset = SpecSet()

        specset.add_spec('Django>=1.3')
        specset.add_spec('Django<1.4')
        specset.add_spec('Django>=1.3.2')
        specset.add_spec('Django<1.3.99')

        normalized = str(specset.normalize())
        assert 'django<1.3.99,>=1.3.2' in normalized

        specset.add_spec('Django<=1.3.2')
        normalized = specset.normalize()

        assert 'django==1.3.2' in list(map(str, normalized))

    def test_normalizing_drops_obsoletes(self):
        """Normalizing combines predicates to a single Spec."""
        specset = SpecSet()

        specset.add_spec('Django')
        specset.add_spec('Django<1.4')

{'fraction_non_alphanumeric': 0.14687687088405507, 'fraction_numerical': 0.024146876870884054, 'mean_word_length': 2.696165191740413, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, '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': '1655333', 'n_tokens_mistral': 1676, 'n_tokens_neox': 1616, 'n_words': 301}