Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added test of turbine schema and fixed issues #70

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 34 additions & 3 deletions test/turbine/test_turbine.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import unittest
import os
from jsonschema import validate
import yaml
import unittest

import yaml
from jsonschema import Draft7Validator, validate

path2schema = (
os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
Expand Down Expand Up @@ -65,6 +65,37 @@ def test_IEA_15_240_RWT_VolturnUS_S(self):
_ = yaml.load(inputs, Loader=yaml.FullLoader)

return None

def test_valid_schema(self):
with open(path2schema, "r") as file:
schema = yaml.load(file, Loader=yaml.FullLoader)

Draft7Validator.META_SCHEMA["additionalProperties"] = False
Draft7Validator.META_SCHEMA["properties"]["definitions"]["additionalProperties"] = True
Draft7Validator.META_SCHEMA["properties"]["units"] = dict(type="string")
Draft7Validator.META_SCHEMA["properties"]["optional"] = Draft7Validator.META_SCHEMA["properties"]["required"]

Draft7Validator.check_schema(schema)

def recursive_require_optional_in_properties(schema, name_list=None):
if name_list is None:
name_list = []
for name in schema.get("required", []):
assert name in schema["properties"], f"Required property: '{name}' is not in `properties` for {name_list}"
for name in schema.get("optional", []):
assert name in schema["properties"], f"Optional property: '{name}' is not in `properties` for {name_list}"
for name, val in schema.items():
if name in ["if", "then", "else"]:
continue
if isinstance(val, dict):
recursive_require_optional_in_properties(val, name_list+[name])
if isinstance(val, list):
for iel, el in enumerate(val):
if isinstance(el, dict):
recursive_require_optional_in_properties(el, name_list+[name, iel])

recursive_require_optional_in_properties(schema)



def suite():
Expand Down
Loading
Loading