def test_display_summary_edge_case_scan_time_zero(): from cStringIO import StringIO import sys from scancode.cli import display_summary from scancode.resource import Codebase # Set up test codebase test_codebase = test_env.get_test_loc('resource/client') codebase = Codebase(test_codebase, strip_root=True) codebase.timings['scan'] = 0 scan_names = '' processes = 0 verbose = False errors = [] # Redirect summary output from `stderr` to `result` result = StringIO() sys.stderr = result # Output from `display_summary` will be in `result` display_summary(codebase, scan_names, processes, errors, verbose) # Set `stderr` back sys.stderr = sys.__stderr__ # No exception should be thrown and this assertion should pass assert 'Scan Speed: 0.00 files/sec.' in result.getvalue()
def test_display_summary_edge_case_scan_time_zero_should_not_fail(): from io import StringIO import sys from scancode.cli import display_summary from commoncode.resource import Codebase # Set up test codebase test_codebase = test_env.get_test_loc('summaries/client') codebase = Codebase(test_codebase, strip_root=True) codebase.timings['scan'] = 0 scan_names = 'foo, bar, baz' processes = 23 errors = ['failed to scan ABCD'] try: # Redirect summary output from `stderr` to `result` result = StringIO() sys.stderr = result # Output from `display_summary` will be in `result` display_summary(codebase, scan_names, processes, errors) finally: # Set `stderr` back sys.stderr = sys.__stderr__