def test_populate_upload_directory(self): # This also tests write_summary() and write_result_directory(). revision = '0bdaaf9c1622ca49eb140381af1ece6d8001c934' r = WPTReport() r._report = { 'results': [{ 'test': '/foo/bar.html', 'status': 'PASS', 'message': None, 'subtests': [] }], 'run_info': { 'revision': revision, 'product': 'firefox', 'browser_version': '59.0', 'os': 'linux' } } r.hashsum = '0123456789' r.populate_upload_directory(output_dir=self.tmp_dir) self.assertTrue( os.path.isfile( os.path.join(self.tmp_dir, revision, 'firefox-59.0-linux-0123456789-summary.json.gz'))) self.assertTrue( os.path.isfile( os.path.join(self.tmp_dir, revision, 'firefox-59.0-linux-0123456789', 'foo', 'bar.html')))
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_product_id_sanitize(self): r = WPTReport() r._report = { 'run_info': { 'product': 'chrome!', 'browser_version': '1.2.3 dev-1', 'os': 'linux', } } r.hashsum = 'afa59408e1797c7091d7e89de5561612f7da440d' self.assertEqual(r.product_id(separator='-', sanitize=True), 'chrome_-1.2.3_dev-1-linux-afa59408e1')
def test_sha_summary_path(self): r = WPTReport() r._report = { 'run_info': { 'revision': '0bdaaf9c1622ca49eb140381af1ece6d8001c934', 'product': 'firefox', 'browser_version': '59.0', 'os': 'linux' } } r.hashsum = 'afa59408e1797c7091d7e89de5561612f7da440d' self.assertEqual( r.sha_summary_path, '0bdaaf9c1622ca49eb140381af1ece6d8001c934/' 'firefox-59.0-linux-afa59408e1-summary.json.gz')
def test_product_id(self): r = WPTReport() r._report = { 'run_info': { 'product': 'firefox', 'browser_version': '59.0', 'os': 'linux', } } r.hashsum = 'afa59408e1797c7091d7e89de5561612f7da440d' self.assertEqual(r.product_id(), 'firefox-59.0-linux-afa59408e1') r._report['run_info']['os_version'] = '4.4' self.assertEqual(r.product_id(separator='_'), 'firefox_59.0_linux_4.4_afa59408e1')
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')