MCPcopy
hub / github.com/cool-RR/PySnooper / assert_output

Function assert_output

tests/utils.py:362–399  ·  view source on GitHub ↗
(output, expected_entries, prefix=None, normalize=False)

Source from the content-addressed store, hash-verified

360
361
362def assert_output(output, expected_entries, prefix=None, normalize=False):
363 lines = tuple(filter(None, output.split('\n')))
364 if expected_entries and not lines:
365 raise OutputFailure("Output is empty")
366
367 if prefix is not None:
368 for line in lines:
369 if not line.startswith(prefix):
370 raise OutputFailure(line)
371
372 if normalize:
373 verify_normalize(lines, prefix)
374
375 # Filter only entries compatible with the current Python
376 filtered_expected_entries = []
377 for expected_entry in expected_entries:
378 if isinstance(expected_entry, _BaseEntry):
379 if expected_entry.is_compatible_with_current_python_version():
380 filtered_expected_entries.append(expected_entry)
381 else:
382 filtered_expected_entries.append(expected_entry)
383
384 expected_entries_count = len(filtered_expected_entries)
385 any_mismatch = False
386 result = ''
387 template = u'\n{line!s:%s} {expected_entry} {arrow}' % max(map(len, lines))
388 for expected_entry, line in zip_longest(filtered_expected_entries, lines, fillvalue=""):
389 mismatch = not (expected_entry and expected_entry.check(line))
390 any_mismatch |= mismatch
391 arrow = '<===' * mismatch
392 result += template.format(**locals())
393
394 if len(lines) != expected_entries_count:
395 result += '\nOutput has {} lines, while we expect {} lines.'.format(
396 len(lines), len(expected_entries))
397
398 if any_mismatch:
399 raise OutputFailure(result)
400
401
402def assert_sample_output(module):

Callers 15

test_string_ioFunction · 0.85
test_relative_timeFunction · 0.85
test_thread_infoFunction · 0.85
test_multi_thread_infoFunction · 0.85
test_callableFunction · 0.85
test_watchFunction · 0.85
test_watch_explodeFunction · 0.85
test_variables_classesFunction · 0.85
test_long_variableFunction · 0.85

Calls 4

OutputFailureClass · 0.85
verify_normalizeFunction · 0.85
checkMethod · 0.45

Tested by 15

test_string_ioFunction · 0.68
test_relative_timeFunction · 0.68
test_thread_infoFunction · 0.68
test_multi_thread_infoFunction · 0.68
test_callableFunction · 0.68
test_watchFunction · 0.68
test_watch_explodeFunction · 0.68
test_variables_classesFunction · 0.68
test_long_variableFunction · 0.68