1 # Copyright (C) 2010 Google Inc. All rights reserved. 2 # 3 # Redistribution and use in source and binary forms, with or without 4 # modification, are permitted provided that the following conditions are 5 # met: 6 # 7 # * Redistributions of source code must retain the above copyright 8 # notice, this list of conditions and the following disclaimer. 9 # * Redistributions in binary form must reproduce the above 10 # copyright notice, this list of conditions and the following disclaimer 11 # in the documentation and/or other materials provided with the 12 # distribution. 13 # * Neither the name of Google Inc. nor the names of its 14 # contributors may be used to endorse or promote products derived from 15 # this software without specific prior written permission. 16 # 17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 29 import json 30 import unittest 31 32 from webkitpy.layout_tests.layout_package import json_results_generator 33 34 35 class JSONGeneratorTest(unittest.TestCase): 36 def setUp(self): 37 self.builder_name = 'DUMMY_BUILDER_NAME' 38 self.build_name = 'DUMMY_BUILD_NAME' 39 self.build_number = 'DUMMY_BUILDER_NUMBER' 40 41 # For archived results. 42 self._json = None 43 self._num_runs = 0 44 self._tests_set = set([]) 45 self._test_timings = {} 46 self._failed_count_map = {} 47 48 self._PASS_count = 0 49 self._DISABLED_count = 0 50 self._FLAKY_count = 0 51 self._FAILS_count = 0 52 self._fixable_count = 0 53 54 def test_strip_json_wrapper(self): 55 json = "['contents']" 56 self.assertEqual(json_results_generator.strip_json_wrapper(json_results_generator._JSON_PREFIX + json + json_results_generator._JSON_SUFFIX), json) 57 self.assertEqual(json_results_generator.strip_json_wrapper(json), json) 58 59 def _find_test_in_trie(self, path, trie): 60 nodes = path.split("/") 61 sub_trie = trie 62 for node in nodes: 63 self.assertIn(node, sub_trie) 64 sub_trie = sub_trie[node] 65 return sub_trie 66 67 def test_test_timings_trie(self): 68 individual_test_timings = [] 69 individual_test_timings.append(json_results_generator.TestResult('foo/bar/baz.html', elapsed_time=1.2)) 70 individual_test_timings.append(json_results_generator.TestResult('bar.html', elapsed_time=0.0001)) 71 trie = json_results_generator.test_timings_trie(individual_test_timings) 72 73 expected_trie = { 74 'bar.html': 0, 75 'foo': { 76 'bar': { 77 'baz.html': 1200, 78 } 79 } 80 } 81 82 self.assertEqual(json.dumps(trie), json.dumps(expected_trie)) 83