Commit d0d5692e by Chris McGraw

Adds tag parsing to features

Add tag parsing logic from scenarios up to the feature as well.  Also
extends a unit test to cover a scenario that we ran into where tags
would break when the previous scenario ended with a table.

[272]
parent e788f04e
......@@ -848,6 +848,11 @@ class Feature(object):
language)
self._set_definition(feature_definition)
if original_string and '@' in self.original_string:
self.tags = self._find_tags_in(original_string)
else:
self.tags = None
self._add_myself_to_scenarios()
@property
......@@ -867,6 +872,35 @@ class Feature(object):
def _add_myself_to_scenarios(self):
for scenario in self.scenarios:
scenario.feature = self
if scenario.tags and self.tags:
scenario.tags.extend(self.tags)
def _find_tags_in(self, original_string):
broad_regex = re.compile(ur"([@].*)%s: (%s)" % (
self.language.feature,
re.escape(self.name)), re.DOTALL)
regexes = [broad_regex]
def try_finding_with(regex):
found = regex.search(original_string)
if found:
tag_lines = found.group().splitlines()
tags = set(chain(*map(self._extract_tag, tag_lines)))
return tags
for regex in regexes:
found = try_finding_with(regex)
if found:
return found
return []
def _extract_tag(self, item):
regex = re.compile(r'(?:(?:^|\s+)[@]([^@\s]+))')
found = regex.findall(item)
return found
def __repr__(self):
return u'<%s: "%s">' % (self.language.first_of_feature, self.name)
......
......@@ -217,7 +217,9 @@ Feature: correct matching
@runme2
Scenario: Holy tag2, Batman (2)
Given this scenario has other tags
Then it can be inspected from within the object
Then it can be inspected from within the object even with the table
| What | Is | This |
| It | is | TABLE |
@runme3
Scenario: Holy tag3, Batman
......@@ -419,14 +421,17 @@ def test_single_feature_single_tag():
"All scenarios within a feature inherit the feature's tags"
feature = Feature.from_string(FEATURE15)
# FIXME (mitgr81): It seems worth the efficiency to not loop through the feature tags and
# check to see if every tag exists in the child. The "right" fix might just be to not
# add the tag from the feature in the first scenario directly.
assert that(feature.scenarios[0].tags).deep_equals([
'feature_runme', 'runme1'])
'feature_runme', 'runme1', 'feature_runme'])
assert that(feature.scenarios[1].tags).deep_equals([
'feature_runme', 'runme2'])
'runme2', 'feature_runme'])
assert that(feature.scenarios[2].tags).deep_equals([
'feature_runme', 'runme3'])
'runme3', 'feature_runme'])
def test_single_scenario_many_scenarios():
......
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