Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix coverage-5.x incompatibility. #25

Merged
merged 1 commit into from
Jan 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ script:
# regular unit tests
#-------------------
- python ./run-tests.py runtests/tests/test_regular.py
- python ./run-tests.py runtests/tests/test_regular.py --with-coverage
- python ./run-mpitests.py --single runtests/tests/test_regular.py
- python ./run-mpitests.py runtests/mpi/tests/test_mpiworld.py
- python ./run-mpitests.py runtests/tests/test_regular.py --with-coverage
# expecting a failure for uncollective
- if python ./run-mpitests.py runtests/mpi/tests/test_uncollective.py; then false; fi;

Expand Down
29 changes: 22 additions & 7 deletions runtests/coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import coverage
import shutil
import glob

class Coverage(object):
"""
Expand Down Expand Up @@ -44,13 +45,27 @@ def __init__(self, source, with_coverage=False, html_cov=False,
if not os.path.exists(self.config_file):
self.config_file = None

if self.comm:
if self.comm.rank == 0:
self.tmpdir = tempfile.mkdtemp()
else:
self.tmpdir = None
self.tmpdir = self.comm.bcast(self.tmpdir)
self.tmp_datafile = "coverage.%d" % self.comm.rank
else:
self.tmpdir = tempfile.mkdtemp()
self.tmp_datafile = "coverage"

def __enter__(self):

if not self.with_coverage:
self.cov = None
return
else:
self.cov = coverage.coverage(source=[self.source], config_file=self.config_file)
self.cov = coverage.coverage(source=[self.source],
config_file=self.config_file,
data_file=os.path.join(self.tmpdir, self.tmp_datafile)
)
self.cov.start()

def __exit__(self, type, value, tb):
Expand All @@ -61,7 +76,7 @@ def __exit__(self, type, value, tb):

# with only one rank, just write out the coverage
if self.comm is None or self.comm.size == 1:
self.cov.get_data().write_file(os.path.join(self.root, self.cov.config.data_file))
self.cov.get_data().write()
self.report(self.cov)

# parallel -- combine coverage from all ranks
Expand All @@ -75,17 +90,17 @@ def __exit__(self, type, value, tb):

try:
# write coverage data file
filename = os.path.join(tmpdir, '.coverage.%d' % os.getpid())
self.cov.get_data().write_file(filename)
self.cov.get_data().write()

# now combine from each rank and save
self.comm.barrier()
if self.comm.rank == 0:

# write out combined data
combined_cov = coverage.coverage(config_file=self.config_file, data_file='.coverage')
combined_cov.combine(data_paths=[tmpdir])
combined_cov.get_data().write_file(os.path.join(self.root, self.cov.config.data_file))
combined_cov = coverage.coverage(config_file=self.config_file)
combined_cov.combine(data_paths=glob.glob(os.path.join(
self.tmpdir, '*')))
combined_cov.get_data().write()

# and report
self.report(combined_cov)
Expand Down