def _parse_remaining_lines(self, lines, original_string, with_file=None): joined = u"\n".join(lines[1:]) # replacing occurrences of Scenario Outline, with just "Scenario" scenario_prefix = u'%s:' % self.language.first_of_scenario regex = re.compile(u"%s:\s" % self.language.scenario_separator, re.U | re.I) joined = regex.sub(scenario_prefix, joined) parts = strings.split_wisely(joined, scenario_prefix) description = u"" tags_array = [] first_tags = [] if not re.search("^" + scenario_prefix, joined): description = parts[0] first_tags, description_array = strings.steal_tags_from_lines(description.split("\n")) description = u"\n".join(description_array) parts.pop(0) tags_array.append(first_tags) scenario_strings = [ u"%s: %s" % (self.language.first_of_scenario, s) for s in parts if s.strip() ] tmp = [] for s in scenario_strings: split_lines = s.split("\n") tags, minus_tags = strings.steal_tags_from_lines(split_lines) tmp.append(u"\n".join(minus_tags)) tags_array.append(tags) scenario_strings = tmp kw = dict( original_string=original_string, with_file=with_file, language=self.language ) scenarios = [] for s in scenario_strings: scenario_tags = tags_array[0] + self.tags tags_array.pop(0) scenarios.append(Scenario.from_string(s, scenario_tags, **kw)) return scenarios, description
def from_string(cls, string, with_file=None, original_string=None): """Creates a new step from string""" lines = strings.get_stripped_lines(string) tags, lines = strings.steal_tags_from_lines(lines) sentence = lines.pop(0) line = None if with_file and original_string: for pline, line in enumerate(original_string.splitlines()): if sentence in line: line = pline + 1 break return cls(sentence, remaining_lines=lines, line=line, filename=with_file, tags=tags)
def test_steal_right_tags(): tags = [] rc = strings.steal_tags_from_line(" @red, @blue", tags) assert_equals(["red", "blue"], tags) assert_equals(rc, True) tags = [] rc = strings.steal_tags_from_line(" @red Something that could be a scenario description line @blue", tags) assert_equals([], tags) assert_equals(rc, False) lines=["first line with zero tags", "@nice @tags-only, @indeed", "@starting with something taggish", "having a @tag in the middle", "or at @end"] orig_lines = lines[:] tags, non_tag_lines = strings.steal_tags_from_lines(lines) assert_equals(["nice", "tags-only", "indeed"], tags) assert_equals(len(non_tag_lines), len(orig_lines)-1)