def print_description(self, description, indentation, newline=True): if not description: return self.stream.write(indent(description, indentation)) if newline: self.stream.write('\n')
def print_comments(self, comments, indentation): if not comments: return text = indent([c.value for c in comments], indentation) self.writer.write(text, style="comments") self.writer.write('\n')
def describe_table(table, indentation=None): """ Provide a textual description of the table (as used w/ Gherkin). :param table: Table to use (as :class:`behave.model.Table`) :param indentation: Line prefix to use (as string, if any). :return: Textual table description (as unicode string). """ # -- STEP: Determine output size of all cells. cell_lengths = [] all_rows = [table.headings] + table.rows for row in all_rows: lengths = [len(escape_cell(c)) for c in row] cell_lengths.append(lengths) # -- STEP: Determine max. output size for each column. max_lengths = [] for col in range(0, len(cell_lengths[0])): max_lengths.append(max([c[col] for c in cell_lengths])) # -- STEP: Build textual table description. lines = [] for r, row in enumerate(all_rows): line = "|" for c, (cell, max_length) in enumerate(zip(row, max_lengths)): pad_size = max_length - cell_lengths[r][c] line += " %s%s |" % (escape_cell(cell), " " * pad_size) line += "\n" lines.append(line) if indentation: return indent(lines, indentation) # -- OTHERWISE: return "".join(lines)
def doc_string(self, doc_string): #self.stream.write(' """' + doc_string.content_type + '\n') prefix = ' ' self.stream.write('%s"""\n' % prefix) doc_string = escape_triple_quotes(indent(doc_string, prefix)) self.stream.write(doc_string) self.stream.write('\n%s"""\n' % prefix) self.stream.flush()
def print_description(self, description, indentation, newline=True): if not description: return self.writer.write(indent(description, indentation), style="description") if newline: self.writer.write('\n')
def doc_string(self, doc_string): #self.stream.write(' """' + doc_string.content_type + '\n') doc_string = _text(doc_string) prefix = u" " if self.current_rule: prefix += u" " self.stream.write(u'%s"""\n' % prefix) doc_string = escape_triple_quotes(indent(doc_string, prefix)) self.stream.write(doc_string) self.stream.write(u'\n%s"""\n' % prefix) self.stream.flush()
def result(self, result): if self.use_step_replay: lines = self.printer.step_lines + 1 self.terminal.move_cursor_up(lines) self.print_step(result.status, proceed=True) # XXX if result.error_message: error_message = indent(result.error_message.strip(), u' ') self.terminal.write(error_message, style="error") self.terminal.write('\n\n') self.terminal.flush() self._match = None
def write_step_definition(self, step_definition): step_definition_text = self.describe_step_definition(step_definition) self.stream.write(u"%s\n" % step_definition_text) doc = inspect.getdoc(step_definition.func) func_name = step_definition.func.__name__ if self.shows_function_name and func_name not in ("step", "impl"): self.stream.write(u" Function: %s()\n" % func_name) if self.shows_location: self.stream.write(u" Location: %s\n" % step_definition.location) if doc: doc = doc.strip() self.stream.write(indent(doc, self.doc_prefix)) self.stream.write("\n") self.stream.write("\n")
def describe_docstring(doc_string, indentation=None): """ Provide a textual description of the multi-line text/triple-quoted doc-string (as used w/ Gherkin). :param doc_string: Multi-line text to use. :param indentation: Line prefix to use (as string, if any). :return: Textual table description (as unicode string). """ text = escape_triple_quotes(doc_string) text = '"""\n' + text + '\n"""\n' if indentation: text = indent(text, indentation) return text
def describe_scenario(cls, scenario): """ Describe the scenario and the test status. NOTE: table, multiline text is missing in description. :param scenario: Scenario that was tested. :return: Textual description of the scenario. """ header_line = u'\[email protected]\n' header_line += ' %s: %s\n' % (scenario.keyword, scenario.name) footer_line = u'\[email protected]\n' + u'-' * 80 + '\n' text = u'' for step in scenario: text += cls.describe_step(step) step_indentation = make_indentation(4) return header_line + indent(text, step_indentation) + footer_line
def result(self, result): if self.use_step_replay: lines = self.printer.step_lines + 1 self.terminal.move_cursor_up(lines) status_name = result.status if Status: # -- SINCE: behave 1.2.6 with Status enum class status_name = result.status.name self.print_step(status_name, proceed=True) if result.error_message: error_message = indent(result.error_message.strip(), u' ') self.terminal.write(error_message, style="error") self.terminal.write('\n\n') self.terminal.flush() self._match = None
def describe_scenario(self, scenario): """Describe the scenario and the test status. NOTE: table, multiline text is missing in description. :param scenario: Scenario that was tested. :return: Textual description of the scenario. """ header_line = '\[email protected]\n' if self.show_tags and scenario.tags: header_line += '\n %s\n' % self.describe_tags(scenario.tags) header_line += ' %s: %s\n' % (scenario.keyword, scenario.name) footer_line = '\[email protected]\n' + '-' * 80 + '\n' text = '' for step in scenario: text += self.describe_step(step) step_indentation = make_indentation(4) return header_line + indent(text, step_indentation) + footer_line
def describe_scenario(cls, scenario): """ Describe the scenario and the test status. NOTE: table, multiline text is missing in description. :param scenario: Scenario that was tested. :return: Textual description of the scenario. """ header_line = u"\[email protected]\n" if cls.show_tags and scenario.tags: header_line += u"\n %s\n" % cls.describe_tags(scenario.tags) header_line += u" %s: %s\n" % (scenario.keyword, scenario.name) footer_line = u"\[email protected]\n" + u"-" * 80 + "\n" text = u"" for step in scenario: text += cls.describe_step(step) step_indentation = make_indentation(4) return header_line + indent(text, step_indentation) + footer_line
def result(self, result): if not self.monochrome: lines = self.step_lines + 1 if self.show_multiline: if result.table: lines += len(result.table.rows) + 1 if result.text: lines += len(result.text.splitlines()) + 2 self.stream.write(up(lines)) arguments = [] location = None if self._match: arguments = self._match.arguments location = self._match.location self.print_step(result.status, arguments, location, True) if result.error_message: self.stream.write(indent(result.error_message.strip(), u' ')) self.stream.write('\n\n') self.stream.flush()
def report_testcases(filename, testcases): print(u"REPORT: {0}".format(filename)) for xml_testcase in testcases: print(" TESTCASE: {0}".format(xml_testcase.get("name"))) xml_text = indent(xml_prettify(xml_testcase), " ") print(xml_text)
def print_comments(self, comments, indentation): if not comments: return self.stream.write(indent([c.value for c in comments], indentation)) self.stream.write('\n')