def many_from_lines(klass, lines, filename=None, original_string=None): """Parses a set of steps from lines of input. This will correctly parse and produce a list of steps from lines without any Scenario: heading at the top. Examples in table form are correctly parsed, but must be well-formed under a regular step sentence. """ invalid_first_line_error = '\nFirst line of step "%s" is in %s form.' if lines and strings.wise_startswith(lines[0], u'|'): raise LettuceSyntaxError( None, invalid_first_line_error % (lines[0], 'table')) if lines and strings.wise_startswith(lines[0], u'"""'): raise LettuceSyntaxError( None, invalid_first_line_error % (lines[0], 'multiline')) # Select only lines that aren't end-to-end whitespace lines = filter(lambda x: not REP.only_whitespace.match(x), lines) step_strings = [] in_multiline = False for line in lines: if strings.wise_startswith(line, u'"""'): in_multiline = not in_multiline step_strings[-1] += "\n%s" % line elif strings.wise_startswith(line, u"|") or in_multiline: step_strings[-1] += "\n%s" % line elif '#' in line: step_strings.append(klass._handle_inline_comments(line)) else: step_strings.append(line) mkargs = lambda s: [s, filename, original_string] return [klass.from_string(*mkargs(s)) for s in step_strings]
def _parse_remaining_lines(self, lines, with_file, original_string): invalid_first_line_error = '\nInvalid step on scenario "%s".\n' \ 'Maybe you killed the first step text of that scenario\n' if lines and strings.wise_startswith(lines[0], u'|'): raise LettuceSyntaxError(with_file, invalid_first_line_error % self.name) return Step.many_from_lines(lines, with_file, original_string)
def many_from_lines(klass, lines, filename=None, original_string=None): """Parses a set of steps from lines of input. This will correctly parse and produce a list of steps from lines without any Scenario: heading at the top. Examples in table form are correctly parsed, but must be well-formed under a regular step sentence. """ invalid_first_line_error = '\nFirst line of step "%s" is in %s form.' if lines and strings.wise_startswith(lines[0], '|'): raise LettuceSyntaxError( None, invalid_first_line_error % (lines[0], 'table')) if lines and strings.wise_startswith(lines[0], '"""'): raise LettuceSyntaxError( None, invalid_first_line_error % (lines[0], 'multiline')) # Select only lines that aren't end-to-end whitespace and aren't tags # Tags could be included as steps if the first scenario following a background is tagged # This then causes the test to fail, because lettuce looks for the step's definition (which doesn't exist) lines = [ x for x in lines if not (REP.only_whitespace.match(x) or re.match(r'^\s*@', x)) ] step_strings = [] in_multiline = False for line in lines: if strings.wise_startswith(line, '"""'): in_multiline = not in_multiline step_strings[-1] += "\n%s" % line elif strings.wise_startswith(line, "|") or in_multiline: step_strings[-1] += "\n%s" % line elif '#' in line: step_strings.append(klass._handle_inline_comments(line)) else: step_strings.append(line) mkargs = lambda s: [s, filename, original_string] return [klass.from_string(*mkargs(s)) for s in step_strings]
def test_wise_startswith_ignores_case(): "strings.wise_startswith ignores case" assert strings.wise_startswith("Gabriel", "g") assert strings.wise_startswith("Gabriel", "G") assert strings.wise_startswith("'Gabriel", "'") assert strings.wise_startswith("#Gabriel", "#") assert strings.wise_startswith("$Gabriel", "$") assert strings.wise_startswith("^Gabriel", "^")