Skip to content

Commit

Permalink
Remove deprecated coveragerc file (#923)
Browse files Browse the repository at this point in the history
* Remove extra covrc file and update case.py to handle the active file

* Fix _getCovRcFile to only make copy for cov.start

* Add test

* Release notes

* Add PROJECT_ROOT variable in context.py

* Address reviewer comment, sort of, with better if statement
  • Loading branch information
opotowsky committed Oct 6, 2022
1 parent 8ea8beb commit b4e477c
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 23 deletions.
3 changes: 3 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ omit =
armi/utils/tests/test_gridGui.py
venv/
source = armi
# change default .coverage file to something that doesn't have a dot
# because our Windows file server can't handle dots. :s
data_file = coverage_results.cov

[coverage:run]
parallel = true
Expand Down
31 changes: 28 additions & 3 deletions armi/cases/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@
import glob
import os
import pathlib
import platform
import pstats
import re
import shutil
import sys
import textwrap
import time
Expand Down Expand Up @@ -380,7 +382,7 @@ def _startCoverage(self):
cov = None
if self.cs["coverage"]:
cov = coverage.Coverage(
config_file=os.path.join(context.RES, "coveragerc"), debug=["dataio"]
config_file=Case._getCoverageRcFile(makeCopy=True), debug=["dataio"]
)
if context.MPI_SIZE > 1:
# interestingly, you cannot set the parallel flag in the constructor
Expand Down Expand Up @@ -415,8 +417,7 @@ def _endCoverage(cov=None):
# combine all the parallel coverage data files into one and make
# the XML and HTML reports for the whole run.
combinedCoverage = coverage.Coverage(
config_file=os.path.join(context.RES, "coveragerc"),
debug=["dataio"],
config_file=Case._getCoverageRcFile(), debug=["dataio"]
)
combinedCoverage.config.parallel = True
# combine does delete the files it merges
Expand All @@ -425,6 +426,30 @@ def _endCoverage(cov=None):
combinedCoverage.html_report()
combinedCoverage.xml_report()

@staticmethod
def _getCoverageRcFile(makeCopy=False):
"""Helper to provide the coverage configuration file according to the OS.
Parameters
----------
makeCopy : bool (optional)
Whether or not to copy the coverage config file to an alternate file path
Returns
-------
covFile : str
path of coveragerc file
"""
covRcDir = os.path.abspath(context.PROJECT_ROOT)
covFile = os.path.join(covRcDir, ".coveragerc")
if platform.system() == "Windows":
covFileWin = os.path.join(covRcDir, "coveragerc")
if makeCopy == True:
# Make a copy of the file without the dot in the name
shutil.copy(covFile, covFileWin)
return covFileWin
return covFile

def _startProfiling(self):
"""Helper to the Case.run(): start the Python profiling,
if the CaseSettings file says to.
Expand Down
13 changes: 10 additions & 3 deletions armi/cases/tests/test_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@
import logging
import os
import platform
import sys
import unittest

import coverage

from armi import cases
from armi import context
from armi import getApp
Expand Down Expand Up @@ -124,6 +121,16 @@ def test_independentVariables(self):
for name, val in vals.items():
self.assertEqual(newCase.independentVariables[name], val)

def test_getCoverageRcFile(self):
case = cases.Case(settings.Settings())
covRcDir = os.path.abspath(context.PROJECT_ROOT)
# Don't actually copy the file, just check the file paths match
covRcFile = case._getCoverageRcFile(makeCopy=False)
if platform.system() == "Windows":
self.assertEqual(covRcFile, os.path.join(covRcDir, "coveragerc"))
else:
self.assertEqual(covRcFile, os.path.join(covRcDir, ".coveragerc"))

def test_startCoverage(self):
with directoryChangers.TemporaryDirectoryChanger():
cs = settings.Settings(ARMI_RUN_PATH)
Expand Down
3 changes: 2 additions & 1 deletion armi/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ def setMode(cls, mode):


ROOT = os.path.abspath(os.path.dirname(__file__))
PROJECT_ROOT = os.path.join(ROOT, "..")
RES = os.path.join(ROOT, "resources")
DOC = os.path.abspath(os.path.join(ROOT, "..", "doc"))
DOC = os.path.abspath(os.path.join(PROJECT_ROOT, "doc"))
USER = getpass.getuser()
START_TIME = time.ctime()

Expand Down
16 changes: 0 additions & 16 deletions armi/resources/coveragerc

This file was deleted.

1 change: 1 addition & 0 deletions doc/release/0.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ What's new in ARMI
------------------

#. TBD
#. Cleanup of stale ``coveragerc`` file (`PR#923 <https://github.com/terrapower/armi/pull/923>`_)
#. Added writer style option to ``SettingsWriter`` and added it as arg to modify CLI (`PR#924 <https://github.com/terrapower/armi/pull/924>`_)

Bug fixes
Expand Down

0 comments on commit b4e477c

Please sign in to comment.