def test_keyword_regexes_are_cached(self): for text in [u'cat', u'dog', u'mouse']: tr = TriggerRuleFactory(keywords=[text]) tr.match_description(text) tr = TriggerRuleFactory(keywords=[text]) tr.match_description(text) cache_info = _generate_keywords_regex.cache_info() assert cache_info.hits >= 3
def test_match_keywords(self): tests = [ # tr.keywords, description, expected ([], u'', True), ([], u'my dog has fleas', True), ([u'my'], u'', False), ([u'my'], u'my dog has fleas', True), ([u'my'], u'MY DOG HAS FLEAS', True), ([u'your', u'dog'], u'my dog has fleas', True), ([u'my dog'], u'my dog has fleas', True), ([u'my dog'], u'your dog has fleas', False), ([u'my dog', u'cat'], u'my dog has fleas', True), ([u'my cat'], u'my dog has fleas', False), ([u'my cat'], u'my cat hat fleas', True), ([u'my cat'], u'my cat hat fleas', True), ([u'\xca'], u'abcd \xca abcd', True), ([u'my-cat'], u'my-cat has fleas', True), ([u'(my cat)'], u'(my cat) has fleas', True), ([u'cat'], u'i love my cat!', True), ([u'cat'], u'(cat)', True), ] for tr_keywords, description, expected in tests: tr = TriggerRuleFactory(keywords=tr_keywords) assert tr.match_description(description) == expected