Merge lp:~jelmer/brz/coverage-coverage into lp:brz

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: no longer in the source branch.
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~jelmer/brz/coverage-coverage
Merge into: lp:brz
Diff against target: 157 lines (+26/-23)
6 files modified
.bzrignore (+1/-0)
.coveragerc (+1/-0)
.travis.yml (+2/-3)
breezy/commands.py (+15/-19)
breezy/plugin.py (+1/-1)
breezy/tests/__init__.py (+6/-0)
To merge this branch: bzr merge lp:~jelmer/brz/coverage-coverage
Reviewer Review Type Date Requested Status
Martin Packman Approve
Jelmer Vernooij Approve
Review via email: mp+345192@code.launchpad.net

Commit message

Switch --coverage to use coverage module.

Description of the change

This should make it easier to integrate with e.g. codecov.io; it also allows more easily generating HTML coverage output (rather than the text output that tracer generates).

To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) :
review: Approve
Revision history for this message
Martin Packman (gz) wrote :

Looks good to me. The envvar setting is a little ugly but interface is otherwise close enough and this is the module I use on other projects.

review: Approve
Revision history for this message
The Breezy Bot (the-breezy-bot) wrote :

Running landing tests failed
https://ci.breezy-vcs.org/job/brz-dev/144/

Revision history for this message
The Breezy Bot (the-breezy-bot) wrote :

Running landing tests failed
https://ci.breezy-vcs.org/job/brz-dev/145/

Revision history for this message
The Breezy Bot (the-breezy-bot) wrote :

