src.hamcrest.core.core.AnyOf.__init__()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 1
dl 0
loc 2
rs 10
1
from hamcrest.core.base_matcher import BaseMatcher
2
from hamcrest.core.helpers.wrap_matcher import wrap_matcher
3
4
__author__ = "Jon Reid"
5
__copyright__ = "Copyright 2011 hamcrest.org"
6
__license__ = "BSD, see License.txt"
7
8
9
class AnyOf(BaseMatcher):
10
11
    def __init__(self, *matchers):
12
        self.matchers = matchers
13
14
    def _matches(self, item):
15
        for matcher in self.matchers:
16
            if matcher.matches(item):
17
                return True
18
        return False
19
20
    def describe_to(self, description):
21
        description.append_list('(', ' or ', ')', self.matchers)
22
23
24
def any_of(*items):
25
    """Matches if any of the given matchers evaluate to ``True``.
26
27
    :param matcher1,...:  A comma-separated list of matchers.
28
29
    The matchers are evaluated from left to right using short-circuit
30
    evaluation, so evaluation stops as soon as a matcher returns ``True``.
31
32
    Any argument that is not a matcher is implicitly wrapped in an
33
    :py:func:`~hamcrest.core.core.isequal.equal_to` matcher to check for
34
    equality.
35
36
    """
37
    return AnyOf(*[wrap_matcher(item) for item in items])
38