How to use merge_results method in avocado

Best Python code snippet using avocado_python

merge_results_unittest.py

Source:merge_results_unittest.py Github

copy

Full Screen

1# Copyright 2017 The Chromium Authors. All rights reserved.2# Use of this source code is governed by a BSD-style license that can be3# found in the LICENSE file.4# pylint: disable=invalid-name5# pylint complains about the assertXXX methods and the usage of short variables6# m/a/b/d in the tests.7import types8import unittest9import cStringIO as StringIO10from collections import OrderedDict11from blinkpy.common.system.filesystem_mock import FileSystemTestCase, MockFileSystem12from blinkpy.web_tests import merge_results13class JSONMergerTests(unittest.TestCase):14 def test_type_match(self):15 self.assertTrue(16 merge_results.TypeMatch(types.DictType)(dict()))17 self.assertFalse(18 merge_results.TypeMatch(types.ListType, types.TupleType)(dict()))19 self.assertTrue(20 merge_results.TypeMatch(types.ListType, types.TupleType)(list()))21 self.assertTrue(22 merge_results.TypeMatch(types.ListType, types.TupleType)(tuple()))23 def test_merge_listlike(self):24 m = merge_results.JSONMerger()25 tests = [26 # expected, (inputa, inputb)27 ([1, 2], ([1], [2])),28 ([2, 1], ([2], [1])),29 ([1, 2, 3], ([], [1, 2, 3])),30 ([1, 2, 3], ([1], [2, 3])),31 ([1, 2, 3], ([1, 2], [3])),32 ([1, 2, 3], ([1, 2, 3], [])),33 ]34 for expected, (inputa, inputb) in tests:35 self.assertListEqual(36 expected, m.merge_listlike([inputa, inputb]))37 self.assertListEqual(38 expected, m.merge([inputa, inputb]))39 self.assertSequenceEqual(40 expected,41 m.merge_listlike([tuple(inputa), tuple(inputb)]),42 types.TupleType)43 self.assertSequenceEqual(44 expected,45 m.merge([tuple(inputa), tuple(inputb)]),46 types.TupleType)47 def test_merge_simple_dict(self):48 m = merge_results.JSONMerger()49 m.fallback_matcher = m.merge_equal50 tests = [51 # expected, (inputa, inputb)52 ({'a': 1}, ({'a': 1}, {'a': 1})),53 ({'a': 1, 'b': 2}, ({'a': 1, 'b': 2}, {})),54 ({'a': 1, 'b': 2}, ({}, {'a': 1, 'b': 2})),55 ({'a': 1, 'b': 2}, ({'a': 1}, {'b': 2})),56 ({'a': 1, 'b': 2, 'c': 3}, ({'a': 1, 'b': 2, 'c': 3}, {})),57 ({'a': 1, 'b': 2, 'c': 3}, ({'a': 1, 'b': 2}, {'c': 3})),58 ({'a': 1, 'b': 2, 'c': 3}, ({'a': 1}, {'b': 2, 'c': 3})),59 ({'a': 1, 'b': 2, 'c': 3}, ({}, {'a': 1, 'b': 2, 'c': 3})),60 ]61 for expected, (inputa, inputb) in tests:62 self.assertDictEqual(expected, m.merge_dictlike([inputa, inputb]))63 with self.assertRaises(merge_results.MergeFailure):64 m.merge_dictlike([{'a': 1}, {'a': 2}])65 def test_merge_compound_dict(self):66 m = merge_results.JSONMerger()67 tests = [68 # expected, (inputa, inputb)69 ({'a': [1, 2]}, ({'a': [1]}, {'a': [2]})),70 ({'a': [1, 'c', 3]}, ({'a': [1]}, {'a': ['c', 3]})),71 ({'a': [1], 'b': [2]}, ({'a': [1]}, {'b': [2]})),72 ({'a': {'b': 1, 'c': 2}}, ({'a': {'b': 1}}, {'a': {'c': 2}})),73 ]74 for expected, (inputa, inputb) in tests:75 self.assertDictEqual(expected, m.merge_dictlike([inputa, inputb]))76 def test_merge(self):77 m = merge_results.JSONMerger()78 m.fallback_matcher = m.merge_equal79 tests = [80 # expected, (inputa, inputb)81 (None, (None, None)),82 ({'a': 1}, ({'a': 1}, None)),83 ({'b': 2}, (None, {'b': 2})),84 ({'a': 1}, ({'a': 1}, {'a': 1})),85 # "Left side" value is None86 ({'a': None, 'b': 2}, ({'a': None, 'b': 2}, {})),87 ({'a': None, 'b': 2}, ({}, {'a': None, 'b': 2})),88 ({'a': None, 'b': 2}, ({'a': None}, {'b': 2})),89 ({'a': None, 'b': 2, 'c': 3}, ({'a': None, 'b': 2, 'c': 3}, {})),90 ({'a': None, 'b': 2, 'c': 3}, ({'a': None, 'b': 2}, {'c': 3})),91 ({'a': None, 'b': 2, 'c': 3}, ({'a': None}, {'b': 2, 'c': 3})),92 ({'a': None, 'b': 2, 'c': 3}, ({}, {'a': None, 'b': 2, 'c': 3})),93 # "Right side" value is None94 ({'a': 1, 'b': None}, ({'a': 1, 'b': None}, {})),95 ({'a': 1, 'b': None}, ({}, {'a': 1, 'b': None})),96 ({'a': 1, 'b': None}, ({'a': 1}, {'b': None})),97 ({'a': 1, 'b': None, 'c': 3}, ({'a': 1, 'b': None, 'c': 3}, {})),98 ({'a': 1, 'b': None, 'c': 3}, ({'a': 1, 'b': None}, {'c': 3})),99 ({'a': 1, 'b': None, 'c': 3}, ({'a': 1}, {'b': None, 'c': 3})),100 ({'a': 1, 'b': None, 'c': 3}, ({}, {'a': 1, 'b': None, 'c': 3})),101 # Both values non-None102 ({'a': 1, 'b': 2}, ({'a': 1, 'b': 2}, {})),103 ({'a': 1, 'b': 2}, ({}, {'a': 1, 'b': 2})),104 ({'a': 1, 'b': 2}, ({'a': 1}, {'b': 2})),105 ({'a': 1, 'b': 2, 'c': 3}, ({'a': 1, 'b': 2, 'c': 3}, {})),106 ({'a': 1, 'b': 2, 'c': 3}, ({'a': 1, 'b': 2}, {'c': 3})),107 ({'a': 1, 'b': 2, 'c': 3}, ({'a': 1}, {'b': 2, 'c': 3})),108 ({'a': 1, 'b': 2, 'c': 3}, ({}, {'a': 1, 'b': 2, 'c': 3})),109 # Complex values110 ({'a': [1, 2]}, ({'a': [1]}, {'a': [2]})),111 ({'a': [1, 'c', 3]}, ({'a': [1]}, {'a': ['c', 3]})),112 ({'a': [1], 'b': [2]}, ({'a': [1]}, {'b': [2]})),113 ({'a': {'b': 1, 'c': 2}}, ({'a': {'b': 1}}, {'a': {'c': 2}})),114 ]115 for expected, (inputa, inputb) in tests:116 self.assertEqual(expected, m.merge([inputa, inputb]))117 with self.assertRaises(merge_results.MergeFailure):118 m.merge([{'a': 1}, {'a': 2}])119 # Ordered values120 a = OrderedDict({'a': 1})121 b = OrderedDict({'b': 2})122 a_before_b = OrderedDict()123 a_before_b['a'] = 1124 a_before_b['b'] = 2125 b_before_a = OrderedDict()126 b_before_a['b'] = 2127 b_before_a['a'] = 1128 r1 = m.merge([a, b])129 self.assertSequenceEqual(a_before_b.items(), r1.items())130 self.assertIsInstance(r1, OrderedDict)131 r2 = m.merge([b, a])132 self.assertSequenceEqual(b_before_a.items(), r2.items())133 self.assertIsInstance(r2, OrderedDict)134 def test_custom_match_on_name(self):135 m = merge_results.JSONMerger()136 m.add_helper(137 merge_results.NameRegexMatch('a'),138 lambda o, name=None: sum(o))139 self.assertDictEqual({'a': 3}, m.merge([{'a': 1}, {'a': 2}]))140 with self.assertRaises(merge_results.MergeFailure):141 m.merge([{'b': 1}, {'b': 2}])142 # Test that helpers that are added later have precedence.143 m.add_helper(144 merge_results.NameRegexMatch('b'),145 lambda o, name=None: sum(o))146 m.add_helper(147 merge_results.NameRegexMatch('b'),148 lambda o, name=None: o[0] - o[1])149 self.assertDictEqual({'b': -1}, m.merge([{'b': 1}, {'b': 2}]))150 def test_custom_match_on_obj_type(self):151 m = merge_results.JSONMerger()152 m.add_helper(153 merge_results.TypeMatch(int),154 lambda o, name=None: sum(o))155 self.assertDictEqual({'a': 3}, m.merge([{'a': 1}, {'a': 2}]))156 self.assertDictEqual({'b': 3}, m.merge([{'b': 1}, {'b': 2}]))157 def test_custom_match_on_obj_value(self):158 m = merge_results.JSONMerger()159 m.add_helper(160 merge_results.ValueMatch(3),161 lambda o, name=None: sum(o))162 self.assertDictEqual({'a': 6}, m.merge([{'a': 3}, {'a': 3}]))163 self.assertDictEqual({'a': 5}, m.merge([{'a': 2}, {'a': 3}]))164 self.assertDictEqual({'a': 7}, m.merge([{'a': 3}, {'a': 4}]))165 with self.assertRaises(merge_results.MergeFailure):166 m.merge([{'a': 1}, {'a': 2}])167class MergeFilesOneTests(FileSystemTestCase):168 def test(self):169 mock_filesystem = MockFileSystem({'/s/file1': '1', '/s/file2': '2'}, dirs=['/output'])170 merger = merge_results.MergeFilesOne(mock_filesystem)171 with self.assertFilesAdded(mock_filesystem, {'/output/file1': '1'}):172 merger('/output/file1', ['/s/file1'])173 with self.assertRaises(AssertionError):174 merger('/output/file1', ['/s/file1', '/s/file2'])175class MergeFilesMatchingContentsTests(FileSystemTestCase):176 def test(self):177 mock_filesystem = MockFileSystem({'/s/file1': '1', '/s/file2': '2', '/s/file3': '1'}, dirs=['/output'])178 merger = merge_results.MergeFilesMatchingContents(mock_filesystem)179 with self.assertFilesAdded(mock_filesystem, {'/output/out1': '1'}):180 merger('/output/out1', ['/s/file1'])181 with self.assertFilesAdded(mock_filesystem, {'/output/out2': '2'}):182 merger('/output/out2', ['/s/file2'])183 with self.assertRaises(merge_results.MergeFailure):184 merger('/output/out3', ['/s/file1', '/s/file2'])185 with self.assertFilesAdded(mock_filesystem, {'/output/out4': '1'}):186 merger('/output/out4', ['/s/file1', '/s/file3'])187class MergeFilesLinesSortedTests(FileSystemTestCase):188 def test(self):189 mock_filesystem = MockFileSystem({'/s/file1': 'A\nC\n', '/s/file2': 'B\n', '/s/file3': 'A\nB\n'}, dirs=['/output'])190 merger = merge_results.MergeFilesLinesSorted(mock_filesystem)191 with self.assertFilesAdded(mock_filesystem, {'/output/out1': 'A\nC\n'}):192 merger('/output/out1', ['/s/file1'])193 with self.assertFilesAdded(mock_filesystem, {'/output/out2': 'B\n'}):194 merger('/output/out2', ['/s/file2'])195 with self.assertFilesAdded(mock_filesystem, {'/output/out3': 'A\nB\nC\n'}):196 merger('/output/out3', ['/s/file1', '/s/file2'])197 with self.assertFilesAdded(mock_filesystem, {'/output/out4': 'A\nB\nB\n'}):198 merger('/output/out4', ['/s/file2', '/s/file3'])199class MergeFilesKeepFilesTests(FileSystemTestCase):200 def test(self):201 mock_filesystem = MockFileSystem({'/s1/file1': 'a', '/s2/file1': 'b', '/s3/file1': 'c'}, dirs=['/output'])202 merger = merge_results.MergeFilesKeepFiles(mock_filesystem)203 with self.assertFilesAdded(mock_filesystem, {'/output/out_0': 'a', '/output/out_1': 'b', '/output/out_2': 'c'}):204 merger('/output/out', ['/s1/file1', '/s2/file1', '/s3/file1'])205class DirMergerTests(FileSystemTestCase):206 def test_success_no_overlapping_files(self):207 mock_filesystem = MockFileSystem({'/shard0/file1': '1', '/shard1/file2': '2'})208 d = merge_results.DirMerger(mock_filesystem)209 with self.assertFilesAdded(mock_filesystem, {'/output/file1': '1', '/output/file2': '2'}):210 d.merge('/output', ['/shard0', '/shard1'])211 def test_success_no_overlapping_files_but_matching_contents(self):212 mock_filesystem = MockFileSystem({'/shard0/file1': '1', '/shard1/file2': '1'})213 d = merge_results.DirMerger(mock_filesystem)214 with self.assertFilesAdded(mock_filesystem, {'/output/file1': '1', '/output/file2': '1'}):215 d.merge('/output', ['/shard0', '/shard1'])216 def test_success_same_file_but_matching_contents(self):217 mock_filesystem = MockFileSystem({'/shard0/file1': '1', '/shard1/file1': '1'})218 d = merge_results.DirMerger(mock_filesystem)219 with self.assertFilesAdded(mock_filesystem, {'/output/file1': '1'}):220 d.merge('/output', ['/shard0', '/shard1'])221 def test_failure_same_file_but_contents_differ(self):222 mock_filesystem = MockFileSystem({'/shard0/file1': '1', '/shard1/file1': '2'})223 d = merge_results.DirMerger(mock_filesystem)224 with self.assertRaises(merge_results.MergeFailure):225 d.merge('/output', ['/shard0', '/shard1'])226class MergeFilesJSONPTests(FileSystemTestCase):227 def assertLoad(self, fd, expected_before, expected_json, expected_after):228 before, json_data, after = merge_results.MergeFilesJSONP.load_jsonp(fd)229 self.assertEqual(expected_before, before)230 self.assertDictEqual(expected_json, json_data)231 self.assertEqual(expected_after, after)232 def assertDump(self, before, json, after, expected_data):233 fd = StringIO.StringIO()234 merge_results.MergeFilesJSONP.dump_jsonp(fd, before, json, after)235 self.assertMultiLineEqual(fd.getvalue(), expected_data)236 def test_load(self):237 fdcls = StringIO.StringIO238 self.assertLoad(fdcls('{"a": 1}'), '', {'a': 1}, '')239 self.assertLoad(fdcls('f({"a": 1});'), 'f(', {'a': 1}, ');')240 self.assertLoad(fdcls('var o = {"a": 1}'), 'var o = ', {'a': 1}, '')241 self.assertLoad(fdcls('while(1); // {"a": 1}'), 'while(1); // ', {'a': 1}, '')242 self.assertLoad(fdcls('/* {"a": 1} */'), '/* ', {'a': 1}, ' */')243 def test_dump(self):244 self.assertDump('', {}, '', '{}')245 self.assertDump('f(', {}, ');', 'f({});')246 self.assertDump('var o = ', {}, '', 'var o = {}')247 self.assertDump('while(1); // ', {}, '', 'while(1); // {}')248 self.assertDump('/* ', {}, ' */', '/* {} */')249 self.assertDump('', {'a': 1}, '', """\250{251 "a": 1252}""")253 self.assertDump('', {'a': [1, 'c', 3], 'b': 2}, '', """\254{255 "a": [256 1,257 "c",258 3259 ],260 "b": 2261}""")262 def assertMergeResults(self, mock_filesystem_contents, inputargs, filesystem_contains, json_data_merger=None):263 mock_filesystem = MockFileSystem(mock_filesystem_contents, dirs=['/output'])264 file_merger = merge_results.MergeFilesJSONP(mock_filesystem, json_data_merger)265 with self.assertFilesAdded(mock_filesystem, filesystem_contains):266 file_merger(*inputargs)267 def assertMergeRaises(self, mock_filesystem_contents, inputargs):268 mock_filesystem = MockFileSystem(mock_filesystem_contents, dirs=['/output'])269 file_merger = merge_results.MergeFilesJSONP(mock_filesystem)270 with self.assertRaises(merge_results.MergeFailure):271 file_merger(*inputargs)272 def test_single_file(self):273 self.assertMergeResults(274 {'/s/filea': '{"a": 1}'},275 ('/output/out1', ['/s/filea']),276 {'/output/out1': """\277{278 "a": 1279}"""})280 self.assertMergeResults(281 {'/s/filef1a': 'f1({"a": 1})'},282 ('/output/outf1', ['/s/filef1a']),283 {'/output/outf1': """\284f1({285 "a": 1286})"""})287 self.assertMergeResults(288 {'/s/fileb1': '{"b": 2}'},289 ('/output/out2', ['/s/fileb1']),290 {'/output/out2': """\291{292 "b": 2293}"""})294 self.assertMergeResults(295 {'/s/filef1b1': 'f1({"b": 2})'},296 ('/output/outf2', ['/s/filef1b1']),297 {'/output/outf2': """\298f1({299 "b": 2300})"""})301 def test_two_files_nonconflicting_values(self):302 self.assertMergeResults(303 {304 '/s/filea': '{"a": 1}',305 '/s/fileb1': '{"b": 2}',306 },307 ('/output/out3', ['/s/filea', '/s/fileb1']),308 {309 '/output/out3': """\310{311 "a": 1,312 "b": 2313}"""})314 self.assertMergeResults(315 {316 '/s/filef1a': 'f1({"a": 1})',317 '/s/filef1b1': 'f1({"b": 2})',318 },319 ('/output/outf3', ['/s/filef1a', '/s/filef1b1']),320 {321 '/output/outf3': """\322f1({323 "a": 1,324 "b": 2325})"""})326 def test_two_files_identical_values_fails_by_default(self):327 self.assertMergeRaises(328 {329 '/s/fileb1': '{"b": 2}',330 '/s/fileb2': '{"b": 2}',331 },332 ('/output/out4', ['/s/fileb1', '/s/fileb2']))333 self.assertMergeRaises(334 {335 '/s/filef1b1': 'f1({"b": 2})',336 '/s/filef1b2': 'f1({"b": 2})',337 },338 ('/output/outf4', ['/s/filef1b1', '/s/filef1b2']))339 def test_two_files_identical_values_works_with_custom_merger(self):340 json_data_merger = merge_results.JSONMerger()341 json_data_merger.fallback_matcher = json_data_merger.merge_equal342 self.assertMergeResults(343 {344 '/s/fileb1': '{"b": 2}',345 '/s/fileb2': '{"b": 2}',346 },347 ('/output/out4', ['/s/fileb1', '/s/fileb2']),348 {349 '/output/out4': """\350{351 "b": 2352}"""},353 json_data_merger=json_data_merger)354 self.assertMergeResults(355 {356 '/s/filef1b1': 'f1({"b": 2})',357 '/s/filef1b2': 'f1({"b": 2})',358 },359 ('/output/outf4', ['/s/filef1b1', '/s/filef1b2']),360 {361 '/output/outf4': """\362f1({363 "b": 2364})"""},365 json_data_merger=json_data_merger)366 def test_two_files_conflicting_values(self):367 self.assertMergeRaises(368 {369 '/s/fileb1': '{"b": 2}',370 '/s/fileb3': '{"b": 3}',371 },372 ('/output/outff1', ['/s/fileb1', '/s/fileb3']))373 self.assertMergeRaises(374 {375 '/s/filef1b1': 'f1({"b": 2})',376 '/s/filef1b3': 'f1({"b": 3})',377 },378 ('/output/outff2', ['/s/filef1b1', '/s/filef1b3']))379 def test_two_files_conflicting_function_names(self):380 self.assertMergeRaises(381 {382 '/s/filef1a': 'f1({"a": 1})',383 '/s/filef2a': 'f2({"a": 1})',384 },385 ('/output/outff3', ['/s/filef1a', '/s/filef2a']))386 def test_two_files_mixed_json_and_jsonp(self):387 self.assertMergeRaises(388 {389 '/s/filea': '{"a": 1}',390 '/s/filef1a': 'f1({"a": 1})',391 },392 ('/output/outff4', ['/s/filea', '/s/filef1a']))393class JSONTestResultsMerger(unittest.TestCase):394 def test_allow_unknown_if_matching(self):395 merger = merge_results.JSONTestResultsMerger(allow_unknown_if_matching=False)396 self.assertEqual(397 {'version': 3.0},398 merger.merge([{'version': 3.0}, {'version': 3.0}]))399 with self.assertRaises(merge_results.MergeFailure):400 merger.merge([{'random': 'hello'}, {'random': 'hello'}])401 merger = merge_results.JSONTestResultsMerger(allow_unknown_if_matching=True)402 self.assertEqual(403 {'random': 'hello'},404 merger.merge([{'random': 'hello'}, {'random': 'hello'}]))405 def test_summable(self):406 merger = merge_results.JSONTestResultsMerger()407 self.assertEqual(408 {'fixable': 5},409 merger.merge([{'fixable': 2}, {'fixable': 3}]))410 self.assertEqual(411 {'num_failures_by_type': {'A': 4, 'B': 3, 'C': 2}},412 merger.merge([413 {'num_failures_by_type': {'A': 3, 'B': 1}},414 {'num_failures_by_type': {'A': 1, 'B': 2, 'C': 2}},415 ]))416 def test_interrupted(self):417 merger = merge_results.JSONTestResultsMerger()418 self.assertEqual(419 {'interrupted': False},420 merger.merge([{'interrupted': False}, {'interrupted': False}]))421 self.assertEqual(422 {'interrupted': True},423 merger.merge([{'interrupted': True}, {'interrupted': False}]))424 self.assertEqual(425 {'interrupted': True},426 merger.merge([{'interrupted': False}, {'interrupted': True}]))427 def test_seconds_since_epoch(self):428 merger = merge_results.JSONTestResultsMerger()429 self.assertEqual(430 {'seconds_since_epoch': 2},431 merger.merge([{'seconds_since_epoch': 3}, {'seconds_since_epoch': 2}]))432 self.assertEqual(433 {'seconds_since_epoch': 2},434 merger.merge([{'seconds_since_epoch': 2}, {'seconds_since_epoch': 3}]))435 self.assertEqual(436 {'seconds_since_epoch': 12},437 merger.merge([{'seconds_since_epoch': 12}, {}]))438class WebTestDirMergerTests(unittest.TestCase):439 # JSON files for shard 1440 # Shard1 has the following tests;441 # testdir1/test1.html442 # testdir1/test2.html443 # testdir2/testdir2.1/test3.html444 shard0_output_json = """\445{446 "build_number": "DUMMY_BUILD_NUMBER",447 "builder_name": "abc",448 "chromium_revision": "123",449 "fixable": 1,450 "interrupted": false,451 "layout_tests_dir": "/b/s/w/irJ1McdS/third_party/blink/web_tests",452 "num_failures_by_type": {453 "AUDIO": 2,454 "CRASH": 3455 },456 "num_flaky": 4,457 "num_passes": 5,458 "num_regressions": 6,459 "path_delimiter": "/",460 "random_order_seed": 4,461 "seconds_since_epoch": 1488435717,462 "skipped": 8,463 "tests": {464 "testdir1": {465 "test1.html": {466 "actual": "PASS",467 "expected": "PASS",468 "has_stderr": false,469 "time": 0.3470 },471 "test2.html": {472 "actual": "PASS",473 "expected": "PASS",474 "has_stderr": false,475 "time": 0.3476 }477 },478 "testdir2": {479 "testdir2.1": {480 "test3.html": {481 "actual": "PASS",482 "expected": "PASS",483 "has_stderr": false,484 "time": 0.3485 }486 }487 }488 },489 "version": 3490}"""491 shard0_archived_results_json = """\492ADD_RESULTS({493 "result_links": [494 "results.html"495 ],496 "tests": {497 "testdir1": {498 "test1.html": {499 "archived_results": [500 "PASS"501 ]502 },503 "test2.html": {504 "archived_results": [505 "PASS"506 ]507 }508 },509 "testdir2": {510 "testdir2.1": {511 "test3.html": {512 "archived_results": [513 "PASS"514 ]515 }516 }517 }518 }519});"""520 shard0_stats_json = """\521{522 "testdir1": {523 "test1.html": {524 "results": [1, 2, 3, 4, 5]525 },526 "test2.html": {527 "results": [6, 7, 8, 9, 10]528 }529 },530 "testdir2": {531 "testdir2.1": {532 "test3.html": {533 "results": [11, 12, 13, 14, 15]534 }535 }536 }537}538"""539 shard0_times_ms_json = """{540 "testdir1": {541 "test1.html": 263,542 "test2.html": 32543 },544 "testdir2": {545 "testdir2.1": {546 "test3.html": 77547 }548 }549}"""550 # Logs for shard 1551 shard0_access_log = """\552127.0.0.1 - - [01/Mar/2017:22:20:10 -0800] "GET /testdir1/test1.html HTTP/1.1" 200 594553127.0.0.1 - - [01/Mar/2017:22:20:10 -0800] "GET /testdir1/test2.html HTTP/1.1" 200 251554"""555 shard0_error_log = """\556[Wed Mar 01 22:20:07.392108 2017] [ssl:warn] [pid 15009] AH01909: RSA certificate configured for 127.0.0.1:443 does NOT include an ID which matches the server name557"""558 # JSON files for shard 2559 # Shard1 has the following tests;560 # testdir2/testdir2.1/test4.html561 # testdir3/testt.html562 shard1_output_json = """\563{564 "build_number": "DUMMY_BUILD_NUMBER",565 "builder_name": "abc",566 "chromium_revision": "123",567 "fixable": 9,568 "interrupted": false,569 "layout_tests_dir": "/b/s/w/sadfa124/third_party/blink/web_tests",570 "num_failures_by_type": {571 "AUDIO": 10,572 "CRASH": 11573 },574 "num_flaky": 12,575 "num_passes": 13,576 "num_regressions": 14,577 "path_delimiter": "/",578 "random_order_seed": 4,579 "seconds_since_epoch": 1488435717,580 "skipped": 15,581 "tests": {582 "testdir2": {583 "testdir2.1": {584 "test4.html": {585 "actual": "FAIL",586 "expected": "PASS",587 "has_stderr": true,588 "time": 0.3589 }590 }591 },592 "testdir3": {593 "test5.html": {594 "actual": "PASS",595 "expected": "PASS",596 "has_stderr": true,597 "time": 0.3598 }599 }600 },601 "version": 3602}"""603 shard1_archived_results_json = """\604ADD_RESULTS({605 "result_links": [606 "results.html"607 ],608 "tests": {609 "testdir2": {610 "testdir2.1": {611 "test4.html": {612 "archived_results": [613 "FAIL"614 ]615 }616 }617 },618 "testdir3": {619 "test5.html": {620 "archived_results": [621 "PASS"622 ]623 }624 }625 }626});"""627 shard1_stats_json = """\628{629 "testdir2": {630 "testdir2.1": {631 "test4.html": {632 "results": [16, 17, 18, 19, 20]633 }634 }635 },636 "testdir3": {637 "test5.html": {638 "results": [21, 22, 23, 24, 25]639 }640 }641}642"""643 shard1_times_ms_json = """{644 "testdir2": {645 "testdir2.1": {646 "test4.html": 99647 }648 },649 "testdir3": {650 "test5.html": 11651 }652}"""653 # Logs for shard 2654 shard1_access_log = """\655127.0.0.1 - - [01/Mar/2017:22:20:10 -0800] "GET /resource.html HTTP/1.1" 200 594656"""657 shard1_error_log = """\658[Wed Mar 01 22:20:07.400802 2017] [ssl:warn] [pid 15010] AH01909: RSA certificate configured for 127.0.0.1:443 does NOT include an ID which matches the server name659"""660 web_test_filesystem = {661 # Files for shard0662 '/shards/0/layout-test-results/access_log.txt': shard0_access_log,663 '/shards/0/layout-test-results/archived_results.json': shard0_archived_results_json,664 '/shards/0/layout-test-results/error_log.txt': shard0_error_log,665 '/shards/0/layout-test-results/failing_results.json': "ADD_RESULTS(" + shard0_output_json + ");",666 '/shards/0/layout-test-results/full_results.json': shard0_output_json,667 '/shards/0/layout-test-results/stats.json': shard0_stats_json,668 '/shards/0/layout-test-results/testdir1/test1-actual.png': '1ap',669 '/shards/0/layout-test-results/testdir1/test1-diff.png': '1dp',670 '/shards/0/layout-test-results/testdir1/test1-diffs.html': '1dh',671 '/shards/0/layout-test-results/testdir1/test1-expected-stderr.txt': '1est',672 '/shards/0/layout-test-results/testdir1/test1-expected.png': '1ep',673 '/shards/0/layout-test-results/testdir1/test2-actual.png': '2ap',674 '/shards/0/layout-test-results/testdir1/test2-diff.png': '2dp',675 '/shards/0/layout-test-results/testdir1/test2-diffs.html': '2dh',676 '/shards/0/layout-test-results/testdir1/test2-expected-stderr.txt': '2est',677 '/shards/0/layout-test-results/testdir1/test2-expected.png': '2ep',678 '/shards/0/layout-test-results/testdir2/testdir2.1/test3-actual.png': '3ap',679 '/shards/0/layout-test-results/testdir2/testdir2.1/test3-diff.png': '3dp',680 '/shards/0/layout-test-results/testdir2/testdir2.1/test3-diffs.html': '3dh',681 '/shards/0/layout-test-results/testdir2/testdir2.1/test3-expected-stderr.txt': '3est',682 '/shards/0/layout-test-results/testdir2/testdir2.1/test3-expected.png': '3ep',683 '/shards/0/layout-test-results/times_ms.json': shard0_times_ms_json,684 '/shards/0/output.json': shard0_output_json,685 # Files for shard1686 '/shards/1/layout-test-results/access_log.txt': shard1_access_log,687 '/shards/1/layout-test-results/archived_results.json': shard1_archived_results_json,688 '/shards/1/layout-test-results/error_log.txt': shard1_error_log,689 '/shards/1/layout-test-results/failing_results.json': "ADD_RESULTS(" + shard1_output_json + ");",690 '/shards/1/layout-test-results/full_results.json': shard1_output_json,691 '/shards/1/layout-test-results/stats.json': shard1_stats_json,692 '/shards/1/layout-test-results/testdir2/testdir2.1/test4-actual.png': '4ap',693 '/shards/1/layout-test-results/testdir2/testdir2.1/test4-diff.png': '4dp',694 '/shards/1/layout-test-results/testdir2/testdir2.1/test4-diffs.html': '4dh',695 '/shards/1/layout-test-results/testdir2/testdir2.1/test4-expected-stderr.txt': '4est',696 '/shards/1/layout-test-results/testdir2/testdir2.1/test4-expected.png': '4ep',697 '/shards/1/layout-test-results/testdir3/test5-actual.png': '5ap',698 '/shards/1/layout-test-results/testdir3/test5-diff.png': '5dp',699 '/shards/1/layout-test-results/testdir3/test5-diffs.html': '5dh',700 '/shards/1/layout-test-results/testdir3/test5-expected-stderr.txt': '5est',701 '/shards/1/layout-test-results/testdir3/test5-expected.png': '5ep',702 '/shards/1/layout-test-results/times_ms.json': shard1_times_ms_json,703 '/shards/1/output.json': shard1_output_json,704 }705 # Combined JSON files706 output_output_json = """\707{708 "build_number": "DUMMY_BUILD_NUMBER",709 "builder_name": "abc",710 "chromium_revision": "123",711 "fixable": 10,712 "interrupted": false,713 "layout_tests_dir": "src",714 "num_failures_by_type": {715 "AUDIO": 12,716 "CRASH": 14717 },718 "num_flaky": 16,719 "num_passes": 18,720 "num_regressions": 20,721 "path_delimiter": "/",722 "random_order_seed": 4,723 "seconds_since_epoch": 1488435717,724 "skipped": 23,725 "tests": {726 "testdir1": {727 "test1.html": {728 "actual": "PASS",729 "expected": "PASS",730 "has_stderr": false,731 "time": 0.3732 },733 "test2.html": {734 "actual": "PASS",735 "expected": "PASS",736 "has_stderr": false,737 "time": 0.3738 }739 },740 "testdir2": {741 "testdir2.1": {742 "test3.html": {743 "actual": "PASS",744 "expected": "PASS",745 "has_stderr": false,746 "time": 0.3747 },748 "test4.html": {749 "actual": "FAIL",750 "expected": "PASS",751 "has_stderr": true,752 "time": 0.3753 }754 }755 },756 "testdir3": {757 "test5.html": {758 "actual": "PASS",759 "expected": "PASS",760 "has_stderr": true,761 "time": 0.3762 }763 }764 },765 "version": 3766}"""767 output_archived_results_json = """\768ADD_RESULTS({769 "result_links": [770 "results.html",771 "results.html"772 ],773 "tests": {774 "testdir1": {775 "test1.html": {776 "archived_results": [777 "PASS"778 ]779 },780 "test2.html": {781 "archived_results": [782 "PASS"783 ]784 }785 },786 "testdir2": {787 "testdir2.1": {788 "test3.html": {789 "archived_results": [790 "PASS"791 ]792 },793 "test4.html": {794 "archived_results": [795 "FAIL"796 ]797 }798 }799 },800 "testdir3": {801 "test5.html": {802 "archived_results": [803 "PASS"804 ]805 }806 }807 }808});"""809 output_stats_json = """\810{811 "testdir1": {812 "test1.html": {813 "results": [814 1,815 2,816 3,817 4,818 5819 ]820 },821 "test2.html": {822 "results": [823 6,824 7,825 8,826 9,827 10828 ]829 }830 },831 "testdir2": {832 "testdir2.1": {833 "test3.html": {834 "results": [835 11,836 12,837 13,838 14,839 15840 ]841 },842 "test4.html": {843 "results": [844 16,845 17,846 18,847 19,848 20849 ]850 }851 }852 },853 "testdir3": {854 "test5.html": {855 "results": [856 21,857 22,858 23,859 24,860 25861 ]862 }863 }864}865"""866 output_times_ms_json = """{867 "testdir1": {868 "test1.html": 263,869 "test2.html": 32870 },871 "testdir2": {872 "testdir2.1": {873 "test3.html": 77,874 "test4.html": 99875 }876 },877 "testdir3": {878 "test5.html": 11879 }880}"""881 # Combined Logs882 output_access_log = """\883127.0.0.1 - - [01/Mar/2017:22:20:10 -0800] "GET /resource.html HTTP/1.1" 200 594884127.0.0.1 - - [01/Mar/2017:22:20:10 -0800] "GET /testdir1/test1.html HTTP/1.1" 200 594885127.0.0.1 - - [01/Mar/2017:22:20:10 -0800] "GET /testdir1/test2.html HTTP/1.1" 200 251886"""887 output_error_log = """\888[Wed Mar 01 22:20:07.392108 2017] [ssl:warn] [pid 15009] AH01909: RSA certificate configured for 127.0.0.1:443 does NOT include an ID which matches the server name889[Wed Mar 01 22:20:07.400802 2017] [ssl:warn] [pid 15010] AH01909: RSA certificate configured for 127.0.0.1:443 does NOT include an ID which matches the server name890"""891 web_test_output_filesystem = {892 '/out/layout-test-results/access_log.txt': output_access_log,893 '/out/layout-test-results/archived_results.json': output_archived_results_json,894 '/out/layout-test-results/error_log.txt': output_error_log,895 '/out/layout-test-results/failing_results.json': "ADD_RESULTS(" + output_output_json + ");",896 '/out/layout-test-results/full_results.json': output_output_json,897 '/out/layout-test-results/stats.json': output_stats_json,898 '/out/layout-test-results/testdir1/test1-actual.png': '1ap',899 '/out/layout-test-results/testdir1/test1-diff.png': '1dp',900 '/out/layout-test-results/testdir1/test1-diffs.html': '1dh',901 '/out/layout-test-results/testdir1/test1-expected-stderr.txt': '1est',902 '/out/layout-test-results/testdir1/test1-expected.png': '1ep',903 '/out/layout-test-results/testdir2/testdir2.1/test3-actual.png': '3ap',904 '/out/layout-test-results/testdir2/testdir2.1/test3-diff.png': '3dp',905 '/out/layout-test-results/testdir2/testdir2.1/test3-diffs.html': '3dh',906 '/out/layout-test-results/testdir2/testdir2.1/test3-expected-stderr.txt': '3est',907 '/out/layout-test-results/testdir2/testdir2.1/test3-expected.png': '3ep',908 '/out/layout-test-results/testdir2/testdir2.1/test4-actual.png': '4ap',909 '/out/layout-test-results/testdir2/testdir2.1/test4-diff.png': '4dp',910 '/out/layout-test-results/testdir2/testdir2.1/test4-diffs.html': '4dh',911 '/out/layout-test-results/testdir2/testdir2.1/test4-expected-stderr.txt': '4est',912 '/out/layout-test-results/testdir2/testdir2.1/test4-expected.png': '4ep',913 '/out/layout-test-results/testdir3/test5-actual.png': '5ap',914 '/out/layout-test-results/testdir3/test5-diff.png': '5dp',915 '/out/layout-test-results/testdir3/test5-diffs.html': '5dh',916 '/out/layout-test-results/testdir3/test5-expected-stderr.txt': '5est',917 '/out/layout-test-results/testdir3/test5-expected.png': '5ep',918 '/out/layout-test-results/times_ms.json': output_times_ms_json,919 '/out/output.json': output_output_json,920 }921 def test(self):922 fs = MockFileSystem(self.web_test_filesystem)923 merger = merge_results.WebTestDirMerger(fs, results_json_value_overrides={'layout_tests_dir': 'src'})924 merger.merge('/out', ['/shards/0', '/shards/1'])925 for fname, contents in self.web_test_output_filesystem.items():926 self.assertIn(fname, fs.files)...

