-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Create a salad schema
- Loading branch information
Showing
6 changed files
with
57 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ dependencies: | |
- black | ||
- f90nml=1.4* | ||
- jinja2=3.0* | ||
- jsonschema=4.17* | ||
- numpy=1.21* | ||
- pylint | ||
- pytest | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"type": "object", | ||
"properties": { | ||
"fruit": {"type": "string"}, | ||
"vegetable": {"type": "string"}, | ||
"how_many": {"type": "integer"}, | ||
"dressing": {"type": "string"} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
fruit: papaya | ||
vegetable: 4 | ||
how_many: 17 | ||
dressing: ranch | ||
topping: crouton | ||
size: large | ||
meat: chicken |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
''' | ||
Tests for schema validation tool | ||
''' | ||
import io | ||
import json | ||
from contextlib import redirect_stdout | ||
import os | ||
import pathlib | ||
import jsonschema | ||
import pytest | ||
import yaml | ||
|
||
|
||
uwtools_file_base = os.path.join(os.path.dirname(__file__)) | ||
|
||
def test_validate_yaml_salad(): #pylint: disable=unused-variable | ||
''' | ||
Test that simple salad schema is accepted as valid json schema and that it validates both valid | ||
and bad input files | ||
''' | ||
schema_file = os.path.join(os.path.dirname(uwtools_file_base), pathlib.Path("schema/salad.jsonschema")) | ||
input_file = os.path.join(uwtools_file_base, pathlib.Path("fixtures/fruit_config_similar.yaml")) | ||
bad_input_file = os.path.join(uwtools_file_base, pathlib.Path("fixtures/bad_fruit_config.yaml")) | ||
|
||
with open(schema_file, 'r', encoding="utf-8") as schema_file: | ||
schema = json.load(schema_file) | ||
with open(input_file, encoding="utf-8") as input_file: | ||
infile = yaml.safe_load(input_file) | ||
outstring = io.StringIO() | ||
with redirect_stdout(outstring): | ||
jsonschema.validate(infile, schema) | ||
result = outstring.getvalue() | ||
assert result == "" | ||
|
||
with open(bad_input_file, encoding="utf-8") as bad_input_file: | ||
bad_infile = yaml.safe_load(bad_input_file) | ||
with pytest.raises(jsonschema.exceptions.ValidationError): | ||
jsonschema.validate(bad_infile, schema) |