Skip to content

Commit

Permalink
Require data.spec only on certain data types (#366)
Browse files Browse the repository at this point in the history
* Require data.spec only on certain data types

* linting

* improve test

* linting

* include test for table object

* remove unnecessary allOf
  • Loading branch information
adnejacobsen authored Sep 8, 2023
1 parent b2b909c commit 7d2a709
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 1 deletion.
71 changes: 71 additions & 0 deletions schema/definitions/0.8.0/examples/dictionary_parameters.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
$schema: "https://main-fmu-schemas-prod.radix.equinor.com/schemas/0.8.0/fmu_results.json"
version: "0.8.0"
source: "fmu"
tracklog:
- datetime: "2023-09-07T07:39:33.291683"
user:
id: "adnj"
event: "created"
class: "dictionary"
fmu:
model:
name: "ff"
revision: "undefined"
context:
stage: "realization"
case:
name: "adnj_drogon_parameters_test"
uuid: "0db864d3-ac25-4e0f-9195-36fd524e0840"
user:
id: "adnj"
iteration:
id: 0
uuid: "dad9a25a-3ad0-0f0a-08f2-c6fe8aae4c45"
name: "iter-0"
realization:
id: 0
uuid: "28274007-fd40-29c4-c6ef-10e2414ccdcd"
name: "realization-0"
file:
relative_path: "realization-0/iter-0/share/results/dictionaries/parameters.json"
absolute_path: "/scratch/fmu/adnj/adnj_drogon_parameters_test/realization-0/iter-0/share/results/dictionaries/parameters.json"
checksum_md5: "ebbf160256cc2cf2011ed2fb6ac13f85"
data:
name: "parameters"
stratigraphic: false
content: "parameters"
tagname: ""
format: "json"
layout: "dictionary"
unit: ""
vertical_domain: "depth"
depth_reference: "msl"
undef_is_zero: false
is_prediction: true
is_observation: false
display:
name: "parameters"
access:
asset:
name: "Drogon"
ssdl:
access_level: "internal"
rep_include: false
classification: "internal"
masterdata:
smda:
country:
- identifier: "Norway"
uuid: "ad214d85-8a1d-19da-e053-c918a4889309"
discovery:
- short_identifier: "DROGON"
uuid: "ad214d85-8a1d-19da-e053-c918a4889309"
field:
- identifier: "DROGON"
uuid: "00000000-0000-0000-0000-000000000000"
coordinate_system:
identifier: "ST_WGS84_UTM37N_P32637"
uuid: "ad214d85-dac7-19da-e053-c918a4889309"
stratigraphic_column:
identifier: "DROGON_HAS_NO_STRATCOLUMN"
uuid: "00000000-0000-0000-0000-000000000000"
20 changes: 19 additions & 1 deletion schema/definitions/0.8.0/schema/fmu_results.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@
"content",
"name",
"format",
"spec",
"stratigraphic",
"is_prediction",
"is_observation"
Expand Down Expand Up @@ -1370,6 +1369,25 @@
"ssdl"
]
}
},
"if": {
"properties": {
"class": {
"enum": [
"table",
"surface"
]
}
}
},
"then": {
"properties": {
"data": {
"required": [
"spec"
]
}
}
}
}
]
Expand Down
36 changes: 36 additions & 0 deletions tests/test_schema/test_schema_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,3 +347,39 @@ def test_schema_logic_classification(schema_080, metadata_examples):
example["access"]["classification"] = "open"
with pytest.raises(jsonschema.exceptions.ValidationError):
jsonschema.validate(instance=example, schema=schema_080)


def test_schema_logic_data_spec(schema_080, metadata_examples):
"""Test schema logic for data.spec"""

# fetch surface example
example_surface = deepcopy(metadata_examples["surface_depth.yml"])

# assert validation with no changes
jsonschema.validate(instance=example_surface, schema=schema_080)

# assert data.spec required when class == surface
del example_surface["data"]["spec"]
with pytest.raises(jsonschema.exceptions.ValidationError):
jsonschema.validate(instance=example_surface, schema=schema_080)

# fetch table example
example_table = deepcopy(metadata_examples["table_inplace.yml"])

# assert validation with no changes
jsonschema.validate(instance=example_table, schema=schema_080)

# assert data.spec required when class == table
del example_table["data"]["spec"]
with pytest.raises(jsonschema.exceptions.ValidationError):
jsonschema.validate(instance=example_table, schema=schema_080)

# fetch dictionary example
example_dict = deepcopy(metadata_examples["dictionary_parameters.yml"])

# assert data.spec is not present
with pytest.raises(KeyError):
example_dict["data"]["spec"]

# assert data.spec not required when class === dictionary
jsonschema.validate(instance=example_dict, schema=schema_080)

0 comments on commit 7d2a709

Please sign in to comment.