Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Side by Side Diff: Tools/TestResultServer/model/jsonresults_unittest.py

Issue 14833004: Revert "Change TestResultServer to use python 2.7." (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Tools/TestResultServer/model/jsonresults.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (C) 2010 Google Inc. All rights reserved. 1 # Copyright (C) 2010 Google Inc. All rights reserved.
2 # 2 #
3 # Redistribution and use in source and binary forms, with or without 3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are 4 # modification, are permitted provided that the following conditions are
5 # met: 5 # met:
6 # 6 #
7 # * Redistributions of source code must retain the above copyright 7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer. 8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above 9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer 10 # copyright notice, this list of conditions and the following disclaimer
(...skipping 15 matching lines...) Expand all
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 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. 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 28
29 try: 29 try:
30 import jsonresults 30 import jsonresults
31 from jsonresults import JsonResults 31 from jsonresults import JsonResults
32 except ImportError: 32 except ImportError:
33 print "ERROR: Add the TestResultServer, google_appengine and yaml/lib direct ories to your PYTHONPATH" 33 print "ERROR: Add the TestResultServer, google_appengine and yaml/lib direct ories to your PYTHONPATH"
34 raise 34 raise
35 35
36 import json 36 from django.utils import simplejson
37
37 import unittest 38 import unittest
38 39
39 40
40 JSON_RESULTS_TEMPLATE = ( 41 JSON_RESULTS_TEMPLATE = (
41 '{"Webkit":{' 42 '{"Webkit":{'
42 '"allFixableCount":[[TESTDATA_COUNT]],' 43 '"allFixableCount":[[TESTDATA_COUNT]],'
43 '"buildNumbers":[[TESTDATA_BUILDNUMBERS]],' 44 '"buildNumbers":[[TESTDATA_BUILDNUMBERS]],'
44 '"chromeRevision":[[TESTDATA_CHROMEREVISION]],' 45 '"chromeRevision":[[TESTDATA_CHROMEREVISION]],'
45 '"deferredCounts":[[TESTDATA_COUNTS]],' 46 '"deferredCounts":[[TESTDATA_COUNTS]],'
46 '"fixableCount":[[TESTDATA_COUNT]],' 47 '"fixableCount":[[TESTDATA_COUNT]],'
(...skipping 26 matching lines...) Expand all
73 74
74 JSON_RESULTS_TEST_LIST_TEMPLATE = ( 75 JSON_RESULTS_TEST_LIST_TEMPLATE = (
75 '{"Webkit":{"tests":{[TESTDATA_TESTS]}}}') 76 '{"Webkit":{"tests":{[TESTDATA_TESTS]}}}')
76 77
77 78
78 class JsonResultsTest(unittest.TestCase): 79 class JsonResultsTest(unittest.TestCase):
79 def setUp(self): 80 def setUp(self):
80 self._builder = "Webkit" 81 self._builder = "Webkit"
81 82
82 def test_strip_prefix_suffix(self): 83 def test_strip_prefix_suffix(self):
83 json_string = "['contents']" 84 json = "['contents']"
84 self.assertEqual(JsonResults._strip_prefix_suffix("ADD_RESULTS(" + json_ string + ");"), json_string) 85 self.assertEqual(JsonResults._strip_prefix_suffix("ADD_RESULTS(" + json + ");"), json)
85 self.assertEqual(JsonResults._strip_prefix_suffix(json_string), json_str ing) 86 self.assertEqual(JsonResults._strip_prefix_suffix(json), json)
86 87
87 def _make_test_json(self, test_data): 88 def _make_test_json(self, test_data):
88 if not test_data: 89 if not test_data:
89 return "" 90 return ""
90 91
91 builds = test_data["builds"] 92 builds = test_data["builds"]
92 tests = test_data["tests"] 93 tests = test_data["tests"]
93 if not builds or not tests: 94 if not builds or not tests:
94 return "" 95 return ""
95 96
96 json_string = JSON_RESULTS_TEMPLATE 97 json = JSON_RESULTS_TEMPLATE
97 98
98 counts = [] 99 counts = []
99 build_numbers = [] 100 build_numbers = []
100 webkit_revision = [] 101 webkit_revision = []
101 chrome_revision = [] 102 chrome_revision = []
102 times = [] 103 times = []
103 for build in builds: 104 for build in builds:
104 counts.append(JSON_RESULTS_COUNTS_TEMPLATE.replace("[TESTDATA]", bui ld)) 105 counts.append(JSON_RESULTS_COUNTS_TEMPLATE.replace("[TESTDATA]", bui ld))
105 build_numbers.append("1000%s" % build) 106 build_numbers.append("1000%s" % build)
106 webkit_revision.append("2000%s" % build) 107 webkit_revision.append("2000%s" % build)
107 chrome_revision.append("3000%s" % build) 108 chrome_revision.append("3000%s" % build)
108 times.append("100000%s000" % build) 109 times.append("100000%s000" % build)
109 110
110 json_string = json_string.replace("[TESTDATA_COUNTS]", ",".join(counts)) 111 json = json.replace("[TESTDATA_COUNTS]", ",".join(counts))
111 json_string = json_string.replace("[TESTDATA_COUNT]", ",".join(builds)) 112 json = json.replace("[TESTDATA_COUNT]", ",".join(builds))
112 json_string = json_string.replace("[TESTDATA_BUILDNUMBERS]", ",".join(bu ild_numbers)) 113 json = json.replace("[TESTDATA_BUILDNUMBERS]", ",".join(build_numbers))
113 json_string = json_string.replace("[TESTDATA_WEBKITREVISION]", ",".join( webkit_revision)) 114 json = json.replace("[TESTDATA_WEBKITREVISION]", ",".join(webkit_revisio n))
114 json_string = json_string.replace("[TESTDATA_CHROMEREVISION]", ",".join( chrome_revision)) 115 json = json.replace("[TESTDATA_CHROMEREVISION]", ",".join(chrome_revisio n))
115 json_string = json_string.replace("[TESTDATA_TIMES]", ",".join(times)) 116 json = json.replace("[TESTDATA_TIMES]", ",".join(times))
116 117
117 version = str(test_data["version"]) if "version" in test_data else "4" 118 version = str(test_data["version"]) if "version" in test_data else "4"
118 json_string = json_string.replace("[VERSION]", version) 119 json = json.replace("[VERSION]", version)
119 json_string = json_string.replace("{[TESTDATA_TESTS]}", json.dumps(tests , separators=(',', ':'), sort_keys=True)) 120 json = json.replace("{[TESTDATA_TESTS]}", simplejson.dumps(tests, separa tors=(',', ':'), sort_keys=True))
120 return json_string 121 return json
121 122
122 def _test_merge(self, aggregated_data, incremental_data, expected_data, max_ builds=jsonresults.JSON_RESULTS_MAX_BUILDS): 123 def _test_merge(self, aggregated_data, incremental_data, expected_data, max_ builds=jsonresults.JSON_RESULTS_MAX_BUILDS):
123 aggregated_results = self._make_test_json(aggregated_data) 124 aggregated_results = self._make_test_json(aggregated_data)
124 incremental_results = self._make_test_json(incremental_data) 125 incremental_results = self._make_test_json(incremental_data)
125 merged_results = JsonResults.merge(self._builder, aggregated_results, in cremental_results, max_builds, sort_keys=True) 126 merged_results = JsonResults.merge(self._builder, aggregated_results, in cremental_results, max_builds, sort_keys=True)
126 127
127 if expected_data: 128 if expected_data:
128 expected_results = self._make_test_json(expected_data) 129 expected_results = self._make_test_json(expected_data)
129 self.assertEqual(merged_results, expected_results) 130 self.assertEqual(merged_results, expected_results)
130 else: 131 else:
131 self.assertFalse(merged_results) 132 self.assertFalse(merged_results)
132 133
133 def _test_get_test_list(self, input_data, expected_data): 134 def _test_get_test_list(self, input_data, expected_data):
134 input_results = self._make_test_json(input_data) 135 input_results = self._make_test_json(input_data)
135 expected_results = JSON_RESULTS_TEST_LIST_TEMPLATE.replace("{[TESTDATA_T ESTS]}", json.dumps(expected_data, separators=(',', ':'))) 136 expected_results = JSON_RESULTS_TEST_LIST_TEMPLATE.replace("{[TESTDATA_T ESTS]}", simplejson.dumps(expected_data, separators=(',', ':')))
136 actual_results = JsonResults.get_test_list(self._builder, input_results) 137 actual_results = JsonResults.get_test_list(self._builder, input_results)
137 self.assertEqual(actual_results, expected_results) 138 self.assertEqual(actual_results, expected_results)
138 139
139 def test_merge_null_incremental_results(self): 140 def test_merge_null_incremental_results(self):
140 # Empty incremental results json. 141 # Empty incremental results json.
141 # Nothing to merge. 142 # Nothing to merge.
142 self._test_merge( 143 self._test_merge(
143 # Aggregated results 144 # Aggregated results
144 {"builds": ["2", "1"], 145 {"builds": ["2", "1"],
145 "tests": {"001.html": { 146 "tests": {"001.html": {
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 "results": [[101,"I"]], 689 "results": [[101,"I"]],
689 "times": [[101,0]]}, 690 "times": [[101,0]]},
690 "foo.bar3": { 691 "foo.bar3": {
691 "results": [[1,"F"]], 692 "results": [[1,"F"]],
692 "times": [[1,0]]}, 693 "times": [[1,0]]},
693 }, 694 },
694 "version": 4}) 695 "version": 4})
695 696
696 if __name__ == '__main__': 697 if __name__ == '__main__':
697 unittest.main() 698 unittest.main()
OLDNEW
« no previous file with comments | « Tools/TestResultServer/model/jsonresults.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698