| 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 import test_env # pylint: disable=W0611 | 7 import test_env # pylint: disable=W0611 |
| 8 | 8 |
| 9 import coverage | 9 import coverage |
| 10 | 10 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 self.c._warn_no_data = False | 29 self.c._warn_no_data = False |
| 30 self.c.start() | 30 self.c.start() |
| 31 | 31 |
| 32 def __exit__(self, *_): | 32 def __exit__(self, *_): |
| 33 if self.enabled: | 33 if self.enabled: |
| 34 self.c.stop() | 34 self.c.stop() |
| 35 self.c.save() | 35 self.c.save() |
| 36 | 36 |
| 37 | 37 |
| 38 class CoverageContext(object): | 38 class CoverageContext(object): |
| 39 def __init__(self, name, cover_branches, html_report, enabled=True): | 39 def __init__(self, cover_branches, html_report, enabled=True): |
| 40 self.opts = None | 40 self.opts = None |
| 41 self.cov = None | 41 self.cov = None |
| 42 self.enabled = enabled | 42 self.enabled = enabled |
| 43 | 43 |
| 44 self.html_report = html_report | 44 self.html_report = html_report |
| 45 | 45 |
| 46 if enabled: | 46 if enabled: |
| 47 self.opts = { | 47 self.opts = { |
| 48 'data_file': '.%s_coverage' % name, | 48 'data_file': '.expect_tests_coverage', |
| 49 'data_suffix': True, | 49 'data_suffix': True, |
| 50 'branch': cover_branches, | 50 'branch': cover_branches, |
| 51 } | 51 } |
| 52 self.cov = coverage.coverage(**self.opts) | 52 self.cov = coverage.coverage(**self.opts) |
| 53 self.cov.erase() | 53 self.cov.erase() |
| 54 | 54 |
| 55 def cleanup(self): | 55 def cleanup(self): |
| 56 if self.enabled: | 56 if self.enabled: |
| 57 self.cov.combine() | 57 self.cov.combine() |
| 58 | 58 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 78 print | 78 print |
| 79 print 'FATAL: Test coverage is not at 100%.' | 79 print 'FATAL: Test coverage is not at 100%.' |
| 80 | 80 |
| 81 return not fail | 81 return not fail |
| 82 | 82 |
| 83 def create_subprocess_context(self): | 83 def create_subprocess_context(self): |
| 84 # Can't have this method be the contextmanager because otherwise | 84 # Can't have this method be the contextmanager because otherwise |
| 85 # self (and self.cov) will get pickled to the subprocess, and we don't want | 85 # self (and self.cov) will get pickled to the subprocess, and we don't want |
| 86 # that :( | 86 # that :( |
| 87 return _Cover(self.enabled, self.opts) | 87 return _Cover(self.enabled, self.opts) |
| OLD | NEW |