Browse Source

Adding test coverage report. Making tests a little less brittle.

Dan Helfman 1 year ago
parent
commit
f4e5dc8382
3 changed files with 12 additions and 12 deletions
  1. 3
    2
      borgmatic/config/validate.py
  2. 8
    9
      borgmatic/tests/integration/config/test_validate.py
  3. 1
    1
      tox.ini

+ 3
- 2
borgmatic/config/validate.py View File

@@ -39,6 +39,7 @@ def parse_configuration(config_filename, schema_filename):
39 39
     have permissions to read the file, or Validation_error if the config does not match the schema.
40 40
     '''
41 41
     try:
42
+        config = yaml.round_trip_load(open(config_filename))
42 43
         schema = yaml.round_trip_load(open(schema_filename))
43 44
     except yaml.error.YAMLError as error:
44 45
         raise Validation_error(config_filename, (str(error),))
@@ -49,7 +50,7 @@ def parse_configuration(config_filename, schema_filename):
49 50
         for field_name, field_schema in section_schema['map'].items():
50 51
             field_schema.pop('example')
51 52
 
52
-    validator = pykwalify.core.Core(source_file=config_filename, schema_data=schema)
53
+    validator = pykwalify.core.Core(source_data=config, schema_data=schema)
53 54
     parsed_result = validator.validate(raise_exception=False)
54 55
 
55 56
     if validator.validation_errors:
@@ -58,7 +59,7 @@ def parse_configuration(config_filename, schema_filename):
58 59
     return parsed_result
59 60
 
60 61
 
61
-def display_validation_error(validation_error):
62
+def display_validation_error(validation_error):  # pragma: no cover
62 63
     '''
63 64
     Given a Validation_error, display its error messages to stderr.
64 65
     '''

+ 8
- 9
borgmatic/tests/integration/config/test_validate.py View File

@@ -17,15 +17,14 @@ def test_schema_filename_returns_plausable_path():
17 17
 
18 18
 def mock_config_and_schema(config_yaml):
19 19
     '''
20
-    Set up mocks for the config config YAML string and the default schema so that pykwalify consumes
21
-    them when parsing the configuration. This is a little brittle in that it's relying on the code
22
-    under test to open() the respective files in a particular order.
20
+    Set up mocks for the config config YAML string and the default schema so that the code under
21
+    test consumes them when parsing the configuration.
23 22
     '''
24
-    schema_stream = open(module.schema_filename())
25 23
     config_stream = io.StringIO(config_yaml)
26
-    builtins = flexmock(sys.modules['builtins']).should_call('open').mock
27
-    builtins.should_receive('open').and_return(schema_stream).and_return(config_stream)
28
-    flexmock(os.path).should_receive('exists').and_return(True)
24
+    schema_stream = open(module.schema_filename())
25
+    builtins = flexmock(sys.modules['builtins'])
26
+    builtins.should_receive('open').with_args('config.yaml').and_return(config_stream)
27
+    builtins.should_receive('open').with_args('schema.yaml').and_return(schema_stream)
29 28
 
30 29
 
31 30
 def test_parse_configuration_transforms_file_into_mapping():
@@ -95,9 +94,9 @@ def test_parse_configuration_raises_for_missing_schema_file():
95 94
 
96 95
 
97 96
 def test_parse_configuration_raises_for_syntax_error():
98
-    mock_config_and_schema('invalid = yaml')
97
+    mock_config_and_schema('foo:\nbar')
99 98
 
100
-    with pytest.raises(module.Validation_error):
99
+    with pytest.raises(ValueError):
101 100
         module.parse_configuration('config.yaml', 'schema.yaml')
102 101
 
103 102
 

+ 1
- 1
tox.ini View File

@@ -5,4 +5,4 @@ skipsdist=True
5 5
 [testenv]
6 6
 usedevelop=True
7 7
 deps=-rtest_requirements.txt
8
-commands = py.test --cov=borgmatic borgmatic []
8
+commands = py.test --cov-report term-missing:skip-covered --cov=borgmatic borgmatic []

Loading…
Cancel
Save