<commit_before>__author__ = "<NAME>"
__copyright__ = "Copyright 2011 hamcrest.org"
__license__ = "BSD, see License.txt"

if __name__ == '__main__':
    import sys
    sys.path.insert(0, '..')
    sys.path.insert(0, '../..')

from hamcrest.library.collection.issequence_onlycontaining import *

from hamcrest.core.core.isequal import equal_to
from hamcrest.library.number.ordering_comparison import less_than
from matcher_test import MatcherTest
from quasisequence import QuasiSequence
import unittest


class IsSequenceOnlyContainingTest(MatcherTest):

    def testMatchesSingletonList(self):
        self.assert_matches('singleton list', only_contains(equal_to(1)), [1])

    def testMatchesAllItemsWithOneMatcher(self):
        self.assert_matches('one matcher',
                            only_contains(less_than(3)), [0, 1, 2])

    def testMatchesAllItemsWithMultipleMatchers(self):
        self.assert_matches('multiple matchers',
                            only_contains(less_than(3), equal_to('hi')),
                            [0, 'hi', 1, 2])

    def testProvidesConvenientShortcutForMatchingWithIsEqualTo(self):
        self.assert_matches('Values automatically wrapped with equal_to',
                            only_contains(less_than(3), 'hi'),
                            [0, 'hi', 1, 2])

    def testDoesNotMatchListWithMismatchingItem(self):
        self.assert_does_not_match('3 is not less than 3',
                                   only_contains(less_than(3)), [1, 2, 3])

    def testDoesNotMatchEmptyList(self):
        self.assert_does_not_match('empty', only_contains('foo'), [])

    def testMatchesAnyConformingSequence(self):
        class ObjectWithLenOnly:
            def __len__(self): return 20
        self.assert_matches('quasi-sequence',
                            only_contains(less_than(3)), QuasiSequence())
        self.assert_does_not_match('non-sequence', only_contains(1), object())
        self.assert_does_not_match('non-sequence with length',
                                   only_contains(1), ObjectWithLenOnly())

    def testHasAReadableDescription(self):
        self.assert_description('a sequence containing items matching (<1> or <2>)',
                                only_contains(1,2))

    def testDescribeMismatch(self):<commit_msg>Fixed test to work in Python 3<commit_after>__author__ = "<NAME>"
__copyright__ = "Copyright 2011 hamcrest.org"
__license__ = "BSD, see License.txt"

if __name__ == '__main__':
    import sys
    sys.path.insert(0, '..')
    sys.path.insert(0, '../..')

from hamcrest.library.collection.issequence_onlycontaining import *

from hamcrest.core.core.isequal import equal_to
from hamcrest.library.number.ordering_comparison import less_than
from matcher_test import MatcherTest
from quasisequence import QuasiSequence
import unittest


class IsSequenceOnlyContainingTest(MatcherTest):

    def testMatchesSingletonList(self):
        self.assert_matches('singleton list', only_contains(equal_to(1)), [1])

    def testMatchesAllItemsWithOneMatcher(self):
        self.assert_matches('one matcher',
                            only_contains(less_than(3)), [0, 1, 2])

    def testMatchesAllItemsWithMultipleMatchers(self):
        self.assert_matches('multiple matchers',
                            only_contains(less_than(3), equal_to(7)),
                            [0, 7, 1, 2])

    def testProvidesConvenientShortcutForMatchingWithIsEqualTo(self):
        self.assert_matches('Values automatically wrapped with equal_to',
                            only_contains(less_than(3), 7),
                            [0, 7, 1, 2])

    def testDoesNotMatchListWithMismatchingItem(self):
        self.assert_does_not_match('3 is not less than 3',
                                   only_contains(less_than(3)), [1, 2, 3])

    def testDoesNotMatchEmptyList(self):
        self.assert_does_not_match('empty', only_contains('foo'), [])

    def testMatchesAnyConformingSequence(self):
        class ObjectWithLenOnly:
            def __len__(self): return 20
        self.assert_matches('quasi-sequence',
                            only_contains(less_than(3)), QuasiSequence())
        self.assert_does_not_match('non-sequence', only_contains(1), object())
        self.assert_does_not_match('non-sequence with length',
                                   only_contains(1), ObjectWithLenOnly())

    def testHasAReadableDescription(self):
        self.assert_description('a sequence containing items matching (<1> or <2>)',
                                only_contains(1,2))

    def testDescribeMismatch(self):
{'fraction_non_alphanumeric': 0.10254182055181403, 'fraction_numerical': 0.0162937214859874, 'mean_word_length': 2.820746887966805, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5216481', 'n_tokens_mistral': 1361, 'n_tokens_neox': 1290, 'n_words': 255}