aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/PyHamcrest/hamcrest/library/collection/isin.py
blob: 87962a2474b4ad4846efba1cb9ac95b2254e2b20 (plain) (blame)
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
from hamcrest.core.base_matcher import BaseMatcher

__author__ = "Jon Reid"
__copyright__ = "Copyright 2011 hamcrest.org"
__license__ = "BSD, see License.txt"


class IsIn(BaseMatcher):

    def __init__(self, sequence):
        self.sequence = sequence

    def _matches(self, item):
        return item in self.sequence

    def describe_to(self, description):
        description.append_text('one of ')      \
                   .append_list('(', ', ', ')', self.sequence)


def is_in(sequence):
    """Matches if evaluated object is present in a given sequence.

    :param sequence: The sequence to search.

    This matcher invokes the ``in`` membership operator to determine if the
    evaluated object is a member of the sequence.

    """
    return IsIn(sequence)