config_file = os.path.join(source_dir, '_config.yml')
config = load_yaml(config_file)
reporter.check_field(config_file, 'configuration', config, 'kind', 'lesson')
+ reporter.check_field(config_file, 'configuration', config, 'carpentry', ('swc', 'dc'))
+ reporter.check_field(config_file, 'configuration', config, 'title')
+ reporter.check_field(config_file, 'configuration', config, 'email')
+ reporter.check_field(config_file, 'configuration', config, 'repo')
+ reporter.check_field(config_file, 'configuration', config, 'root')
+ if ('repo' in config) and ('root' in config):
+ reporter.check(config['repo'].endswith(config['root']),
+ config_file,
+ 'Repository name "{0}" not consistent with root "{1}"',
+ config['repo'], config['root'])
def read_all_markdown(source_dir, parser):
]
+REPORTER_NOT_SET = []
+
class Reporter(object):
"""Collect and report errors."""
self.messages = []
- def check_field(self, filename, name, values, key, expected):
+ def check_field(self, filename, name, values, key, expected=REPORTER_NOT_SET):
"""Check that a dictionary has an expected value."""
if key not in values:
self.add(filename, '{0} does not contain {1}', name, key)
+ elif expected is REPORTER_NOT_SET:
+ pass
+ elif type(expected) in (tuple, set, list):
+ if values[key] not in expected:
+ self.add(filename, '{0} {1} value {2} is not in {3}', name, key, values[key], expected)
elif values[key] != expected:
self.add(filename, '{0} {1} is {2} not {3}', name, key, values[key], expected)