def collect_result_sizes(path, log=logging.debug): """Collect the result sizes information and build result summary. It first tries to merge directory summaries and calculate the result sizes including: client_result_collected_KB: The volume in KB that's transfered from the test device. original_result_total_KB: The volume in KB that's the original size of the result files before being trimmed. result_uploaded_KB: The volume in KB that will be uploaded. result_throttled: Indicating if the result files were throttled. If directory summary merging failed for any reason, fall back to use the total size of the given result directory. @param path: Path of the result directory to get size information. @param log: The logging method, default to logging.debug @return: A ResultSizeInfo namedtuple containing information of test result sizes. """ try: client_collected_bytes, summary = result_utils.merge_summaries(path) result_size_info = result_utils_lib.get_result_size_info( client_collected_bytes, summary) html_file = os.path.join(path, result_view.DEFAULT_RESULT_SUMMARY_NAME) result_view.build(client_collected_bytes, summary, html_file) except: log('Failed to calculate result sizes based on directory summaries for ' 'directory %s. Fall back to record the total size.\nException: %s' % (path, traceback.format_exc())) result_size_info = _get_default_size_info(path) _report_result_size_metrics(result_size_info) return result_size_info
def testMergeSummariesFromNoHistory(self): """Test method merge_summaries can handle results with no existing summary. """ os.remove(self.summary_1) os.remove(self.summary_2) client_collected_bytes, _ = result_utils.merge_summaries(self.test_dir) self.assertEqual(client_collected_bytes, 0)
def testMergeSummaries(self): """Test method merge_summaries.""" collected_bytes, merged_summary, files = result_utils.merge_summaries( self.test_dir) self.assertEqual(EXPECTED_MERGED_SUMMARY, merged_summary) self.assertEqual(collected_bytes, 12 * SIZE) self.assertEqual(len(files), 3)
def testBuildView(self): """Test build method in result_view module.""" client_collected_bytes, summary, _ = result_utils.merge_summaries( self.test_dir) html_file = os.path.join(self.test_dir, result_view.DEFAULT_RESULT_SUMMARY_NAME) result_view.build(client_collected_bytes, summary, html_file) # Make sure html_file is created with content. self.assertGreater(os.stat(html_file).st_size, 1000)
def testMergeSummaries(self): """Test method merge_summaries.""" client_collected_bytes, merged_summary = result_utils.merge_summaries( self.test_dir) self.assertEqual(EXPECTED_MERGED_SUMMARY, merged_summary) self.assertEqual(client_collected_bytes, 9 * SIZE)