From 299922bfcd98dbc438e5d2ee6971ab6ed6e18e22 Mon Sep 17 00:00:00 2001 From: Daniel <d.hornung@indiscale.com> Date: Fri, 8 Mar 2024 11:36:03 +0100 Subject: [PATCH] ENH: Filling XLSX Tests now also test for handling of invalid data. --- .../data/error_simple_data.json | 11 +++++++++++ .../table_json_conversion/test_fill_xlsx.py | 16 ++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 unittests/table_json_conversion/data/error_simple_data.json 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 00000000..bfea88b6 --- /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 0353eaa3..edc723d8 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'" -- GitLab