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

Side by Side Diff: go/test.py

Issue 1133353002: cipd: Skip test on Windows for now. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Created 5 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
« no previous file with comments | « go/src/infra/tools/cipd/local/local.infra_testing ('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 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2014 The Chromium Authors. All rights reserved. 2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Runs Go unit tests verifying code coverage. 6 """Runs Go unit tests verifying code coverage.
7 7
8 Expects Go toolset to be in PATH, GOPATH and GOROOT correctly set. Use ./env.py 8 Expects Go toolset to be in PATH, GOPATH and GOROOT correctly set. Use ./env.py
9 to set them up. 9 to set them up.
10 10
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 82
83 83
84 _package_info_cache = {} 84 _package_info_cache = {}
85 85
86 def get_package_info(package): 86 def get_package_info(package):
87 """Returns contents of <package>/<name>.infra_testing file or {} if missing. 87 """Returns contents of <package>/<name>.infra_testing file or {} if missing.
88 88
89 *.infra_testing contains a JSON dict with the following keys: 89 *.infra_testing contains a JSON dict with the following keys:
90 { 90 {
91 // Do not run tests in this package at all. Default 'false'. 91 // Do not run tests in this package at all. Default 'false'.
92 "skip_testing": boolean, 92 "skip_testing": boolean or a list of platforms to skip tests on,
iannucci 2015/05/13 08:18:19 why not always a list of platforms?
Vadim Sh. 2015/05/13 22:57:24 Okay...
93 // Minimum allowed code coverage percentage, see below. Default '100'. 93 // Minimum allowed code coverage percentage, see below. Default '100'.
94 "expected_coverage_min": number, 94 "expected_coverage_min": number,
95 // Maximum allowed code coverage percentage, see below. Default '100'. 95 // Maximum allowed code coverage percentage, see below. Default '100'.
96 "expected_coverage_max": number 96 "expected_coverage_max": number
97 } 97 }
98 98
99 expected_coverage_min and expected_coverage_max set a boundary on what the 99 expected_coverage_min and expected_coverage_max set a boundary on what the
100 code coverage percentage of the package is expected to be. test.py will fail 100 code coverage percentage of the package is expected to be. test.py will fail
101 if code coverage is less than 'expected_coverage_min' (meaning the package 101 if code coverage is less than 'expected_coverage_min' (meaning the package
102 code has degraded), or larger than 'expected_coverage_max' (meaning the 102 code has degraded), or larger than 'expected_coverage_max' (meaning the
(...skipping 30 matching lines...) Expand all
133 print >> sys.stderr, 'Not a valid JSON file: %s' % info_file 133 print >> sys.stderr, 'Not a valid JSON file: %s' % info_file
134 return {} 134 return {}
135 135
136 if package not in _package_info_cache: 136 if package not in _package_info_cache:
137 _package_info_cache[package] = do_read() 137 _package_info_cache[package] = do_read()
138 return _package_info_cache[package] 138 return _package_info_cache[package]
139 139
140 140
141 def should_skip(package): 141 def should_skip(package):
142 """True to skip package tests, reads 'skip_testing' from *.infra_testing.""" 142 """True to skip package tests, reads 'skip_testing' from *.infra_testing."""
143 return get_package_info(package).get('skip_testing', False) 143 skip = get_package_info(package).get('skip_testing', False)
144 if isinstance(skip, list):
145 return sys.platform in skip
iannucci 2015/05/13 08:18:19 return sys.platform.startswith(skip) maybe? Then
Vadim Sh. 2015/05/13 22:57:24 [""] is sort of confusing... Made it GOOS ("darw
146 return bool(skip)
147
144 148
145 def get_build_tags(package): 149 def get_build_tags(package):
146 """True to skip package tests, reads 'skip_testing' from *.infra_testing.""" 150 """Build tags to use when building a package, read from *.infra_testing."""
147 tags = get_package_info(package).get('build_tags', ()) 151 tags = get_package_info(package).get('build_tags', ())
148 if tags: 152 if tags:
149 return '-tags='+(','.join(tags)) 153 return '-tags='+(','.join(tags))
150 return None 154 return None
151 155
156
152 def get_expected_coverage(package): 157 def get_expected_coverage(package):
153 """Returns allowed code coverage percentage as a pair (min, max).""" 158 """Returns allowed code coverage percentage as a pair (min, max)."""
154 info = get_package_info(package) 159 info = get_package_info(package)
155 min_cover = info.get('expected_coverage_min', 100.0) 160 min_cover = info.get('expected_coverage_min', 100.0)
156 max_cover = info.get('expected_coverage_max', 100.0) 161 max_cover = info.get('expected_coverage_max', 100.0)
157 if max_cover < min_cover: 162 if max_cover < min_cover:
158 max_cover = min_cover 163 max_cover = min_cover
159 return (min_cover, max_cover) 164 return (min_cover, max_cover)
160 165
161 166
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 print 'Use ./env.py python test.py' 255 print 'Use ./env.py python test.py'
251 return 1 256 return 1
252 257
253 # Coverage dir is always overwritten with new coverage reports. 258 # Coverage dir is always overwritten with new coverage reports.
254 if os.path.exists(coverage_dir): 259 if os.path.exists(coverage_dir):
255 shutil.rmtree(coverage_dir) 260 shutil.rmtree(coverage_dir)
256 makedirs(coverage_dir) 261 makedirs(coverage_dir)
257 262
258 # Code coverage report requires tests to be run against a single package, so 263 # Code coverage report requires tests to be run against a single package, so
259 # discover all individual packages. 264 # discover all individual packages.
260 packages = [p for p in list_packages(package_root) if not should_skip(p)] 265 skipped = []
266 packages = []
267 for p in list_packages(package_root):
268 if should_skip(p):
269 skipped.append(p)
270 else:
271 packages.append(p)
272 if skipped:
273 print 'Skipping %d packages' % len(skipped)
261 if not packages: 274 if not packages:
262 print 'No tests to run' 275 print 'No tests to run'
263 return 0 276 return 0
264 277
265 failed = [] 278 failed = []
266 bad_cover = [] 279 bad_cover = []
267 tpool = ThreadPool(len(packages)) 280 tpool = ThreadPool(len(packages))
268 def run(pkg): 281 def run(pkg):
269 coverage_file = os.path.join(coverage_dir, pkg.replace('/', os.sep)) 282 coverage_file = os.path.join(coverage_dir, pkg.replace('/', os.sep))
270 return run_package_tests(pkg, coverage_file) 283 return run_package_tests(pkg, coverage_file)
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 elif len(args) == 1: 341 elif len(args) == 1:
329 package_root = args[0] 342 package_root = args[0]
330 else: 343 else:
331 print >> sys.stderr, sys.modules['__main__'].__doc__.strip() 344 print >> sys.stderr, sys.modules['__main__'].__doc__.strip()
332 return 1 345 return 1
333 return run_tests(package_root, os.path.join(INFRA_GO_DIR, 'coverage')) 346 return run_tests(package_root, os.path.join(INFRA_GO_DIR, 'coverage'))
334 347
335 348
336 if __name__ == '__main__': 349 if __name__ == '__main__':
337 sys.exit(main(sys.argv[1:])) 350 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « go/src/infra/tools/cipd/local/local.infra_testing ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698