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)
def from_string(new_feature, string, with_file=None, language=None): """Creates a new feature from string""" lines = strings.get_stripped_lines(string, ignore_lines_starting_with='#') tags = [] if not language: language = Language() while strings.steal_tags_from_line(lines[0], tags): lines.pop(0) found = len(re.findall(r'%s:[ ]*\w+' % language.feature, "\n".join(lines), re.U)) if found > 1: raise LettuceSyntaxError( with_file, 'A feature file must contain ONLY ONE feature!' ) elif found == 0: raise LettuceSyntaxError( with_file, 'Features must have a name that start with a word letter (not an odd character). e.g: "Feature: This is my name"' ) while lines: matched = re.search(r'%s:(.*)' % language.feature, lines[0], re.I) if matched: name = matched.groups()[0].strip() break line = lines.pop(0) feature = new_feature(name=name, remaining_lines=lines, with_file=with_file, original_string=string, language=language, tags=tags) return feature