Beispiel #1
0
 def testNoMatchIfArgumentFailsToSatisfyAnyOfManyOtherMatchers(self):
     self.assert_does_not_match(
         "all matchers",
         any_of(
             equal_to("bad"), equal_to("bad"), equal_to("bad"), equal_to("bad"), equal_to("bad")
         ),
         "good",
     )
Beispiel #2
0
 def testMatchesIfArgumentSatisfiesAnyOfManyOtherMatchers(self):
     self.assert_matches(
         "matcher in the middle",
         any_of(
             equal_to("bad"), equal_to("bad"), equal_to("good"), equal_to("bad"), equal_to("bad")
         ),
         "good",
     )
def only_contains(*items):
    """Matches if each element of sequence satisfies any of the given matchers.

    :param match1,...: A comma-separated list of matchers.

    This matcher iterates the evaluated sequence, confirming whether each
    element satisfies any of the given matchers.

    Example::

        only_contains(less_than(4))

    will match ``[3,1,2]``.

    Any argument that is not a matcher is implicitly wrapped in an
    :py:func:`~hamcrest.core.core.isequal.equal_to` matcher to check for
    equality.

    """
    matchers = []
    for item in items:
        matchers.append(wrap_matcher(item))
    return IsSequenceOnlyContaining(any_of(*matchers))
def only_contains(*items):
    """Matches if each element of sequence satisfies any of the given matchers.

    :param match1,...: A comma-separated list of matchers.

    This matcher iterates the evaluated sequence, confirming whether each
    element satisfies any of the given matchers.

    Example::

        only_contains(less_than(4))

    will match ``[3,1,2]``.

    Any argument that is not a matcher is implicitly wrapped in an
    :py:func:`~hamcrest.core.core.isequal.equal_to` matcher to check for
    equality.

    """
    matchers = []
    for item in items:
        matchers.append(wrap_matcher(item))
    return IsSequenceOnlyContaining(any_of(*matchers))
Beispiel #5
0
 def testDescribeMismatch(self):
     self.assert_describe_mismatch(
         "was 'ugly'", any_of(equal_to("bad"), equal_to("good")), "ugly"
     )
Beispiel #6
0
 def testMismatchDescriptionDescribesFirstFailingMatch(self):
     self.assert_mismatch_description(
         "was 'ugly'", any_of(equal_to("bad"), equal_to("good")), "ugly"
     )
Beispiel #7
0
 def testSuccessfulMatchDoesNotGenerateMismatchDescription(self):
     self.assert_no_mismatch_description(any_of(equal_to("good"), equal_to("bad")), "good")
Beispiel #8
0
 def testHasAReadableDescription(self):
     self.assert_description(
         "('good' or 'bad' or 'ugly')",
         any_of(equal_to("good"), equal_to("bad"), equal_to("ugly")),
     )
Beispiel #9
0
 def testNoMatchIfArgumentFailsToSatisfyEitherOfTwoOtherMatchers(self):
     self.assert_does_not_match(
         "either matcher", any_of(equal_to("bad"), equal_to("bad")), "good"
     )
Beispiel #10
0
 def testProvidesConvenientShortcutForMatchingWithEqualTo(self):
     self.assert_matches("first matcher", any_of("good", "bad"), "good")
     self.assert_matches("second matcher", any_of("bad", "good"), "good")
     self.assert_matches("both matchers", any_of("good", "good"), "good")
Beispiel #11
0
 def testMatchesIfArgumentSatisfiesEitherOrBothOfTwoOtherMatchers(self):
     self.assert_matches("first matcher", any_of(equal_to("good"), equal_to("bad")), "good")
     self.assert_matches("second matcher", any_of(equal_to("bad"), equal_to("good")), "good")
     self.assert_matches("both matchers", any_of(equal_to("good"), equal_to("good")), "good")
Beispiel #12
0
 def __init__(self, resource_type_matcher, resource_logical_id_matcher):
     """Init the stack resource matcher class."""
     self.resource_type_matcher = resource_type_matcher
     self.resource_logical_id_matcher = resource_logical_id_matcher
     self.resource_status_matcher = any_of('UPDATE_COMPLETE', 'CREATE_COMPLETE')