Commit 2c7a6ff7 by Gabriel Falcão

Merge pull request #496 from nathanial/compiled-regexes

added compiled regexes
parents d0e446b3 9f9849fc
......@@ -357,9 +357,9 @@ class Step(object):
def _get_match(self, ignore_case):
matched, func = None, lambda: None
for regex, func in STEP_REGISTRY.items():
matched = re.search(regex, self.sentence, ignore_case and re.I or 0)
for step, func in STEP_REGISTRY.items():
regex = STEP_REGISTRY.get_regex(step, ignore_case)
matched = regex.search(self.sentence)
if matched:
break
......@@ -1354,4 +1354,3 @@ class SummaryTotalResults(TotalResult):
self._proposed_definitions.extend(scenario_result.steps_undefined)
if len(scenario_result.steps_failed) > 0:
self.failed_scenario_locations.append(scenario_result.scenario.represented())
......@@ -41,6 +41,24 @@ class CallbackDict(dict):
callback_list[:] = []
class StepDict(dict):
def __init__(self, *args, **kwargs):
super(StepDict, self).__init__(*args, **kwargs)
self._compiled = {}
self._compiled_ignore_case = {}
def get_regex(self, step, ignore_case=False):
if ignore_case:
regex = self._compiled_ignore_case.get(step, None)
if not regex:
regex = re.compile(step, re.I)
self._compiled_ignore_case[step] = regex
else:
regex = self._compiled.get(step, None)
if not regex:
regex = re.compile(step)
self._compiled[step] = regex
return regex
def load(self, step, func):
self._assert_is_step(step, func)
self[step] = func
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment