def test_basestring(self): f = filters.msg_filter("^Hello.*$") assert callable(f) assert f(m) f = filters.msg_filter("^Goodbye.*$") assert callable(f) assert not f(m)
def test_regex(self): f = filters.msg_filter(re.compile("^Hello.*$")) assert callable(f) assert f(m) f = filters.msg_filter(re.compile("^Goodbye.*$")) assert callable(f) assert not f(m)
def test_bool(self): f = filters.msg_filter(True) assert callable(f) assert f(m) f = filters.msg_filter(False) assert callable(f) assert not f(m)
def test_list(self): re1 = "^Hello.*$" re2 = "^.*Funnypants$" l = [re1, re2] f = filters.msg_filter(l) assert callable(f) assert f(m) re3 = "^.*Sillyhead$" l = (re1, re3) f = filters.msg_filter(l) assert callable(f) assert not f(m)
def test_list(self): re1 = "^Hello.*$" re2 = "^.*Funnypants$" filter_list = [re1, re2] f = filters.msg_filter(filter_list) assert callable(f) assert f(m) re3 = "^.*Sillyhead$" filter_tuple = (re1, re3) f = filters.msg_filter(filter_tuple) assert callable(f) assert not f(m)
def test_nested_list(self): # not encouraged as it's equivalent, but let's support it anyway re1 = "^Hello.*$" re2 = "^.*Funnypants$" filter_list = [re1, [re2]] f = filters.msg_filter(filter_list) assert callable(f) assert f(m)
def test_nested_list(self): # not encouraged as it's equivalent, but let's support it anyway re1 = "^Hello.*$" re2 = "^.*Funnypants$" l = [re1, [re2]] f = filters.msg_filter(l) assert callable(f) assert f(m)
def test_callable(self): f = filters.msg_filter(self._always_true) assert f is self._always_true
def test_None(self): f = filters.msg_filter(None) assert callable(f) assert f(m)
def test_bad_arg(self): with self.assertRaises(ValueError): f = filters.msg_filter(42)
def test_callable(self): my_func = lambda mesg: True f = filters.msg_filter(my_func) assert f is my_func
def test_bad_arg(self): with self.assertRaises(ValueError): filters.msg_filter(42)
def test_single_list(self): re1 = "^Hello.*$" l = [re1] f = filters.msg_filter(l) assert callable(f) assert f(m)
def test_single_list(self): re1 = "^Hello.*$" filter_list = [re1] f = filters.msg_filter(filter_list) assert callable(f) assert f(m)