def test_error(self): regex = re.compile('abc') with self.assertRaisesRegex(TypeError, "got int: 123"): self.assertFalse(_check_regex(regex, 123)) # Regex fails with TypeError. with self.assertRaisesRegex(TypeError, "got tuple: \('a', 'b'\)"): self.assertFalse(_check_regex(regex, ('a', 'b')))
def test_function(self): regex = re.compile('(Ch|H)ann?ukk?ah?') function = lambda x: _check_regex(regex, x) self.assertTrue(function('Happy Hanukkah')) self.assertTrue(function('Happy Chanukah')) self.assertFalse(function('Merry Christmas'))
def test_identity(self): regex = re.compile('abc') self.assertTrue(_check_regex(regex, regex))
def test_incompatible_types(self): regex = re.compile('abc') self.assertFalse(_check_regex(regex, 123)) self.assertFalse(_check_regex(regex, ('a', 'b')))