# Path: marvinbot/filters.py
# class RegexpFilter(BaseFilter):
#     def __init__(self, pattern, mode='match', **options):
#         """Takes a pattern, and returns a match object if it complies.
# 
#         Support caching."""
#         if mode not in ['match', 'search']:
#             raise ValueError('Mode should be either match or search')
#         self.mode = mode
#         self.pattern = re.compile(pattern, **options)
#         self.plain_pattern = pattern
# 
#     def filter(self, message):
#         return bool(message.text is not None and self.pattern.match(message.text))
# 
#     # @cache.cache_on_arguments()
#     # def __call__(self, expression):
#     #     func = getattr(self.pattern, self.mode)
#     #     return func(expression)
#     #
#     # def cache_hash(self):
#     #     return self.plain_pattern
# 
# class MultiRegexpFilter(RegexpFilter):
#     def __init__(self, patterns, **kwargs):
#         """Takes a group of patterns and evaluates them.
# 
#         If patterns is a dict, add a capture group for each pattern."""
#         super(MultiRegexpFilter, self).__init__(self.build_pattern(patterns), **kwargs)
# 
#     @staticmethod
#     def build_pattern(patterns):
#         if isinstance(patterns, dict):
#             return "({})".format('|'.join([r'(?P<{name}>{pattern})'.format(name=name,
#                                                                            pattern=pattern)
#                                            for name, pattern in patterns.items()]))
#         elif isinstance(patterns, list):
#             return "({})".format('|'.join(patterns))


from marvinbot.filters import RegexpFilter, MultiRegexpFilter
import pytest


def test_basic_match():
    filt = RegexpFilter(r't[e]+st', mode='match')
    assert filt('test') is not None
    assert filt('teeeest').group(0) == 'teeeest'


def test_basic_search():
    filt = RegexpFilter(r't[e]+st', mode='search')
    assert filt('somethigntotest') is not None
    assert filt('someteeeest').group(0) == 'teeeest'


def test_basic_no_match():
    filt = RegexpFilter(r't[e]+st', mode='match')
    assert filt('something') is None


def test_wrong_mode():
    pytest.raises(ValueError, RegexpFilter, r't[e]+st', mode='unknown')
    pytest.raises(ValueError, MultiRegexpFilter, [r't[e]+st'], mode='unknown')


def test_multi_match():

# Path: marvinbot/filters.py
# class RegexpFilter(BaseFilter):
#     def __init__(self, pattern, mode='match', **options):
#         """Takes a pattern, and returns a match object if it complies.
# 
#         Support caching."""
#         if mode not in ['match', 'search']:
#             raise ValueError('Mode should be either match or search')
#         self.mode = mode
#         self.pattern = re.compile(pattern, **options)
#         self.plain_pattern = pattern
# 
#     def filter(self, message):
#         return bool(message.text is not None and self.pattern.match(message.text))
# 
#     # @cache.cache_on_arguments()
#     # def __call__(self, expression):
#     #     func = getattr(self.pattern, self.mode)
#     #     return func(expression)
#     #
#     # def cache_hash(self):
#     #     return self.plain_pattern
# 
# class MultiRegexpFilter(RegexpFilter):
#     def __init__(self, patterns, **kwargs):
#         """Takes a group of patterns and evaluates them.
# 
#         If patterns is a dict, add a capture group for each pattern."""
#         super(MultiRegexpFilter, self).__init__(self.build_pattern(patterns), **kwargs)
# 
#     @staticmethod
#     def build_pattern(patterns):
#         if isinstance(patterns, dict):
#             return "({})".format('|'.join([r'(?P<{name}>{pattern})'.format(name=name,
#                                                                            pattern=pattern)
#                                            for name, pattern in patterns.items()]))
#         elif isinstance(patterns, list):
#             return "({})".format('|'.join(patterns))


# Path: tests/test_filters.py
from marvinbot.filters import RegexpFilter, MultiRegexpFilter
import pytest



def test_basic_match():
    filt = RegexpFilter(r't[e]+st', mode='match')
    assert filt('test') is not None
    assert filt('teeeest').group(0) == 'teeeest'


def test_basic_search():
    filt = RegexpFilter(r't[e]+st', mode='search')
    assert filt('somethigntotest') is not None
    assert filt('someteeeest').group(0) == 'teeeest'


def test_basic_no_match():
    filt = RegexpFilter(r't[e]+st', mode='match')
    assert filt('something') is None


def test_wrong_mode():
    pytest.raises(ValueError, RegexpFilter, r't[e]+st', mode='unknown')
    pytest.raises(ValueError, MultiRegexpFilter, [r't[e]+st'], mode='unknown')


def test_multi_match():

    filt = MultiRegexpFilter({'exp1': r't[e]+st', 'exp2': r's[o]+me'})