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 0000000000000000000000000000000000000000..f20eddaf6fdcb0b4fce6e01c6fdb420e1d976b9a --- /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 0000000000000000000000000000000000000000..4a88126052d14212fdc9f08076ee5f5189accaa9 --- /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 0000000000000000000000000000000000000000..7971ad2a2c6b8391977aeba420b82430a5a1fa1e --- /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 5bee9297478d70cc806d0e6759e9b9f5a7f9cb53..ae49f82af285dba631810e572a7c98be4585e8c5 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, ")