def test_load_json_multiple_chunks_ignored_conflicting_data(self): tmp_path = os.path.join(self.tmp_dir, 'test.json') r = WPTReport() with open(tmp_path, 'wt') as f: json.dump( { 'results': [{ 'test1': 'foo' }], 'run_info': { 'browser_build_id': '1', 'browser_changeset': 'r1', }, }, f) with open(tmp_path, 'rb') as f: r.load_json(f) with open(tmp_path, 'wt') as f: json.dump( { 'results': [{ 'test2': 'bar' }], 'run_info': { 'browser_build_id': '2', 'browser_changeset': 'r2', }, }, f) with open(tmp_path, 'rb') as f: r.load_json(f) self.assertIsNone(r.run_info['browser_build_id']) self.assertIsNone(r.run_info['browser_changeset'])
def test_load_json_multiple_chunks_conflicting_data(self): tmp_path = os.path.join(self.tmp_dir, 'test.json') r = WPTReport() with open(tmp_path, 'wt') as f: json.dump( { 'results': [{ 'test1': 'foo' }], 'run_info': { 'product': 'firefox' }, }, f) with open(tmp_path, 'rb') as f: r.load_json(f) with open(tmp_path, 'wt') as f: json.dump( { 'results': [{ 'test2': 'bar' }], 'run_info': { 'product': 'chrome' }, }, f) with open(tmp_path, 'rb') as f: with self.assertRaises(ConflictingDataError): r.load_json(f)
def test_load_json_multiple_chunks_conflicting_data(self): tmp_path = os.path.join(self.tmp_dir, 'test.json') r = WPTReport() with open(tmp_path, 'wt') as f: json.dump({ 'results': [{'test1': 'foo'}], 'run_info': { 'revision': '0bdaaf9c1622ca49eb140381af1ece6d8001c934', 'product': 'firefox', 'browser_version': '59', }, }, f) with open(tmp_path, 'rb') as f: r.load_json(f) with open(tmp_path, 'wt') as f: json.dump({ 'results': [{'test2': 'bar'}], 'run_info': { 'revision': '0bdaaf9c1622ca49eb140381af1ece6d8001c934', 'product': 'chrome', 'browser_version': '70', }, }, f) with open(tmp_path, 'rb') as f: with self.assertRaisesRegex(ConflictingDataError, "product, browser_version"): r.load_json(f) # Fields without conflict should be preserved. self.assertEqual(r.run_info['revision'], '0bdaaf9c1622ca49eb140381af1ece6d8001c934') # Conflicting fields should be set to None. self.assertIsNone(r.run_info['product']) self.assertIsNone(r.run_info['browser_version'])
def test_load_json_empty_report(self): tmp_path = os.path.join(self.tmp_dir, 'test.json') with open(tmp_path, 'wt') as f: f.write('{}') r = WPTReport() with open(tmp_path, 'rb') as f: with self.assertRaises(InsufficientDataError): r.load_json(f)
def test_load_json_invalid_json(self): tmp_path = os.path.join(self.tmp_dir, 'test.json') with open(tmp_path, 'wt') as f: f.write('{[') r = WPTReport() with open(tmp_path, 'rb') as f: with self.assertRaises(InvalidJSONError): r.load_json(f)
def test_load_json(self): tmp_path = os.path.join(self.tmp_dir, 'test.json') with open(tmp_path, 'wt') as f: f.write('{"results": [{"test": "foo"}]}') r = WPTReport() with open(tmp_path, 'rb') as f: r.load_json(f) self.assertEqual(len(r.results), 1) # This is the sha1sum of the string written above. self.assertEqual(r.hashsum, 'afa59408e1797c7091d7e89de5561612f7da440d')
def test_load_json_multiple_chunks(self): tmp_path = os.path.join(self.tmp_dir, 'test.json') r = WPTReport() with open(tmp_path, 'wt') as f: f.write('{"results": [{"test1": "foo"}]}\n') with open(tmp_path, 'rb') as f: r.load_json(f) with open(tmp_path, 'wt') as f: f.write('{"results": [{"test2": "bar"}]}\n') with open(tmp_path, 'rb') as f: r.load_json(f) self.assertEqual(len(r.results), 2) # This is the sha1sum of the two strings above concatenated. self.assertEqual(r.hashsum(), '3aa5e332b892025bc6c301e6578ae0d54375351d')
def test_load_json_multiple_chunks_metadata(self): tmp_path = os.path.join(self.tmp_dir, 'test.json') r = WPTReport() # Load a report with no metadata first to test the handling of None. with open(tmp_path, 'wt') as f: f.write('{"results": [{"test": "foo"}]}\n') with open(tmp_path, 'rb') as f: r.load_json(f) with open(tmp_path, 'wt') as f: json.dump( { 'results': [{ 'test1': 'foo' }], 'run_info': { 'product': 'firefox', 'os': 'linux' }, 'time_start': 100, 'time_end': 200, }, f) with open(tmp_path, 'rb') as f: r.load_json(f) with open(tmp_path, 'wt') as f: json.dump( { 'results': [{ 'test2': 'bar' }], 'run_info': { 'product': 'firefox', 'browser_version': '59.0' }, 'time_start': 10, 'time_end': 500, }, f) with open(tmp_path, 'rb') as f: r.load_json(f) self.assertEqual(len(r.results), 3) # run_info should be the union of all run_info. self.assertDictEqual(r.run_info, { 'product': 'firefox', 'browser_version': '59.0', 'os': 'linux' }) # The smallest time_start should be kept. self.assertEqual(r._report['time_start'], 10) # The largest time_end should be kept. self.assertEqual(r._report['time_end'], 500)