コード例 #1
0
ファイル: pretty2.py プロジェクト: imbrra/logowanie
    def __init__(self, stream_opener, config):
        super(Pretty2Formatter, self).__init__(stream_opener, config)
        # -- ENSURE: Output stream is open.
        self.stream = self.open()
        if self.use_new_impl:
            terminal_writer_class = select_terminal_class(config.color)
            self.terminal = terminal_writer_class(self.stream,
                                                  colored=config.color)
            terminal_width = get_terminal_size()[0]
            use_replay = self.terminal.has_feature("cursor_up")
        else:
            self.terminal = StyledTerminalWriter(self.stream,
                                                 colored=config.color)
            terminal_width = self.terminal.width
            use_replay = self.terminal.styled
        self.printer = ModelPrinter(self.terminal, config, terminal_width)
        self.use_step_replay = use_replay

        # -- UNUSED: self.tag_statement = None
        self.current_feature = None
        self.current_scenario = None
        self.statement = None
        self.steps = []
        self._uri = None
        self._match = None
コード例 #2
0
ファイル: pretty2.py プロジェクト: behave/behave.example
    def __init__(self, stream_opener, config):
        super(Pretty2Formatter, self).__init__(stream_opener, config)
        # -- ENSURE: Output stream is open.
        self.stream = self.open()
        if self.use_new_impl:
            terminal_writer_class = select_terminal_class(config.color)
            self.terminal = terminal_writer_class(self.stream, colored=config.color)
            terminal_width = get_terminal_size()[0]
            use_replay = self.terminal.has_feature("cursor_up")
        else:
            self.terminal = StyledTerminalWriter(self.stream, colored=config.color)
            terminal_width = self.terminal.width
            use_replay = self.terminal.styled
        self.printer = ModelPrinter(self.terminal, config, terminal_width)
        self.use_step_replay = use_replay

        # -- UNUSED: self.tag_statement = None
        self.current_feature = None
        self.current_scenario = None
        self.statement = None
        self.steps = []
        self._uri = None
        self._match = None
コード例 #3
0
ファイル: pretty2.py プロジェクト: behave/behave.example
class Pretty2Formatter(Formatter):
    name = 'pretty2'
    description = 'Standard colourised pretty formatter'
    use_new_impl = True

    def __init__(self, stream_opener, config):
        super(Pretty2Formatter, self).__init__(stream_opener, config)
        # -- ENSURE: Output stream is open.
        self.stream = self.open()
        if self.use_new_impl:
            terminal_writer_class = select_terminal_class(config.color)
            self.terminal = terminal_writer_class(self.stream, colored=config.color)
            terminal_width = get_terminal_size()[0]
            use_replay = self.terminal.has_feature("cursor_up")
        else:
            self.terminal = StyledTerminalWriter(self.stream, colored=config.color)
            terminal_width = self.terminal.width
            use_replay = self.terminal.styled
        self.printer = ModelPrinter(self.terminal, config, terminal_width)
        self.use_step_replay = use_replay

        # -- UNUSED: self.tag_statement = None
        self.current_feature = None
        self.current_scenario = None
        self.statement = None
        self.steps = []
        self._uri = None
        self._match = None

    def reset_statement(self):
        self.statement = None
        self.steps = []
        self._match = None
        self.printer.reset_statement()

    def reset(self):
        # -- UNUSED: self.tag_statement = None
        self.current_feature = None
        self.current_scenario = None
        self._uri = None
        self.reset_statement()

    def finish_last_statement(self):
        self.print_statement()
        self.print_unprocessed_steps()
        self.stream.flush()
        self.reset_statement()

    # -- FORMATTER API:
    def uri(self, uri):
        self.reset()
        self._uri = uri

    def feature(self, feature):
        self.current_feature = feature
        self.printer.print_feature_head(feature)

    def background(self, background):
        self.finish_last_statement()
        self.current_scenario = background
        self.statement = background

    def scenario(self, scenario):
        self.finish_last_statement()
        self.current_scenario = scenario
        self.statement = scenario

    def scenario_outline(self, scenario_outline):
        self.finish_last_statement()
        self.current_scenario = scenario_outline
        self.statement = scenario_outline

    def examples(self, examples):
        self.finish_last_statement()
        self.printer.print_examples(examples)

    def step(self, step):
        self.steps.append(step)

    def match(self, match):
        self._match = match
        self.print_statement()
        if self.use_step_replay:
            # -- PRINT: Mark step as executing before step.run().
            self.print_step("executing", proceed=False)
            self.terminal.flush()

    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 eof(self):
        self.finish_last_statement()
        self.terminal.write('\n')
        self.terminal.flush()

    # -- FORMATTER-SPECIFIC PART:
    def print_statement(self):
        if self.statement:
            self.printer.print_statement_head(self.statement, self.steps)
        # -- FINALLY: Mark statement as printed (after first step, ...).
        self.statement = None

    def print_unprocessed_steps(self):
        assert not self._match
        self._match = None
        while self.steps:
            self.print_step("skipped", proceed=True)
        assert not self.steps

    def print_step(self, status, proceed=True):
        match = self._match
        step = self.steps[0]
        if proceed:
            self.steps.pop(0)
        self.printer.print_step_with_proceed(step, status, match, proceed)
