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

Side by Side Diff: scripts/slave/unittests/expect_tests/serialize.py

Issue 354913003: Add module discovery and autoloading to expect_tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: add --force_coverage option Created 6 years, 5 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 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import difflib 5 import difflib
6 import json 6 import json
7 import os 7 import os
8 import pprint 8 import pprint
9 9
10 from collections import OrderedDict 10 from collections import OrderedDict
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 """ 72 """
73 @type test: Test() 73 @type test: Test()
74 @returns: The deserialized data (or NonExistant), and a boolean indicating if 74 @returns: The deserialized data (or NonExistant), and a boolean indicating if
75 the current serialized data is in the same format which was 75 the current serialized data is in the same format which was
76 requested by |test|. 76 requested by |test|.
77 @rtype: (dict, bool) 77 @rtype: (dict, bool)
78 """ 78 """
79 for ext in sorted(SUPPORTED_SERIALIZERS, key=lambda s: s != test.ext): 79 for ext in sorted(SUPPORTED_SERIALIZERS, key=lambda s: s != test.ext):
80 path = test.expect_path(ext) 80 path = test.expect_path(ext)
81 if path is None: 81 if path is None:
82 return None, True 82 return NonExistant, True
83 83
84 if ext not in SERIALIZERS and ext == test.ext: 84 if ext not in SERIALIZERS and ext == test.ext:
85 raise Exception('The package to support %s is not installed.' % ext) 85 raise Exception('The package to support %s is not installed.' % ext)
86 if os.path.exists(path): 86 if os.path.exists(path):
87 try: 87 try:
88 with open(path, 'rb') as f: 88 with open(path, 'rb') as f:
89 data = SERIALIZERS[ext][0](f) 89 data = SERIALIZERS[ext][0](f)
90 except ValueError as err: 90 except ValueError as err:
91 raise ValueError('Bad format of %s: %s' % (path, err)) 91 raise ValueError('Bad format of %s: %s' % (path, err))
92 return data, ext == test.ext 92 return data, ext == test.ext
(...skipping 25 matching lines...) Expand all
118 return new 118 return new
119 if old == new: 119 if old == new:
120 return None 120 return None
121 else: 121 else:
122 return list(difflib.context_diff( 122 return list(difflib.context_diff(
123 pprint.pformat(old).splitlines(), 123 pprint.pformat(old).splitlines(),
124 pprint.pformat(new).splitlines(), 124 pprint.pformat(new).splitlines(),
125 fromfile='expected', tofile='current', 125 fromfile='expected', tofile='current',
126 n=4, lineterm='' 126 n=4, lineterm=''
127 )) 127 ))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698