Running landing tests failed
https://ci.breezy-vcs.org/job/brz-dev/146/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.bzrignore'
2--- .bzrignore 2018-02-18 17:56:45 +0000
3+++ .bzrignore 2018-05-09 23:48:22 +0000
4@@ -74,3 +74,4 @@
5 python3.passing.old
6 python3.passing.new
7 selftest.log
8+.coverage
9
10=== modified file '.coveragerc'
11--- .coveragerc 2018-05-07 13:30:31 +0000
12+++ .coveragerc 2018-05-09 23:48:22 +0000
13@@ -1,5 +1,6 @@
14 [run]
15 branch = True
16+source = breezy
17
18 [report]
19 exclude_lines =
20
21=== modified file '.travis.yml'
22--- .travis.yml 2018-05-07 13:35:54 +0000
23+++ .travis.yml 2018-05-09 23:48:22 +0000
24@@ -14,12 +14,12 @@
25 matrix:
26 include:
27 - python: 2.7
28- env: SELFTEST_OPTIONS=""
29+ env: SELFTEST_OPTIONS="--coverage"
30 EXTRA_MAKE_ARGS="extensions"
31
32 script:
33 - make docs $EXTRA_MAKE_ARGS
34- - BRZ_PLUGIN_PATH=-site:-user python -Werror -Wignore::ImportWarning -Wignore::PendingDeprecationWarning -Wignore::DeprecationWarning -m coverage run -p --source=breezy ./brz selftest --parallel=fork $SELFTEST_OPTIONS
35+ - BRZ_PLUGIN_PATH=-site:-user python -Werror -Wignore::ImportWarning -Wignore::PendingDeprecationWarning -Wignore::DeprecationWarning ./brz selftest --parallel=fork $SELFTEST_OPTIONS
36
37 install:
38 - sudo apt install python-all-dev python3-all-dev subunit
39@@ -27,5 +27,4 @@
40 - travis_retry pip install -U pip coverage codecov flake8 testtools paramiko fastimport configobj cython testscenarios six docutils python-subunit $TEST_REQUIRE
41
42 after_success:
43- - python -m coverage combine
44 - codecov
45
46=== modified file 'breezy/commands.py'
47--- breezy/commands.py 2017-11-12 13:53:51 +0000
48+++ breezy/commands.py 2018-05-09 23:48:22 +0000
49@@ -957,19 +957,16 @@
50 return argdict
51
52
53-def apply_coveraged(dirname, the_callable, *args, **kwargs):
54- import trace
55- tracer = trace.Trace(count=1, trace=0)
56- sys.settrace(tracer.globaltrace)
57- threading.settrace(tracer.globaltrace)
58-
59+def apply_coveraged(the_callable, *args, **kwargs):
60+ import coverage
61+ cov = coverage.Coverage()
62+ os.environ['COVERAGE_PROCESS_START'] = cov.config_file
63+ cov.start()
64 try:
65 return exception_to_return_code(the_callable, *args, **kwargs)
66 finally:
67- sys.settrace(None)
68- results = tracer.results()
69- results.write_results(show_missing=1, summary=False,
70- coverdir=dirname)
71+ cov.stop()
72+ cov.save()
73
74
75 def apply_profiled(the_callable, *args, **kwargs):
76@@ -1085,7 +1082,7 @@
77 Run under the Python lsprof profiler.
78
79 --coverage
80- Generate line coverage report in the specified directory.
81+ Generate code coverage report
82
83 --concurrency
84 Specify the number of processes that can be run concurrently (selftest).
85@@ -1095,8 +1092,8 @@
86 trace.mutter("brz arguments: %r", argv)
87
88 opt_lsprof = opt_profile = opt_no_plugins = opt_builtin = \
89- opt_no_l10n = opt_no_aliases = False
90- opt_lsprof_file = opt_coverage_dir = None
91+ opt_coverage = opt_no_l10n = opt_no_aliases = False
92+ opt_lsprof_file = None
93
94 # --no-plugins is handled specially at a very early stage. We need
95 # to load plugins before doing other command parsing so that they
96@@ -1127,8 +1124,7 @@
97 os.environ['BRZ_CONCURRENCY'] = argv[i + 1]
98 i += 1
99 elif a == '--coverage':
100- opt_coverage_dir = argv[i + 1]
101- i += 1
102+ opt_coverage = True
103 elif a == '--profile-imports':
104 pass # already handled in startup script Bug #588277
105 elif a.startswith('-D'):
106@@ -1178,17 +1174,17 @@
107 saved_verbosity_level = option._verbosity_level
108 option._verbosity_level = 0
109 if opt_lsprof:
110- if opt_coverage_dir:
111+ if opt_coverage:
112 trace.warning(
113 '--coverage ignored, because --lsprof is in use.')
114 ret = apply_lsprofiled(opt_lsprof_file, run, *run_argv)
115 elif opt_profile:
116- if opt_coverage_dir:
117+ if opt_coverage:
118 trace.warning(
119 '--coverage ignored, because --profile is in use.')
120 ret = apply_profiled(run, *run_argv)
121- elif opt_coverage_dir:
122- ret = apply_coveraged(opt_coverage_dir, run, *run_argv)
123+ elif opt_coverage:
124+ ret = apply_coveraged(run, *run_argv)
125 else:
126 ret = run(*run_argv)
127 return ret or 0
128
129=== modified file 'breezy/plugin.py'
130--- breezy/plugin.py 2017-10-26 11:10:38 +0000
131+++ breezy/plugin.py 2018-05-09 23:48:22 +0000
132@@ -463,7 +463,7 @@
133 if state is None:
134 state = breezy.get_global_state()
135 items = []
136- for name, a_plugin in sorted(state.plugins.items()):
137+ for name, a_plugin in sorted(getattr(state, 'plugins', {}).items()):
138 items.append("%s[%s]" %
139 (name, a_plugin.__version__))
140 return ', '.join(items)
141
142=== modified file 'breezy/tests/__init__.py'
143--- breezy/tests/__init__.py 2018-03-30 14:54:24 +0000
144+++ breezy/tests/__init__.py 2018-05-09 23:48:22 +0000
145@@ -3487,6 +3487,12 @@
146 try:
147 stream = os.fdopen(c2pwrite, 'wb', 1)
148 workaround_zealous_crypto_random()
149+ try:
150+ import coverage
151+ except ImportError:
152+ pass
153+ else:
154+ coverage.process_startup()
155 os.close(c2pread)
156 # Leave stderr and stdout open so we can see test noise
157 # Close stdin so that the child goes away if it decides to

Subscribers

People subscribed via source and target branches