コード例 #4
0
ファイル: pretty2.py プロジェクト: imbrra/logowanie
class Pretty2Formatter(Formatter):
    name = 'pretty2'
    description = 'Standard colourised pretty formatter'
    use_new_impl = True

    def __init__(self, stream_opener, config):
        super(Pretty2Formatter, self).__init__(stream_opener, config)
        # -- ENSURE: Output stream is open.
        self.stream = self.open()
        if self.use_new_impl:
            terminal_writer_class = select_terminal_class(config.color)
            self.terminal = terminal_writer_class(self.stream,
                                                  colored=config.color)
            terminal_width = get_terminal_size()[0]
            use_replay = self.terminal.has_feature("cursor_up")
        else:
            self.terminal = StyledTerminalWriter(self.stream,
                                                 colored=config.color)
            terminal_width = self.terminal.width
            use_replay = self.terminal.styled
        self.printer = ModelPrinter(self.terminal, config, terminal_width)
        self.use_step_replay = use_replay

        # -- UNUSED: self.tag_statement = None
        self.current_feature = None
        self.current_scenario = None
        self.statement = None
        self.steps = []
        self._uri = None
        self._match = None

    def reset_statement(self):
        self.statement = None
        self.steps = []
        self._match = None
        self.printer.reset_statement()

    def reset(self):
        # -- UNUSED: self.tag_statement = None
        self.current_feature = None
        self.current_scenario = None
        self._uri = None
        self.reset_statement()

    def finish_last_statement(self):
        self.print_statement()
        self.print_unprocessed_steps()
        self.stream.flush()
        self.reset_statement()

    # -- FORMATTER API:
    def uri(self, uri):
        self.reset()
        self._uri = uri

    def feature(self, feature):
        self.current_feature = feature
        self.printer.print_feature_head(feature)

    def background(self, background):
        self.finish_last_statement()
        self.current_scenario = background
        self.statement = background

    def scenario(self, scenario):
        self.finish_last_statement()
        self.current_scenario = scenario
        self.statement = scenario

    def scenario_outline(self, scenario_outline):
        self.finish_last_statement()
        self.current_scenario = scenario_outline
        self.statement = scenario_outline

    def examples(self, examples):
        self.finish_last_statement()
        self.printer.print_examples(examples)

    def step(self, step):
        self.steps.append(step)

    def match(self, match):
        self._match = match
        self.print_statement()
        if self.use_step_replay:
            # -- PRINT: Mark step as executing before step.run().
            self.print_step("executing", proceed=False)
            self.terminal.flush()

    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 eof(self):
        self.finish_last_statement()
        self.terminal.write('\n')
        self.terminal.flush()

    # -- FORMATTER-SPECIFIC PART:
    def print_statement(self):
        if self.statement:
            self.printer.print_statement_head(self.statement, self.steps)
        # -- FINALLY: Mark statement as printed (after first step, ...).
        self.statement = None

    def print_unprocessed_steps(self):
        assert not self._match
        self._match = None
        while self.steps:
            self.print_step("skipped", proceed=True)
        assert not self.steps

    def print_step(self, status, proceed=True):
        match = self._match
        step = self.steps[0]
        if proceed:
            self.steps.pop(0)
        self.printer.print_step_with_proceed(step, status, match, proceed)