Full Screen

Full Screen

merge_augs.py

Source:merge_augs.py Github

copy

Full Screen

1import numpy as np2from PIL import Image3def merge_aug_segmaps(results,4 num_classes,5 mode='average',6 aug_weights=None,7 return_proba=False):8 if aug_weights:9 assert isinstance(aug_weights, (list, tuple)) and \10 len(aug_weights) == len(results)11 assert mode in ['average', 'vote']12 if mode == 'average':13 if aug_weights is not None:14 merge_results = np.average(15 np.array(results), axis=0, weights=np.array(aug_weights))16 else:17 merge_results = np.mean(results, axis=0)18 if return_proba:19 seg_results = merge_results20 else:21 seg_results = np.argmax(merge_results, axis=1)22 elif mode == 'vote':23 assert not return_proba24 merge_results = np.array(results)25 if merge_results.ndim > 4:26 merge_results = np.argmax(merge_results, axis=2)27 def func(data):28 return np.bincount(data, minlength=num_classes)29 count = np.apply_along_axis(func, 0, merge_results)30 seg_results = np.argmax(count, axis=0)31 else:32 raise NotImplementedError33 return seg_results34def recover_mask(imgs, img_metas):35 # TODO: realize with numpy36 new_imgs = []37 for i in range(imgs.shape[0]):38 temp_img = []39 for j in range(imgs.shape[1]):40 img = Image.fromarray(imgs[i][j])41 if img_metas[i].get('rotate'):42 img = img.rotate(360 - img_metas[i]['rotate'], Image.NEAREST)43 if img_metas[i].get('horizontal_flip'):44 img = img.transpose(Image.FLIP_LEFT_RIGHT)45 if img_metas[i].get('vertical_flip'):46 img = img.transpose(Image.FLIP_TOP_BOTTOM)47 img = img.resize(img_metas[i]['ori_shape'], Image.NEAREST)48 temp_img.append(np.array(img))49 new_imgs.append(np.array(temp_img))...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run avocado automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful