command.py 文件源码

python
阅读 34 收藏 0 点赞 0 评论 0

项目:cli-bdd 作者: chibisov 项目源码 文件源码
def step(self, output, should_not=False, exactly=False):
        child = self.get_scenario_context().command_response['child']
        ensure_command_finished(child)
        output = 'stdout' if output == 'output' else output

        # todo: separate stdout and stderr
        # todo: test replace
        data = child.logfile_read.getvalue().replace('\r\n', '\n')
        data_lines = data.splitlines()
        if data.endswith('\n'):
            data_lines.append('')

        expected = self.get_text().encode('utf-8')  # todo: test encode
        expected_lines = expected.splitlines()
        if expected.endswith('\n'):
            expected_lines.append('')

        bool_matcher = is_not if should_not else is_
        comparison_matcher = equal_to if exactly else contains_string
        try:
            assert_that(
                data,
                bool_matcher(
                    comparison_matcher(expected)
                )
            )
        except AssertionError:
            if comparison_matcher == equal_to and bool_matcher == is_:
                diff = '\n'.join(
                    difflib.context_diff(
                        data_lines,
                        expected_lines
                    )
                )
                raise AssertionError('Comparison error. Diff:\n' + diff)
            else:
                raise
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号