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

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

Issue 14562007: 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
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 from django.utils import simplejson 36 import json
37
38 import unittest 37 import unittest
39 38
40 39
41 JSON_RESULTS_TEMPLATE = ( 40 JSON_RESULTS_TEMPLATE = (
42 '{"Webkit":{' 41 '{"Webkit":{'
43 '"allFixableCount":[[TESTDATA_COUNT]],' 42 '"allFixableCount":[[TESTDATA_COUNT]],'
44 '"buildNumbers":[[TESTDATA_BUILDNUMBERS]],' 43 '"buildNumbers":[[TESTDATA_BUILDNUMBERS]],'
45 '"chromeRevision":[[TESTDATA_CHROMEREVISION]],' 44 '"chromeRevision":[[TESTDATA_CHROMEREVISION]],'
46 '"deferredCounts":[[TESTDATA_COUNTS]],' 45 '"deferredCounts":[[TESTDATA_COUNTS]],'
47 '"fixableCount":[[TESTDATA_COUNT]],' 46 '"fixableCount":[[TESTDATA_COUNT]],'
(...skipping 26 matching lines...) Expand all
74 73
75 JSON_RESULTS_TEST_LIST_TEMPLATE = ( 74 JSON_RESULTS_TEST_LIST_TEMPLATE = (
76 '{"Webkit":{"tests":{[TESTDATA_TESTS]}}}') 75 '{"Webkit":{"tests":{[TESTDATA_TESTS]}}}')
77 76
78 77
79 class JsonResultsTest(unittest.TestCase): 78 class JsonResultsTest(unittest.TestCase):
80 def setUp(self): 79 def setUp(self):
81 self._builder = "Webkit" 80 self._builder = "Webkit"
82 81
83 def test_strip_prefix_suffix(self): 82 def test_strip_prefix_suffix(self):
84 json = "['contents']" 83 json_string = "['contents']"
85 self.assertEqual(JsonResults._strip_prefix_suffix("ADD_RESULTS(" + json + ");"), json) 84 self.assertEqual(JsonResults._strip_prefix_suffix("ADD_RESULTS(" + json_ string + ");"), json_string)
86 self.assertEqual(JsonResults._strip_prefix_suffix(json), json) 85 self.assertEqual(JsonResults._strip_prefix_suffix(json_string), json_str ing)
87 86
88 def _make_test_json(self, test_data): 87 def _make_test_json(self, test_data):
89 if not test_data: 88 if not test_data:
90 return "" 89 return ""
91 90
92 builds = test_data["builds"] 91 builds = test_data["builds"]
93 tests = test_data["tests"] 92 tests = test_data["tests"]
94 if not builds or not tests: 93 if not builds or not tests:
95 return "" 94 return ""
96 95
97 json = JSON_RESULTS_TEMPLATE 96 json_string = JSON_RESULTS_TEMPLATE
98 97
99 counts = [] 98 counts = []
100 build_numbers = [] 99 build_numbers = []
101 webkit_revision = [] 100 webkit_revision = []
102 chrome_revision = [] 101 chrome_revision = []
103 times = [] 102 times = []
104 for build in builds: 103 for build in builds:
105 counts.append(JSON_RESULTS_COUNTS_TEMPLATE.replace("[TESTDATA]", bui ld)) 104 counts.append(JSON_RESULTS_COUNTS_TEMPLATE.replace("[TESTDATA]", bui ld))
106 build_numbers.append("1000%s" % build) 105 build_numbers.append("1000%s" % build)
107 webkit_revision.append("2000%s" % build) 106 webkit_revision.append("2000%s" % build)
108 chrome_revision.append("3000%s" % build) 107 chrome_revision.append("3000%s" % build)
109 times.append("100000%s000" % build) 108 times.append("100000%s000" % build)
110 109
111 json = json.replace("[TESTDATA_COUNTS]", ",".join(counts)) 110 json_string = json_string.replace("[TESTDATA_COUNTS]", ",".join(counts))
112 json = json.replace("[TESTDATA_COUNT]", ",".join(builds)) 111 json_string = json_string.replace("[TESTDATA_COUNT]", ",".join(builds))
113 json = json.replace("[TESTDATA_BUILDNUMBERS]", ",".join(build_numbers)) 112 json_string = json_string.replace("[TESTDATA_BUILDNUMBERS]", ",".join(bu ild_numbers))
114 json = json.replace("[TESTDATA_WEBKITREVISION]", ",".join(webkit_revisio n)) 113 json_string = json_string.replace("[TESTDATA_WEBKITREVISION]", ",".join( webkit_revision))
115 json = json.replace("[TESTDATA_CHROMEREVISION]", ",".join(chrome_revisio n)) 114 json_string = json_string.replace("[TESTDATA_CHROMEREVISION]", ",".join( chrome_revision))
116 json = json.replace("[TESTDATA_TIMES]", ",".join(times)) 115 json_string = json_string.replace("[TESTDATA_TIMES]", ",".join(times))
117 116
118 version = str(test_data["version"]) if "version" in test_data else "4" 117 version = str(test_data["version"]) if "version" in test_data else "4"
119 json = json.replace("[VERSION]", version) 118 json_string = json_string.replace("[VERSION]", version)
120 json = json.replace("{[TESTDATA_TESTS]}", simplejson.dumps(tests, separa tors=(',', ':'), sort_keys=True)) 119 json_string = json_string.replace("{[TESTDATA_TESTS]}", json.dumps(tests , separators=(',', ':'), sort_keys=True))
121 return json 120 return json_string
122 121
123 def _test_merge(self, aggregated_data, incremental_data, expected_data, max_ builds=jsonresults.JSON_RESULTS_MAX_BUILDS): 122 def _test_merge(self, aggregated_data, incremental_data, expected_data, max_ builds=jsonresults.JSON_RESULTS_MAX_BUILDS):
124 aggregated_results = self._make_test_json(aggregated_data) 123 aggregated_results = self._make_test_json(aggregated_data)
125 incremental_results = self._make_test_json(incremental_data) 124 incremental_results = self._make_test_json(incremental_data)
126 merged_results = JsonResults.merge(self._builder, aggregated_results, in cremental_results, max_builds, sort_keys=True) 125 merged_results = JsonResults.merge(self._builder, aggregated_results, in cremental_results, max_builds, sort_keys=True)
127 126
128 if expected_data: 127 if expected_data:
129 expected_results = self._make_test_json(expected_data) 128 expected_results = self._make_test_json(expected_data)
130 self.assertEqual(merged_results, expected_results) 129 self.assertEqual(merged_results, expected_results)
131 else: 130 else:
132 self.assertFalse(merged_results) 131 self.assertFalse(merged_results)
133 132
134 def _test_get_test_list(self, input_data, expected_data): 133 def _test_get_test_list(self, input_data, expected_data):
135 input_results = self._make_test_json(input_data) 134 input_results = self._make_test_json(input_data)
136 expected_results = JSON_RESULTS_TEST_LIST_TEMPLATE.replace("{[TESTDATA_T ESTS]}", simplejson.dumps(expected_data, separators=(',', ':'))) 135 expected_results = JSON_RESULTS_TEST_LIST_TEMPLATE.replace("{[TESTDATA_T ESTS]}", json.dumps(expected_data, separators=(',', ':')))
137 actual_results = JsonResults.get_test_list(self._builder, input_results) 136 actual_results = JsonResults.get_test_list(self._builder, input_results)
138 self.assertEqual(actual_results, expected_results) 137 self.assertEqual(actual_results, expected_results)
139 138
140 def test_merge_null_incremental_results(self): 139 def test_merge_null_incremental_results(self):
141 # Empty incremental results json. 140 # Empty incremental results json.
142 # Nothing to merge. 141 # Nothing to merge.
143 self._test_merge( 142 self._test_merge(
144 # Aggregated results 143 # Aggregated results
145 {"builds": ["2", "1"], 144 {"builds": ["2", "1"],
146 "tests": {"001.html": { 145 "tests": {"001.html": {
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 "results": [[101,"I"]], 688 "results": [[101,"I"]],
690 "times": [[101,0]]}, 689 "times": [[101,0]]},
691 "foo.bar3": { 690 "foo.bar3": {
692 "results": [[1,"F"]], 691 "results": [[1,"F"]],
693 "times": [[1,0]]}, 692 "times": [[1,0]]},
694 }, 693 },
695 "version": 4}) 694 "version": 4})
696 695
697 if __name__ == '__main__': 696 if __name__ == '__main__':
698 unittest.main() 697 unittest.main()
OLDNEW
« Tools/TestResultServer/handlers/menu.py ('K') | « Tools/TestResultServer/model/jsonresults.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698