| OLD | NEW |
| 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 from cStringIO import StringIO | 5 from cStringIO import StringIO |
| 6 | 6 |
| 7 try: | 7 import test_env # pylint: disable=W0611 |
| 8 import coverage | |
| 9 coverage_version = coverage.__version__ | |
| 10 except ImportError: | |
| 11 coverage = None | |
| 12 coverage_version = None | |
| 13 | 8 |
| 14 from distutils.version import StrictVersion | 9 import coverage |
| 15 | |
| 16 if (not coverage or | |
| 17 not hasattr(coverage.collector, 'CTracer') or | |
| 18 not coverage.collector.CTracer or | |
| 19 StrictVersion(coverage_version) < StrictVersion('3.7')): | |
| 20 raise ImportError( | |
| 21 'This test requires natively-installed python-coverage (>=3.7). ' | |
| 22 'Current is %s.' % coverage_version) | |
| 23 | |
| 24 | 10 |
| 25 # This is instead of a contextmanager because it causes old pylints to crash :( | 11 # This is instead of a contextmanager because it causes old pylints to crash :( |
| 26 class _Cover(object): | 12 class _Cover(object): |
| 27 def __init__(self, enabled, maybe_kwargs): | 13 def __init__(self, enabled, maybe_kwargs): |
| 28 self.enabled = enabled | 14 self.enabled = enabled |
| 29 self.kwargs = maybe_kwargs or {} | 15 self.kwargs = maybe_kwargs or {} |
| 30 self.c = None | 16 self.c = None |
| 31 | 17 |
| 32 def __enter__(self): | 18 def __enter__(self): |
| 33 if self.enabled: | 19 if self.enabled: |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 print | 66 print |
| 81 print 'FATAL: Test coverage is not at 100%.' | 67 print 'FATAL: Test coverage is not at 100%.' |
| 82 | 68 |
| 83 return not fail | 69 return not fail |
| 84 | 70 |
| 85 def create_subprocess_context(self): | 71 def create_subprocess_context(self): |
| 86 # Can't have this method be the contextmanager because otherwise | 72 # Can't have this method be the contextmanager because otherwise |
| 87 # self (and self.cov) will get pickled to the subprocess, and we don't want | 73 # self (and self.cov) will get pickled to the subprocess, and we don't want |
| 88 # that :( | 74 # that :( |
| 89 return _Cover(self.enabled, self.opts) | 75 return _Cover(self.enabled, self.opts) |
| OLD | NEW |