File: issequence_containinginanyorder_test.py

package info (click to toggle)
pyhamcrest 1.6-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 556 kB
  • sloc: python: 2,938; makefile: 2
file content (76 lines) | stat: -rw-r--r-- 3,008 bytes parent folder | download
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
if __name__ == '__main__':
    import sys
    sys.path.insert(0, '..')
    sys.path.insert(0, '../..')

from hamcrest.library.collection.issequence_containinginanyorder 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 IsSequenceContainingInAnyOrderTest(MatcherTest):

    def testMatchingSingleItemSequence(self):
        self.assert_matches("Single item sequence",
                            contains_inanyorder(equal_to(1)), [1])

    def testMatchesSequenceInOrder(self):
        self.assert_matches("In order",
                            contains_inanyorder(equal_to(1), equal_to(2)), [1,2])

    def testMatchesSequenceOutOfOrder(self):
        self.assert_matches("Out of order",
                            contains_inanyorder(equal_to(1), equal_to(2)),
                            [2,1])

    def testProvidesConvenientShortcutForMatchingWithEqualTo(self):
        self.assert_matches("Values automatically wrapped with equal_to",
                            contains_inanyorder(1,2), [2,1])

    def testDoesNotMatchEmptySequence(self):
        self.assert_mismatch_description("no item matches: <1>, <2> in []",
                                         contains_inanyorder(1, 2), [])

    def testEmptySequenceMatchesEmptySequence(self):
        self.assert_matches("Empty sequence", contains_inanyorder(), [])

    def testDoesNotMatchIfOneOfMultipleItemsMismatch(self):
        self.assert_mismatch_description("not matched: <4>",
                                         contains_inanyorder(1,2,3), [1,2,4])

    def testDoesNotMatchWithMoreElementsThanExpected(self):
        self.assert_mismatch_description("not matched: <2>",
                                         contains_inanyorder(1,3), [1,2,3])

    def testDoesNotMatchWithFewerElementsThanExpected(self):
        self.assert_mismatch_description(
                            "no item matches: <4> in [<1>, <2>, <3>]",
                            contains_inanyorder(1,2,3,4), [1,2,3])

    def testMatchesAnyConformingSequence(self):
        self.assert_matches('quasi-sequence', contains_inanyorder(1,2),
                            QuasiSequence())
        self.assert_does_not_match('non-sequence', contains_inanyorder(1,2),
                                   object())

    def testHasAReadableDescription(self):
        self.assert_description("a sequence over [<1>, <2>] in any order",
                                contains_inanyorder(1,2))

    def testDescribeMismatch(self):
        self.assert_describe_mismatch('not matched: <3>',
                                      contains_inanyorder(1,2), [1,3])

    def testDescribeMismatchOfNonSequence(self):
        self.assert_describe_mismatch("was <3>", contains_inanyorder(1,2), 3)


if __name__ == '__main__':
    unittest.main()