From 62588e36a839ee902f6f73d2f8ae2af476c051ce Mon Sep 17 00:00:00 2001 From: davidvlaminck <“david.vlaminck@mow.vlaanderen.be”> Date: Mon, 25 Nov 2024 23:05:34 +0100 Subject: [PATCH] warning for not using the model directory when it probably should be (valid base64 encoding) --- UnitTests/GeneralTests/OTLObjectHelper_test.py | 2 ++ otlmow_model/OtlmowModel/Helpers/OTLObjectHelper.py | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/UnitTests/GeneralTests/OTLObjectHelper_test.py b/UnitTests/GeneralTests/OTLObjectHelper_test.py index ab42763b1..3058e3cc8 100644 --- a/UnitTests/GeneralTests/OTLObjectHelper_test.py +++ b/UnitTests/GeneralTests/OTLObjectHelper_test.py @@ -377,6 +377,8 @@ def test_is_aim_id_valid(): aim_id = '12345678-1234-1234-1234-123456789012-b25kZXJkZWVsI0FsbENhc2VzVGVzdENsYXNz' # AllCasesTestClass model_path = Path(__file__).parent.parent / 'TestModel' + with pytest.warns(ImportWarning): + assert not is_aim_id(aim_id) assert is_aim_id(aim_id, model_directory=model_path) diff --git a/otlmow_model/OtlmowModel/Helpers/OTLObjectHelper.py b/otlmow_model/OtlmowModel/Helpers/OTLObjectHelper.py index e770b1560..62fdfa442 100644 --- a/otlmow_model/OtlmowModel/Helpers/OTLObjectHelper.py +++ b/otlmow_model/OtlmowModel/Helpers/OTLObjectHelper.py @@ -1,4 +1,5 @@ import base64 +import warnings from collections import defaultdict from pathlib import Path from typing import Iterable, List, Dict @@ -223,5 +224,8 @@ def is_aim_id(aim_id: str, model_directory: Path = None) -> bool: ns, name = short_uri.split('#') instance = dynamic_create_instance_from_ns_and_name(ns, name, model_directory=model_directory) return instance is not None + except ModuleNotFoundError: + warnings.warn('Could not import the module for the given aim_id, did you forget the model_directory?', category=ImportWarning) + return False except ValueError: return False