From 841bae3bcb86d6ea98061a1ae1292541023a4fe7 Mon Sep 17 00:00:00 2001 From: "i.nueske" <i.nueske@indiscale.com> Date: Sat, 8 Feb 2025 17:13:37 +0100 Subject: [PATCH] BUG: Create and use jsonschema files that match test data layout --- .../data/indirect_data_schema.json | 66 ++++++ .../data/multiple_choice_data_schema.json | 60 +++++ .../data/multiple_refs_data_schema.json | 216 ++++++++++++++++++ .../table_json_conversion/test_read_xlsx.py | 14 +- 4 files changed, 349 insertions(+), 7 deletions(-) create mode 100644 unittests/table_json_conversion/data/indirect_data_schema.json create mode 100644 unittests/table_json_conversion/data/multiple_choice_data_schema.json create mode 100644 unittests/table_json_conversion/data/multiple_refs_data_schema.json diff --git a/unittests/table_json_conversion/data/indirect_data_schema.json b/unittests/table_json_conversion/data/indirect_data_schema.json new file mode 100644 index 00000000..f20eddaf --- /dev/null +++ b/unittests/table_json_conversion/data/indirect_data_schema.json @@ -0,0 +1,66 @@ +{ + "type": "object", + "properties": { + "Wrapper": { + "type": "array", + "items": { + "type": "object", + "required": [], + "additionalProperties": false, + "title": "Wrapper", + "properties": { + "name": { + "type": "string", + "description": "The name of the Record to be created" + }, + "Training": { + "type": "object", + "required": [], + "additionalProperties": false, + "title": "Training", + "properties": { + "name": { + "type": "string", + "description": "The name of the Record to be created" + }, + "url": { + "type": "string", + "description": "The URL" + } + } + }, + "Results": { + "description": "Results for a training", + "type": "array", + "items": { + "type": "object", + "required": [], + "additionalProperties": false, + "description": "Results for a training", + "title": "Results", + "properties": { + "name": { + "type": "string", + "description": "The name of the Record to be created" + }, + "year": { + "type": "integer" + }, + "avg_score": { + "description": "The average score for the linked training.", + "type": "number" + } + } + } + } + }, + "$schema": "https://json-schema.org/draft/2020-12/schema" + } + } + }, + "required": [ + "Wrapper" + ], + "additionalProperties": false, + "$schema": "https://json-schema.org/draft/2020-12/schema" +} diff --git a/unittests/table_json_conversion/data/multiple_choice_data_schema.json b/unittests/table_json_conversion/data/multiple_choice_data_schema.json new file mode 100644 index 00000000..4a881260 --- /dev/null +++ b/unittests/table_json_conversion/data/multiple_choice_data_schema.json @@ -0,0 +1,60 @@ +{ + "type": "object", + "properties": { + "Training": { + "type": "array", + "items": { + "type": "object", + "required": [], + "additionalProperties": false, + "title": "Training", + "properties": { + "name": { + "type": "string", + "description": "The name of the Record to be created" + }, + "date": { + "description": "The date of the training.", + "anyOf": [ + { + "type": "string", + "format": "date" + }, + { + "type": "string", + "format": "date-time" + } + ] + }, + "skills": { + "description": "Skills that are trained.", + "type": "array", + "items": { + "enum": [ + "Planning", + "Communication", + "Evaluation" + ] + }, + "uniqueItems": true + }, + "exam_types": { + "type": "array", + "items": { + "enum": [ + "Oral", + "Written" + ] + }, + "uniqueItems": true + } + } + } + } + }, + "required": [ + "Training" + ], + "additionalProperties": false, + "$schema": "https://json-schema.org/draft/2020-12/schema" +} diff --git a/unittests/table_json_conversion/data/multiple_refs_data_schema.json b/unittests/table_json_conversion/data/multiple_refs_data_schema.json new file mode 100644 index 00000000..7971ad2a --- /dev/null +++ b/unittests/table_json_conversion/data/multiple_refs_data_schema.json @@ -0,0 +1,216 @@ +{ + "type": "object", + "properties": { + "Training": { + "type": "array", + "items": { + "type": "object", + "required": [], + "additionalProperties": false, + "title": "Training", + "properties": { + "name": { + "type": "string", + "description": "The name of the Record to be created" + }, + "date": { + "description": "The date of the training.", + "anyOf": [ + { + "type": "string", + "format": "date" + }, + { + "type": "string", + "format": "date-time" + } + ] + }, + "url": { + "type": "string", + "description": "The URL" + }, + "trainer": { + "type": "array", + "items": { + "type": "object", + "required": [], + "additionalProperties": false, + "title": "trainer", + "properties": { + "name": { + "type": "string", + "description": "The name of the Record to be created" + }, + "full_name": { + "type": "string" + }, + "email": { + "type": "string" + } + } + } + }, + "participant": { + "type": "array", + "items": { + "type": "object", + "required": [], + "additionalProperties": false, + "title": "participant", + "properties": { + "name": { + "type": "string", + "description": "The name of the Record to be created" + }, + "full_name": { + "type": "string" + }, + "email": { + "type": "string" + } + } + } + }, + "supervisor": { + "type": "object", + "required": [], + "additionalProperties": false, + "title": "supervisor", + "properties": { + "name": { + "type": "string", + "description": "The name of the Record to be created" + }, + "full_name": { + "type": "string" + }, + "email": { + "type": "string" + } + } + }, + "responsible": { + "type": "object", + "required": [], + "additionalProperties": false, + "title": "responsible", + "properties": { + "name": { + "type": "string", + "description": "The name of the Record to be created" + }, + "full_name": { + "type": "string" + }, + "email": { + "type": "string" + } + } + }, + "Organisation": { + "type": "array", + "items": { + "type": "object", + "required": [], + "additionalProperties": false, + "title": "Organisation", + "properties": { + "name": { + "type": "string", + "description": "The name of the Record to be created" + }, + "Country": { + "type": "string" + }, + "Person": { + "type": "array", + "items": { + "type": "object", + "required": [], + "additionalProperties": false, + "title": "Person", + "properties": { + "name": { + "type": "string", + "description": "The name of the Record to be created" + }, + "full_name": { + "type": "string" + }, + "email": { + "type": "string" + } + } + } + } + } + } + }, + "supervisor_inherit": { + "type": "object", + "required": [], + "additionalProperties": false, + "title": "supervisor_inherit", + "properties": { + "name": { + "type": "string", + "description": "The name of the Record to be created" + }, + "full_name": { + "type": "string" + }, + "email": { + "type": "string" + } + } + }, + "responsible_inherit": { + "type": "object", + "required": [], + "additionalProperties": false, + "title": "responsible_inherit", + "properties": { + "name": { + "type": "string", + "description": "The name of the Record to be created" + }, + "full_name": { + "type": "string" + }, + "email": { + "type": "string" + } + } + } + }, + "$schema": "https://json-schema.org/draft/2020-12/schema" + } + }, + "Person": { + "type": "array", + "items": { + "type": "object", + "required": [], + "additionalProperties": false, + "title": "Person", + "properties": { + "name": { + "type": "string", + "description": "The name of the Record to be created" + }, + "full_name": { + "type": "string" + }, + "email": { + "type": "string" + } + }, + "$schema": "https://json-schema.org/draft/2020-12/schema" + } + } + }, + "required": [], + "additionalProperties": false, + "$schema": "https://json-schema.org/draft/2020-12/schema" +} diff --git a/unittests/table_json_conversion/test_read_xlsx.py b/unittests/table_json_conversion/test_read_xlsx.py index 5bee9297..ae49f82a 100644 --- a/unittests/table_json_conversion/test_read_xlsx.py +++ b/unittests/table_json_conversion/test_read_xlsx.py @@ -66,33 +66,33 @@ json: dict def test_conversions(): """Test conversion from XLSX to JSON.""" convert_and_compare(xlsx_file=rfp("data/simple_data.xlsx"), - schema_file=rfp("data/simple_schema.json"), + schema_file=rfp("data/simple_data_schema.json"), known_good_file=rfp("data/simple_data.json")) convert_and_compare(xlsx_file=rfp("data/multiple_refs_data.xlsx"), - schema_file=rfp("data/multiple_refs_schema.json"), + schema_file=rfp("data/multiple_refs_data_schema.json"), known_good_file=rfp("data/multiple_refs_data.json")) convert_and_compare(xlsx_file=rfp("data/indirect_data.xlsx"), - schema_file=rfp("data/indirect_schema.json"), + schema_file=rfp("data/indirect_data_schema.json"), known_good_file=rfp("data/indirect_data.json")) convert_and_compare(xlsx_file=rfp("data/multiple_choice_data.xlsx"), - schema_file=rfp("data/multiple_choice_schema.json"), + schema_file=rfp("data/multiple_choice_data_schema.json"), known_good_file=rfp("data/multiple_choice_data.json"), strict=True) convert_and_compare(xlsx_file=rfp("data/simple_data_booleans.xlsx"), - schema_file=rfp("data/simple_schema.json"), + schema_file=rfp("data/simple_data_schema.json"), known_good_file=rfp("data/simple_data_booleans.json")) with open(rfp("data/simple_data.json"), encoding="utf-8") as myfile: expected_datetime = json.load(myfile) expected_datetime["Training"][0]["date"] = datetime.datetime(2023, 1, 1, 0, 0) convert_and_compare(xlsx_file=rfp("data/simple_data_datetime.xlsx"), - schema_file=rfp("data/simple_schema.json"), + schema_file=rfp("data/simple_data_schema.json"), known_good_file="", known_good_data=expected_datetime) # Data loss when saving as xlsx with pytest.raises(AssertionError) as err: convert_and_compare(xlsx_file=rfp("data/simple_data_ascii_chars.xlsx"), - schema_file=rfp("data/simple_schema.json"), + schema_file=rfp("data/simple_data_schema.json"), known_good_file=rfp("data/simple_data_ascii_chars.json")) assert str(err.value).startswith("Values at path ['Training', 0, ") -- GitLab