diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2020-05-23 09:17:45 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2020-05-23 13:42:44 -0400 |
commit | 2cee76e06445bfd39148b841b75086932decce27 (patch) | |
tree | 6e3bcaf759a3720cd686e065074cb0ed6f02358f | |
parent | a462ab4aeae93979b50ca0c366840a8a3dc2d8b8 (diff) | |
download | python-coveragepy-git-2cee76e06445bfd39148b841b75086932decce27.tar.gz |
Read the config file contents as bytes, it's just for debugging anyway. #990
-rw-r--r-- | CHANGES.rst | 5 | ||||
-rw-r--r-- | coverage/config.py | 2 | ||||
-rw-r--r-- | tests/test_config.py | 14 |
3 files changed, 16 insertions, 5 deletions
diff --git a/CHANGES.rst b/CHANGES.rst index 49016e9f..89ec8a0f 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -28,6 +28,11 @@ Unreleased ``--precision`` option to control the number of decimal points displayed. Thanks, Teake Nutma. +- TOML configuration files with non-ASCII characters would cause errors on + Windows (`issue 990`_). This is now fixed. + +.. _issue 990: https://github.com/nedbat/coveragepy/issues/990 + .. _changes_51: diff --git a/coverage/config.py b/coverage/config.py index d16c9d6e..6d336d1f 100644 --- a/coverage/config.py +++ b/coverage/config.py @@ -325,7 +325,7 @@ class CoverageConfig(object): if used: self.config_file = os.path.abspath(filename) - with open(filename) as f: + with open(filename, "rb") as f: self._config_contents = f.read() return used diff --git a/tests/test_config.py b/tests/test_config.py index 51d9b9ef..89ecb17c 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -3,6 +3,7 @@ # For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt """Test the config file handling for coverage.py""" + from collections import OrderedDict import mock @@ -62,6 +63,8 @@ class ConfigTest(CoverageTest): # A .coveragerc file will be read into the configuration. self.make_file("pyproject.toml", """\ # This is just a bogus toml file for testing. + [tool.somethingelse] + authors = ["Joe D'Ávila <joe@gmail.com>"] [tool.coverage.run] concurrency = ["a", "b"] timid = true @@ -70,20 +73,23 @@ class ConfigTest(CoverageTest): [tool.coverage.report] precision = 3 fail_under = 90.5 + [tool.coverage.html] + title = "tabblo & «ταБЬℓσ»" [tool.coverage.plugins.a_plugin] hello = "world" """) cov = coverage.Coverage(config_file="pyproject.toml") self.assertTrue(cov.config.timid) self.assertFalse(cov.config.branch) - self.assertEqual(cov.config.concurrency, ["a", "b"]) - self.assertEqual(cov.config.data_file, ".hello_kitty.data") - self.assertEqual(cov.config.plugins, ["plugins.a_plugin"]) + self.assertEqual(cov.config.concurrency, [u"a", u"b"]) + self.assertEqual(cov.config.data_file, u".hello_kitty.data") + self.assertEqual(cov.config.plugins, [u"plugins.a_plugin"]) self.assertEqual(cov.config.precision, 3) + self.assertEqual(cov.config.html_title, u"tabblo & «ταБЬℓσ»") self.assertAlmostEqual(cov.config.fail_under, 90.5) self.assertEqual( cov.config.get_plugin_options("plugins.a_plugin"), - {'hello': 'world'} + {u"hello": u"world"} ) # Test that our class doesn't reject integers when loading floats |