diff --git a/unittests/table_json_conversion/data/error_simple_data.json b/unittests/table_json_conversion/data/error_simple_data.json new file mode 100644 index 0000000000000000000000000000000000000000..bfea88b675ab2a6e0c1787fc401afec5c564c006 --- /dev/null +++ b/unittests/table_json_conversion/data/error_simple_data.json @@ -0,0 +1,11 @@ +{ + "Training": { + "duration": 1.0, + "participants": 0.5 + }, + "Person": { + "family_name": "Auric", + "given_name": "Goldfinger", + "Organisation": "Federal Reserve" + } +} diff --git a/unittests/table_json_conversion/test_fill_xlsx.py b/unittests/table_json_conversion/test_fill_xlsx.py index 0353eaa327ca79fd6b1cc69871f1eaee8bc4fa41..edc723d8db18e2f264811e8d4c2ac28d26d92b88 100644 --- a/unittests/table_json_conversion/test_fill_xlsx.py +++ b/unittests/table_json_conversion/test_fill_xlsx.py @@ -22,6 +22,8 @@ import os import tempfile +import jsonschema.exceptions as schema_exc +import pytest from caosadvancedtools.table_json_conversion.fill_xlsx import ( _get_path_rows, _get_row_type_column_index, fill_template) from openpyxl import load_workbook @@ -76,3 +78,17 @@ def test_fill_xlsx(): template_file=rfp("data/multiple_refs_template.xlsx"), known_good=rfp("data/multiple_refs_data.xlsx"), schema=rfp("data/multiple_refs_schema.json")) + + +def test_errors(): + with pytest.raises(AssertionError) as exc: + fill_and_compare(json_file=rfp("data/error_simple_data.json"), + template_file=rfp("data/simple_template.xlsx"), + known_good=rfp("data/simple_data.xlsx")) + assert "Auric\nSteve" in str(exc.value) + with pytest.raises(schema_exc.ValidationError) as exc: + fill_and_compare(json_file=rfp("data/error_simple_data.json"), + template_file=rfp("data/simple_template.xlsx"), + known_good=rfp("data/simple_data.xlsx"), + schema=rfp("data/simple_schema.json")) + assert exc.value.message == "0.5 is not of type 'integer'"