def test_repr(self): def userfunc(x): return True matcher = _get_matcher(userfunc) self.assertEqual(repr(matcher), 'userfunc') userlambda = lambda x: True matcher = _get_matcher(userlambda) self.assertEqual(repr(matcher), '<lambda>')
def test_identity(self): def always_false(x): return False matcher = _get_matcher(always_false) self.assertTrue(matcher == always_false)
def test_identity_with_error(self): def fails_internally(x): # <- Helper function. raise TypeError('raising an error') matcher = _get_matcher(fails_internally) self.assertTrue(matcher == fails_internally)
def test_isinstance(self): matcher = _get_matcher(int) self.assertTrue(matcher == 0) self.assertTrue(matcher == 1) self.assertFalse(matcher == 0.0) self.assertFalse(matcher == 1.0)
def test_error(self): def fails_internally(x): # <- Helper function. raise TypeError('raising an error') matcher = _get_matcher(fails_internally) with self.assertRaises(TypeError): self.assertFalse(matcher == 'abc')
def test_error(self): matcher = _get_matcher(re.compile('abc')) with self.assertRaisesRegex(TypeError, "got int: 123"): self.assertFalse(matcher == 123) # Regex fails with TypeError. with self.assertRaisesRegex(TypeError, "got tuple: \('a', 'b'\)"): self.assertFalse(matcher == ('a', 'b'))
def test_returned_difference(self): """If predicate function returns a difference object, it should count as False. """ def true_or_difference(x): return x == 'foo' or Missing(x) matcher = _get_matcher(true_or_difference) self.assertTrue(matcher == 'foo') self.assertFalse(matcher == 'bar')
def test_equality(self): def divisible3or5(x): # <- Helper function. return (x % 3 == 0) or (x % 5 == 0) matcher = _get_matcher(divisible3or5) self.assertFalse(matcher == 1) self.assertFalse(matcher == 2) self.assertTrue(matcher == 3) self.assertFalse(matcher == 4) self.assertTrue(matcher == 5) self.assertTrue(matcher == 6)
def test_equality(self): matcher = _get_matcher(re.compile('(Ch|H)ann?ukk?ah?')) self.assertTrue(matcher == 'Happy Hanukkah') self.assertTrue(matcher == 'Happy Chanukah') self.assertFalse(matcher == 'Merry Christmas')
def test_repr(self): matcher = _get_matcher(Ellipsis) self.assertEqual(repr(matcher), '...')
def test_equality(self): matcher = _get_matcher(Ellipsis) self.assertTrue(matcher == 1) self.assertTrue(matcher == object()) self.assertTrue(matcher == None)
def test_repr(self): matcher = _get_matcher(set(['a'])) self.assertEqual(repr(matcher), repr(set(['a'])))
def test_whole_set_equality(self): matcher = _get_matcher(set(['a', 'b', 'c'])) self.assertTrue(matcher == set(['a', 'b', 'c']))
def test_equality(self): matcher = _get_matcher(set(['a', 'e', 'i', 'o', 'u'])) self.assertTrue(matcher == 'a') self.assertFalse(matcher == 'x')
def test_repr(self): matcher = _get_matcher(re.compile('abc')) self.assertEqual(repr(matcher), "re.compile('abc')")
def test_identity(self): regex = re.compile('abc') matcher = _get_matcher(regex) self.assertTrue(matcher == regex)