summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES.rst4
-rw-r--r--coverage/config.py6
-rw-r--r--tests/test_config.py35
3 files changed, 44 insertions, 1 deletions
diff --git a/CHANGES.rst b/CHANGES.rst
index 701ac0be..49c3a76e 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -12,9 +12,13 @@ Unreleased
longer counted in statement totals, which could slightly change your total
results.
+- Configuration values which are file paths will now apply tilde-expansion,
+ closing `issue 589`_.
+
- Be more flexible about the command name displayed by help, fixing
`issue 600`_. Thanks, Ben Finney.
+.. _issue 589: https://bitbucket.org/ned/coveragepy/issues/589/allow-expansion-in-coveragerc
.. _issue 600: https://bitbucket.org/ned/coveragepy/issues/600/get-program-name-from-command-line-when
diff --git a/coverage/config.py b/coverage/config.py
index 3fa64495..75da20fd 100644
--- a/coverage/config.py
+++ b/coverage/config.py
@@ -440,4 +440,10 @@ def read_coverage_config(config_file, **kwargs):
# 4) from constructor arguments:
config.from_args(**kwargs)
+ # Once all the config has been collected, there's a little post-processing
+ # to do.
+ config.data_file = os.path.expanduser(config.data_file)
+ config.html_dir = os.path.expanduser(config.html_dir)
+ config.xml_output = os.path.expanduser(config.xml_output)
+
return config_file, config
diff --git a/tests/test_config.py b/tests/test_config.py
index 9a4e8a5e..240a73de 100644
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -4,6 +4,8 @@
"""Test the config file handling for coverage.py"""
+import mock
+
import coverage
from coverage.misc import CoverageException
@@ -150,8 +152,39 @@ class ConfigTest(CoverageTest):
["the_$one", "anotherZZZ", "xZZZy", "xy", "huh${X}what"]
)
+ def test_tilde_in_config(self):
+ # Config entries that are file paths can be tilde-expanded.
+ self.make_file(".coveragerc", """\
+ [run]
+ data_file = ~/data.file
+
+ [html]
+ directory = ~joe/html_dir
+
+ [xml]
+ output = ~/somewhere/xml.out
+
+ [report]
+ # Strings that aren't file paths are not tilde-expanded.
+ exclude_lines =
+ ~/data.file
+ ~joe/html_dir
+ """)
+ def expanduser(s):
+ """Fake tilde expansion"""
+ s = s.replace("~/", "/Users/me/")
+ s = s.replace("~joe/", "/Users/joe/")
+ return s
+
+ with mock.patch.object(coverage.config.os.path, 'expanduser', new=expanduser):
+ cov = coverage.Coverage()
+ self.assertEqual(cov.config.data_file, "/Users/me/data.file")
+ self.assertEqual(cov.config.html_dir, "/Users/joe/html_dir")
+ self.assertEqual(cov.config.xml_output, "/Users/me/somewhere/xml.out")
+ self.assertEqual(cov.config.exclude_list, ["~/data.file", "~joe/html_dir"])
+
def test_tweaks_after_constructor(self):
- # Arguments to the constructor are applied to the configuration.
+ # set_option can be used after construction to affect the config.
cov = coverage.Coverage(timid=True, data_file="fooey.dat")
cov.set_option("run:timid", False)