summaryrefslogtreecommitdiff
path: root/coverage/config.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2015-07-27 20:31:00 -0400
committerNed Batchelder <ned@nedbatchelder.com>2015-07-27 20:31:00 -0400
commit65f8a80beb2373a3eaaa9b509451abf56155b332 (patch)
treed16afb85de70333e6f68cc2f8801c18a78bfeb6a /coverage/config.py
parentc491c93d3f37d070cf2997f78d3e9cc3e83beac9 (diff)
downloadpython-coveragepy-65f8a80beb2373a3eaaa9b509451abf56155b332.tar.gz
Fail on unrecognized configuration options. #386
Diffstat (limited to 'coverage/config.py')
-rw-r--r--coverage/config.py23
1 files changed, 22 insertions, 1 deletions
diff --git a/coverage/config.py b/coverage/config.py
index edcf13e..9939d6c 100644
--- a/coverage/config.py
+++ b/coverage/config.py
@@ -3,7 +3,11 @@
"""Config file for coverage.py"""
-import os, re, sys
+import collections
+import os
+import re
+import sys
+
from coverage.backward import configparser, iitems, string_class
from coverage.misc import CoverageException
@@ -221,6 +225,23 @@ class CoverageConfig(object):
except ValueError as err:
raise CoverageException("Couldn't read config file %s: %s" % (filename, err))
+ # Check that there are no unrecognized options.
+ all_options = collections.defaultdict(set)
+ for option_spec in self.CONFIG_FILE_OPTIONS:
+ section, option = option_spec[1].split(":")
+ all_options[section].add(option)
+
+ for section, options in iitems(all_options):
+ if cp.has_section(section):
+ for unknown in set(cp.options(section)) - options:
+ if section_prefix:
+ section = section_prefix + section
+ raise CoverageException(
+ "Unrecognized option '[%s] %s=' in config file %s" % (
+ section, unknown, filename
+ )
+ )
+
# [paths] is special
if cp.has_section('paths'):
for option in cp.options('paths'):