| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/python | |
| 2 # | |
| 3 # Copyright (c) 2009 The Chromium Authors. All rights reserved. | |
| 4 # Use of this source code is governed by a BSD-style license that can be | |
| 5 # found in the LICENSE file. | |
| 6 | |
| 7 """Verify perf_expectations.json can be loaded using simplejson. | |
| 8 | |
| 9 perf_expectations.json is a JSON-formatted file. This script verifies | |
| 10 that simplejson can load it correctly. It should catch most common | |
| 11 formatting problems. | |
| 12 """ | |
| 13 | |
| 14 import sys | |
| 15 import os | |
| 16 import unittest | |
| 17 | |
| 18 simplejson = None | |
| 19 | |
| 20 def OnTestsLoad(): | |
| 21 old_path = sys.path | |
| 22 script_path = os.path.dirname(sys.argv[0]) | |
| 23 load_path = None | |
| 24 global simplejson | |
| 25 | |
| 26 # This test script should be stored in src/tools/perf_expectations/. That | |
| 27 # directory will most commonly live in 2 locations: | |
| 28 # | |
| 29 # - a regular Chromium checkout, in which case src/third_party | |
| 30 # is where to look for simplejson | |
| 31 # | |
| 32 # - a buildbot checkout, in which case .../pylibs is where | |
| 33 # to look for simplejson | |
| 34 # | |
| 35 # Locate and install the correct path based on what we can find. | |
| 36 # | |
| 37 for path in ('../../../third_party', '../../../../../pylibs'): | |
| 38 path = os.path.join(script_path, path) | |
| 39 if os.path.exists(path) and os.path.isdir(path): | |
| 40 load_path = os.path.abspath(path) | |
| 41 break | |
| 42 | |
| 43 if load_path is None: | |
| 44 msg = "%s expects to live within a Chromium checkout" % sys.argv[0] | |
| 45 raise Exception, "Error locating simplejson load path (%s)" % msg | |
| 46 | |
| 47 # Try importing simplejson once. If this succeeds, we found it and will | |
| 48 # load it again later properly. Fail if we cannot load it. | |
| 49 sys.path.append(load_path) | |
| 50 try: | |
| 51 import simplejson as Simplejson | |
| 52 simplejson = Simplejson | |
| 53 except ImportError, e: | |
| 54 msg = "%s expects to live within a Chromium checkout" % sys.argv[0] | |
| 55 raise Exception, "Error trying to import simplejson from %s (%s)" % \ | |
| 56 (load_path, msg) | |
| 57 finally: | |
| 58 sys.path = old_path | |
| 59 return True | |
| 60 | |
| 61 OnTestsLoad() | |
| 62 | |
| 63 PERF_EXPECTATIONS = os.path.join(os.path.dirname(sys.argv[0]), | |
| 64 '../perf_expectations.json') | |
| 65 | |
| 66 class SimplejsonUnittest(unittest.TestCase): | |
| 67 def testFormat(self): | |
| 68 perf_file = open(PERF_EXPECTATIONS, 'r') | |
| 69 try: | |
| 70 perf_data = simplejson.load(perf_file) | |
| 71 except ValueError, e: | |
| 72 perf_file.seek(0) | |
| 73 print "Error reading %s:\n%s" % (PERF_EXPECTATIONS, | |
| 74 perf_file.read()[:50]+'...') | |
| 75 raise e | |
| 76 print ("Successfully loaded perf_expectations: %d keys found." % | |
| 77 len(perf_data)) | |
| 78 return | |
| 79 | |
| 80 if __name__ == '__main__': | |
| 81 unittest.main() | |
| OLD | NEW |