def test_search_wrong_type(self): uut = SearcherCollection([ RegexSearcher(b'omicron'), RegexSearcher(b'[eu]psilon'), ]) with self.assertRaises(TypeError): uut.search(u('pi omicron mu'))
def test_mismatched_types(self): text_searcher = RegexSearcher(u('omicron')) with self.assertRaises(TypeError): text_searcher.search(b'omicron') binary_searcher = RegexSearcher(b'omicron') with self.assertRaises(TypeError): binary_searcher.search(u('omicron'))
def test_constructor_text_pattern(self): searcher = RegexSearcher(u('Unicode pattern')) self.assertEqual(searcher.match_type, six.text_type) searcher = RegexSearcher(b'ASCII pattern') self.assertEqual(searcher.match_type, six.binary_type) searcher = RegexSearcher(re.compile(u('Unicode precompiled'))) self.assertEqual(searcher.match_type, six.text_type) searcher = RegexSearcher(re.compile(b'ASCII precompiled')) self.assertEqual(searcher.match_type, six.binary_type)
def test_multi_regex_single_match(self): uut = SearcherCollection([ RegexSearcher('omicron'), RegexSearcher('[eu]psilon'), ]) match = uut.search('pi epsilon iota rho') self.assertIsNotNone(match) self.assertEqual(1, uut.index(match.searcher)) self.assertEqual(3, match.start) self.assertEqual(10, match.end)
def test_multi_regex_multi_match(self): uut = SearcherCollection([ RegexSearcher(u('omicron')), RegexSearcher(u('[eu]psilon')), TextSearcher(u('pi')), TextSearcher(u('iota')), ]) match = uut.search(u('pi iota epsilon upsilon omicron')) self.assertIsNotNone(match) self.assertEqual(2, uut.index(match.searcher)) self.assertEqual(0, match.start) self.assertEqual(2, match.end)
def test_repr(self): # Only check no exceptions thrown match = RegexMatch(RegexSearcher(u('rho')), 'rho', 0, 3, None) repr(match)
def test_repr(self): # Only check no exceptions thrown searcher = SearcherCollection([TextSearcher(u('epsilon')), RegexSearcher(u('[eu]psilon'))]) repr(searcher)
def test_repr(self): # Only check no exceptions thrown searcher = RegexSearcher('[eu]psilon') repr(searcher)
def test_single_regex_multi_match(self): uut = RegexSearcher('omicron') match = uut.search('pi delta omicron rho omicron') self.assertIsNotNone(match) self.assertEqual(9, match.start) self.assertEqual(16, match.end)
def test_binary(self): uut = RegexSearcher(b'omicron') match = uut.search(b'omicron pi rho') self.assertIsNotNone(match) self.assertEqual(0, match.start) self.assertEqual(7, match.end)
def test_text(self): uut = RegexSearcher(u('omicron')) match = uut.search(u('omicron pi rho')) self.assertIsNotNone(match) self.assertEqual(0, match.start) self.assertEqual(7, match.end)
def test_no_patterns(self): with self.assertRaises(TypeError): RegexSearcher(None) with self.assertRaises(TypeError): RegexSearcher(5)