1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
if __name__ == '__main__':
import sys
sys.path.insert(0, '..')
sys.path.insert(0, '../..')
from hamcrest.library.collection.issequence_containing import *
from hamcrest.core.core.isequal import equal_to
from hamcrest_unit_test.matcher_test import MatcherTest
from quasisequence import QuasiSequence
import unittest
__author__ = "Jon Reid"
__copyright__ = "Copyright 2011 hamcrest.org"
__license__ = "BSD, see License.txt"
class IsSequenceContainingTest(MatcherTest):
def testMatchesASequenceThatContainsAnElementMatchingTheGivenMatcher(self):
self.assert_matches("sequence contains 'a'",
has_item(equal_to('a')), ['a', 'b', 'c'])
def testNoMatchIfSequenceDoesntContainAnElementMatchingTheGivenMatcher(self):
self.assert_does_not_match("sequence without 'a'",
has_item(equal_to('a')), ['b', 'c'])
self.assert_does_not_match('empty', has_item(equal_to('a')), [])
def testProvidesConvenientShortcutForMatchingWithEqualTo(self):
self.assert_matches("sequence contains 'a'",
has_item('a'), ['a', 'b', 'c'])
self.assert_does_not_match("sequence without 'a'",
has_item('a'), ['b', 'c'])
def testMatchesAnyConformingSequence(self):
self.assert_matches('quasi-sequence', has_item(1), QuasiSequence())
self.assert_does_not_match('non-sequence', has_item(1), object())
def testHasAReadableDescription(self):
self.assert_description("a sequence containing 'a'", has_item('a'))
def testSuccessfulMatchDoesNotGenerateMismatchDescription(self):
self.assert_no_mismatch_description(has_item('a'), ['a', 'b'])
def testMismatchDescriptionShowsActualArgument(self):
self.assert_mismatch_description("was <42>", has_item('a'), 42)
def testDescribeMismatch(self):
self.assert_describe_mismatch("was <42>", has_item('a'), 42)
class IsSequenceContainingItemsTest(MatcherTest):
def testShouldMatchCollectionContainingAllItems(self):
self.assert_matches('contains all items',
has_items(equal_to('a'), equal_to('b'), equal_to('c')),
('a', 'b', 'c'))
def testProvidesConvenientShortcutForMatchingWithEqualTo(self):
self.assert_matches('Values automatically wrapped with equal_to',
has_items('a', 'b', 'c'),
('a', 'b', 'c'))
def testShouldMatchCollectionContainingAllItemsInDifferentOrder(self):
self.assert_matches('all items in different order',
has_items('a', 'b', 'c'),
('c', 'b', 'a'))
def testShouldMatchCollectionContainingAllItemsPlusExtras(self):
self.assert_matches('all items plus extras',
has_items('a', 'b', 'c'),
('e', 'c', 'b', 'a', 'd'))
def testNoMatchIfCollectionDoesntSatisfyAllMatchers(self):
self.assert_does_not_match("missing 'a'",
has_items('a', 'b', 'c'),
('e', 'c', 'b', 'd'))
def testHasAReadableDescription(self):
self.assert_description(
"(a sequence containing 'a' and a sequence containing 'b')",
has_items('a', 'b'))
def testSuccessfulMatchDoesNotGenerateMismatchDescription(self):
self.assert_no_mismatch_description(has_items('a', 'b'), ['a', 'b'])
def testMismatchDescriptionShowsFirstUnmetMatcherAndActualArgument(self):
self.assert_mismatch_description("a sequence containing 'a' was <42>",
has_items('a', 'b'), 42)
def testDescribeMismatch(self):
self.assert_describe_mismatch("a sequence containing 'a' was <42>",
has_items('a', 'b'), 42)
if __name__ == '__main__':
unittest.main()
|