isin.py 774 B

123456789101112131415161718192021222324252627282930
  1. from hamcrest.core.base_matcher import BaseMatcher
  2. __author__ = "Jon Reid"
  3. __copyright__ = "Copyright 2011 hamcrest.org"
  4. __license__ = "BSD, see License.txt"
  5. class IsIn(BaseMatcher):
  6. def __init__(self, sequence):
  7. self.sequence = sequence
  8. def _matches(self, item):
  9. return item in self.sequence
  10. def describe_to(self, description):
  11. description.append_text('one of ') \
  12. .append_list('(', ', ', ')', self.sequence)
  13. def is_in(sequence):
  14. """Matches if evaluated object is present in a given sequence.
  15. :param sequence: The sequence to search.
  16. This matcher invokes the ``in`` membership operator to determine if the
  17. evaluated object is a member of the sequence.
  18. """
  19. return IsIn(sequence)