def test_contents(self): "tests for contents of match object" expected = 'Regular Expressions' first = 'Regular' second = 'Expressions' reobj = findregex(text) self.assertEqual(reobj.group(1), first) self.assertEqual(reobj.group(2), second) self.assertEqual(reobj.group(), expected)
def test_startend(self): "tests for start of regex" expected_start = 231 expected_end = 250 expected = (231, 250) reobj = findregex(text) self.assertEqual(reobj.start(), expected_start) self.assertEqual(reobj.end(), expected_end) self.assertEqual(reobj.span(), expected)
def test_findregex(self): ''' Test the start and end position of "Regular Expressions" in the text bellow ''' words = 'Regular Expressions' text = 'In the 1950s, mathematician Stephen Cole Kleene described automata ' text += 'theory and formal language theory in a set of models using a notation' text += ' called "regular sets" as a method to do pattern matching. Active usage' text += ' of this system, called Regular Expressions, started in the 1960s and ' text += 'continued under such pioneers as David J. Farber, Ralph E. Griswold, ' text += 'Ivan P. Polonsky, Ken Thompson, and Henry Spencer.' observed = findregex(text, words) self.assertEqual(observed, (231, 250), "Expected position are (231, 250), Observed position are %s" % str(observed))
def test_none(self): "tests that bad regex is not matched" self.assertIsNone(findregex('regular expressions'), msg=None)