aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/PyHamcrest/src/hamcrest/library/collection/isin.py
blob: 438ac9b1441733ed0218a9e485514e5c9da37f2e (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)