Esempio n. 1
0
    def describe_table(table, indentation=None):
        """
        Provide a textual description of the table (as used w/ Gherkin).

        :param table:  Table to use (as :class:`Pyautomators.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 = u"|"
            for c, (cell, max_length) in enumerate(zip(row, max_lengths)):
                pad_size = max_length - cell_lengths[r][c]
                line += u" %s%s |" % (escape_cell(cell), " " * pad_size)
            line += u"\n"
            lines.append(line)

        if indentation:
            return indent(lines, indentation)
        # -- OTHERWISE:
        return u"".join(lines)
Esempio n. 2
0
    def print_description(self, description, indentation, newline=True):
        if not description:
            return

        self.stream.write(indent(description, indentation))
        if newline:
            self.stream.write("\n")
Esempio n. 3
0
 def doc_string(self, doc_string):
     #self.stream.write('      """' + doc_string.content_type + '\n')
     doc_string = _text(doc_string)
     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()
Esempio n. 4
0
 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")
Esempio n. 5
0
    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 = u'"""\n' + text + '\n"""\n'

        if indentation:
            text = indent(text, indentation)
        return text
Esempio n. 6
0
    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 = u'\[email protected]\n'
        if self.show_tags and scenario.tags:
            header_line += u'\n  %s\n' % self.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 += self.describe_step(step)
        step_indentation = make_indentation(4)
        return header_line + indent(text, step_indentation) + footer_line
Esempio n. 7
0
 def result(self, step):
     if not self.monochrome:
         lines = self.step_lines + 1
         if self.show_multiline:
             if step.table:
                 lines += len(step.table.rows) + 1
             if step.text:
                 lines += len(step.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(step.status, arguments, location, True)
     if step.error_message:
         self.stream.write(indent(step.error_message.strip(), u"      "))
         self.stream.write("\n\n")
     self.stream.flush()
Esempio n. 8
0
    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")