def test_callable(self): def userfunc(x): return x == 1 pred_handler, repr_string = _get_matcher_parts(userfunc) self.assertTrue(pred_handler(1)) self.assertFalse(pred_handler(2)) self.assertEqual(repr_string, 'userfunc') userlambda = lambda x: x == 1 pred_handler, repr_string = _get_matcher_parts(userlambda) self.assertTrue(pred_handler(1)) self.assertFalse(pred_handler(2)) self.assertEqual(repr_string, '<lambda>')
def test_regex(self): regex = re.compile('ab[cd]') pred_handler, repr_string = _get_matcher_parts(regex) self.assertTrue(pred_handler('abc')) self.assertFalse(pred_handler('abe')) self.assertEqual(repr_string, "re.compile('ab[cd]')")
def test_no_special_handling(self): self.assertIsNone(_get_matcher_parts(1)) self.assertIsNone(_get_matcher_parts(0))
def test_set(self): myset = set(['a']) pred_handler, repr_string = _get_matcher_parts(myset) self.assertTrue(pred_handler('a')) self.assertFalse(pred_handler('b')) self.assertEqual(repr_string, repr(myset))
def test_nan(self): pred_handler, repr_string = _get_matcher_parts(float('nan')) self.assertIs(pred_handler, _check_nan) self.assertEqual(repr_string, "float('nan')")
def test_falsy(self): pred_handler, repr_string = _get_matcher_parts(False) self.assertIs(pred_handler, _check_falsy) self.assertEqual(repr_string, 'False')
def test_truthy(self): pred_handler, repr_string = _get_matcher_parts(True) self.assertIs(pred_handler, _check_truthy) self.assertEqual(repr_string, 'True')
def test_ellipsis_wildcard(self): pred_handler, repr_string = _get_matcher_parts(Ellipsis) self.assertIs(pred_handler, _check_wildcard) self.assertEqual(repr_string, '...')
def test_type(self): pred_handler, repr_string = _get_matcher_parts(int) self.assertTrue(pred_handler(1)) self.assertFalse(pred_handler(1.0)) self.assertEqual(repr_string, 'int')