From fef11372cc389f03764d2f33e137118131782394 Mon Sep 17 00:00:00 2001 From: Daniel <d.hornung@indiscale.com> Date: Fri, 10 Jan 2025 16:18:15 +0100 Subject: [PATCH] MAINT: Adding NotImplementedError if validate=True --- src/caosadvancedtools/table_json_conversion/convert.py | 6 +++++- unittests/table_json_conversion/test_read_xlsx.py | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/caosadvancedtools/table_json_conversion/convert.py b/src/caosadvancedtools/table_json_conversion/convert.py index aabdf827..4b02fa46 100644 --- a/src/caosadvancedtools/table_json_conversion/convert.py +++ b/src/caosadvancedtools/table_json_conversion/convert.py @@ -710,7 +710,7 @@ def _set_in_nested(mydict: dict, path: list, value: Any, prefix: list = [], skip # ToDo: Fix https://gitlab.indiscale.com/caosdb/src/caosdb-advanced-user-tools/-/issues/138 # and remove pylint disable def to_dict(xlsx: Union[str, BinaryIO], schema: Union[dict, str, TextIO], - validate: bool = None, strict: bool = False) -> dict: # pylint: disable=unused-argument + validate: Optional[bool] = None, strict: bool = False) -> dict: """Convert the xlsx contents to a dict, it must follow a schema. Parameters @@ -733,5 +733,9 @@ def to_dict(xlsx: Union[str, BinaryIO], schema: Union[dict, str, TextIO], out: dict A dict representing the JSON with the extracted data. """ + if validate: + raise NotImplementedError( + "For input validation implement " + "https://gitlab.indiscale.com/caosdb/src/caosdb-advanced-user-tools/-/issues/138") converter = XLSXConverter(xlsx, schema, strict=strict) return converter.to_dict() diff --git a/unittests/table_json_conversion/test_read_xlsx.py b/unittests/table_json_conversion/test_read_xlsx.py index 2a81cdc8..ff32c6b1 100644 --- a/unittests/table_json_conversion/test_read_xlsx.py +++ b/unittests/table_json_conversion/test_read_xlsx.py @@ -43,7 +43,7 @@ def rfp(*pathcomponents): def convert_and_compare(xlsx_file: str, schema_file: str, known_good_file: str, known_good_data: Optional[dict] = None, strict: bool = False, - validate: bool = True) -> dict: + validate: bool = False) -> dict: """Convert an XLSX file and compare to a known result. Exactly one of ``known_good_file`` and ``known_good_data`` should be non-empty. @@ -53,6 +53,8 @@ Returns json: dict The result of the conversion. """ + # FIXME Set default "validate" back to True, after implementation of + # https://gitlab.indiscale.com/caosdb/src/caosdb-advanced-user-tools/-/issues/138 result = convert.to_dict(xlsx=xlsx_file, schema=schema_file, validate=validate) if known_good_file: with open(known_good_file, encoding="utf-8") as myfile: -- GitLab