Adding test coverage report. Making tests a little less brittle.
This commit is contained in:
parent
745de200df
commit
e50fd04750
3 changed files with 12 additions and 12 deletions
|
@ -39,6 +39,7 @@ def parse_configuration(config_filename, schema_filename):
|
||||||
have permissions to read the file, or Validation_error if the config does not match the schema.
|
have permissions to read the file, or Validation_error if the config does not match the schema.
|
||||||
'''
|
'''
|
||||||
try:
|
try:
|
||||||
|
config = yaml.round_trip_load(open(config_filename))
|
||||||
schema = yaml.round_trip_load(open(schema_filename))
|
schema = yaml.round_trip_load(open(schema_filename))
|
||||||
except yaml.error.YAMLError as error:
|
except yaml.error.YAMLError as error:
|
||||||
raise Validation_error(config_filename, (str(error),))
|
raise Validation_error(config_filename, (str(error),))
|
||||||
|
@ -49,7 +50,7 @@ def parse_configuration(config_filename, schema_filename):
|
||||||
for field_name, field_schema in section_schema['map'].items():
|
for field_name, field_schema in section_schema['map'].items():
|
||||||
field_schema.pop('example')
|
field_schema.pop('example')
|
||||||
|
|
||||||
validator = pykwalify.core.Core(source_file=config_filename, schema_data=schema)
|
validator = pykwalify.core.Core(source_data=config, schema_data=schema)
|
||||||
parsed_result = validator.validate(raise_exception=False)
|
parsed_result = validator.validate(raise_exception=False)
|
||||||
|
|
||||||
if validator.validation_errors:
|
if validator.validation_errors:
|
||||||
|
@ -58,7 +59,7 @@ def parse_configuration(config_filename, schema_filename):
|
||||||
return parsed_result
|
return parsed_result
|
||||||
|
|
||||||
|
|
||||||
def display_validation_error(validation_error):
|
def display_validation_error(validation_error): # pragma: no cover
|
||||||
'''
|
'''
|
||||||
Given a Validation_error, display its error messages to stderr.
|
Given a Validation_error, display its error messages to stderr.
|
||||||
'''
|
'''
|
||||||
|
|
|
@ -17,15 +17,14 @@ def test_schema_filename_returns_plausable_path():
|
||||||
|
|
||||||
def mock_config_and_schema(config_yaml):
|
def mock_config_and_schema(config_yaml):
|
||||||
'''
|
'''
|
||||||
Set up mocks for the config config YAML string and the default schema so that pykwalify consumes
|
Set up mocks for the config config YAML string and the default schema so that the code under
|
||||||
them when parsing the configuration. This is a little brittle in that it's relying on the code
|
test consumes them when parsing the configuration.
|
||||||
under test to open() the respective files in a particular order.
|
|
||||||
'''
|
'''
|
||||||
schema_stream = open(module.schema_filename())
|
|
||||||
config_stream = io.StringIO(config_yaml)
|
config_stream = io.StringIO(config_yaml)
|
||||||
builtins = flexmock(sys.modules['builtins']).should_call('open').mock
|
schema_stream = open(module.schema_filename())
|
||||||
builtins.should_receive('open').and_return(schema_stream).and_return(config_stream)
|
builtins = flexmock(sys.modules['builtins'])
|
||||||
flexmock(os.path).should_receive('exists').and_return(True)
|
builtins.should_receive('open').with_args('config.yaml').and_return(config_stream)
|
||||||
|
builtins.should_receive('open').with_args('schema.yaml').and_return(schema_stream)
|
||||||
|
|
||||||
|
|
||||||
def test_parse_configuration_transforms_file_into_mapping():
|
def test_parse_configuration_transforms_file_into_mapping():
|
||||||
|
@ -95,9 +94,9 @@ def test_parse_configuration_raises_for_missing_schema_file():
|
||||||
|
|
||||||
|
|
||||||
def test_parse_configuration_raises_for_syntax_error():
|
def test_parse_configuration_raises_for_syntax_error():
|
||||||
mock_config_and_schema('invalid = yaml')
|
mock_config_and_schema('foo:\nbar')
|
||||||
|
|
||||||
with pytest.raises(module.Validation_error):
|
with pytest.raises(ValueError):
|
||||||
module.parse_configuration('config.yaml', 'schema.yaml')
|
module.parse_configuration('config.yaml', 'schema.yaml')
|
||||||
|
|
||||||
|
|
||||||
|
|
2
tox.ini
2
tox.ini
|
@ -5,4 +5,4 @@ skipsdist=True
|
||||||
[testenv]
|
[testenv]
|
||||||
usedevelop=True
|
usedevelop=True
|
||||||
deps=-rtest_requirements.txt
|
deps=-rtest_requirements.txt
|
||||||
commands = py.test --cov=borgmatic borgmatic []
|
commands = py.test --cov-report term-missing:skip-covered --cov=borgmatic borgmatic []
|
||||||
|
|
Loading…
Reference in a new issue