Skip to content

Instantly share code, notes, and snippets.

@dhermes
Created October 15, 2014 06:04
Show Gist options
  • Save dhermes/8516afb92d14fdc38cb6 to your computer and use it in GitHub Desktop.
Save dhermes/8516afb92d14fdc38cb6 to your computer and use it in GitHub Desktop.
"""Simple utility to check config consistency.
Parses the production and test lint config files and makes
sure the test config inherits from the production config.
"""
import ConfigParser
PRODUCTION_RC = 'pylintrc_default'
TEST_RC = 'pylintrc_reduced'
def read_config(filename):
"""Reads pylintrc config onto native ConfigParser object."""
config = ConfigParser.ConfigParser()
with open(filename, 'r') as file_obj:
config.readfp(file_obj)
return config
def split_option(option_val, delimiter=','):
"""Splits a delimited list of options into a list."""
return [value.strip() for value in option_val.split(delimiter)
if value.strip()]
def check_valid_configs():
"""Checks that the test rcfile only extends production."""
full_config = read_config(PRODUCTION_RC)
reduced_config = read_config(TEST_RC)
for section in full_config.sections():
if not reduced_config.has_section(section):
raise ValueError('The section %r from the production config '
'is missing from the test config.' % (section,))
for option, opt_val in full_config.items(section):
try:
reduced_config_val = reduced_config.get(section, option)
except ConfigParser.NoOptionError:
raise ValueError('The option %r.%r from the production config '
'is missing from the test config.' % (
section, option))
# If not equal, we make sure the test options contain the
# production options as a sub-list.
if opt_val != reduced_config_val:
all_options = split_option(opt_val)
all_test_options = split_option(reduced_config_val)
if not set(all_options) <= set(all_test_options):
raise ValueError('Options disagree.')
if __name__ == '__main__':
check_valid_configs()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment