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
评论列表
文章目录