def __process(self, text): if self.action == 'm': result = RexMatch() match = self.re.search(text) if match is not None: rex.group = result result[0] = match.group() result.update(enumerate(match.groups(), start=1)) result.update(match.groupdict()) return result elif self.action == 's': return self.re.sub(self.replacement, text, self.flags)
def test_rex_match_get_empty(): rm = RexMatch((('c', None),)) assert rm.get('a') is None assert rm.get('a', 'b') == 'b' assert rm.get('c', 'b') == 'b'
def test_rex_match_empty(): rm = RexMatch() assert rm['a'] is None assert rm['b'] is None assert str(rm) == '' assert rm.__unicode__() == u''
def test_rex_match(): rm = RexMatch(((0, 'some match'), ('a', 1), ('b', 2))) assert rm['a'] == 1 assert rm['b'] == 2 assert str(rm) == 'some match' assert rm.__unicode__() == u'some match'
def test_rex_match_get_empty(): rm = RexMatch((('c', None), )) assert rm.get('a') is None assert rm.get('a', 'b') == 'b' assert rm.get('c', 'b') == 'b'
def test_rex_match_get_empty(self): rm = RexMatch((('c', None),)) self.assertEqual(rm.get('a'), None) self.assertEqual(rm.get('a', 'b'), 'b') self.assertEqual(rm.get('c', 'b'), 'b')
def test_rex_match_get_empty(self): rm = RexMatch((('c', None), )) self.assertEqual(rm.get('a'), None) self.assertEqual(rm.get('a', 'b'), 'b') self.assertEqual(rm.get('c', 'b'), 'b')
def test_rex_match_empty(self): rm = RexMatch() self.assertEqual(rm['a'], None) self.assertEqual(rm['b'], None) self.assertEqual(str(rm), '') self.assertEqual(unicode(rm), u'')
def test_rex_match(self): rm = RexMatch(((0, 'some match'), ('a', 1), ('b', 2))) self.assertEqual(rm['a'], 1) self.assertEqual(rm['b'], 2) self.assertEqual(str(rm), 'some match') self.assertEqual(unicode(rm), u'some match')
re_flags = [Rex.FLAGS[f] for f in expression[end + 1:]] except KeyError: raise ValueError('Bad flags') rex_obj = Rex(action, pattern, replacement, reduce(operator.or_, re_flags, 0)) if cache: REX_CACHE[expression] = rex_obj if text is not None: return text == rex_obj else: return rex_obj rex.group = RexMatch() def rex_clear_cache(): global REX_CACHE REX_CACHE = {} ########NEW FILE######## __FILENAME__ = test_rex import re import pytest import rex as rex_module from rex import rex_clear_cache, RexMatch, rex