def testRetrieveFile_fails(self): self.mock_request.side_effect = ( ContentResponse(json.dumps({'files': {'foo': {'h': 'hash2'}}})) + UrlResponse('http://get/file/contents', 'nice!')) with self.assertRaises(KeyError): isolate_service.RetrieveFile('hash1', 'bar') # File not in isolate.
def testRetrieveFile_succeeds(self): self.mock_request.side_effect = ( ContentResponse(json.dumps({'files': { 'foo': { 'h': 'hash2' } }})) + UrlResponse('http://get/file/contents', 'nice!')) self.assertEqual(isolate_service.RetrieveFile('hash1', 'foo'), 'nice!')
def DownloadJobResultsAsCsv(job_ids, only_differences, output_file): """Download the perf results of a job as a csv file.""" with open(output_file, 'wb') as f: writer = csv.writer(f) writer.writerow(('job_id', 'change', 'isolate') + histograms_df.COLUMNS) num_rows = 0 for job_id in job_ids: job = pinpoint_service.Job(job_id, with_state=True) os_path = _OsPathFromJob(job) results_file = os_path.join(job['arguments']['benchmark'], 'perf_results.json') print 'Fetching results for %s job %s:' % (job['status'].lower(), job_id) for change_id, isolate_hash in job_results.IterTestOutputIsolates( job, only_differences): print '- isolate: %s ...' % isolate_hash histograms = isolate_service.RetrieveFile( isolate_hash, results_file) for row in histograms_df.IterRows(json.loads(histograms)): writer.writerow((job_id, change_id, isolate_hash) + row) num_rows += 1 print 'Wrote data from %d histograms in %s.' % (num_rows, output_file)