From bb418d7775b988b6fb514ce02c38fb9741aae415 Mon Sep 17 00:00:00 2001 From: Tommaso Comparin <3862206+tcompa@users.noreply.github.com> Date: Thu, 19 Dec 2024 13:02:20 +0100 Subject: [PATCH] Simplify --- .../dev/lib_signature_constraints.py | 18 +++--- .../dev/test_create_schema_for_single_task.py | 59 ------------------- 2 files changed, 8 insertions(+), 69 deletions(-) diff --git a/fractal_tasks_core/dev/lib_signature_constraints.py b/fractal_tasks_core/dev/lib_signature_constraints.py index a16efae47..affa2ca6e 100644 --- a/fractal_tasks_core/dev/lib_signature_constraints.py +++ b/fractal_tasks_core/dev/lib_signature_constraints.py @@ -51,19 +51,17 @@ def _extract_function( Path(module_relative_path).with_suffix("") ) module_relative_path_dots = module_relative_path_no_py.replace("/", ".") - if verbose: - logging.info( - f"Now calling `import_module` for " - f"{package_name}.{module_relative_path_dots}" - ) + logging.warning( + f"Now calling `import_module` for " + f"{package_name}.{module_relative_path_dots}" + ) imported_module = import_module( f"{package_name}.{module_relative_path_dots}" ) - if verbose: - logging.info( - f"Now getting attribute {function_name} from " - f"imported module {imported_module}." - ) + logging.warning( + f"Now getting attribute {function_name} from " + f"imported module {imported_module}." + ) task_function = getattr(imported_module, function_name) return task_function diff --git a/tests/dev/test_create_schema_for_single_task.py b/tests/dev/test_create_schema_for_single_task.py index 2cd43ba00..649c279ef 100644 --- a/tests/dev/test_create_schema_for_single_task.py +++ b/tests/dev/test_create_schema_for_single_task.py @@ -1,8 +1,6 @@ import json -import pytest from devtools import debug -from pydantic import validate_call from fractal_tasks_core.dev.lib_args_schemas import ( create_schema_for_single_task, @@ -21,60 +19,3 @@ def test_create_schema_for_single_task_usage_1(): ) debug(schema) print(json.dumps(schema, indent=2)) - - -@validate_call -def task_function(arg_1: int = 1): - """ - Description - - Args: - arg_1: Description of arg_1. - """ - - -def test_create_schema_for_single_task_usage_2(): - """ - This test reproduces the schema-creation scenario starting from an - existing function, as it's done in tests. - """ - schema = create_schema_for_single_task( - task_function=task_function, - executable=__file__, - package=None, - verbose=True, - ) - debug(schema) - print(json.dumps(schema, indent=2)) - - -def test_create_schema_for_single_task_failures(): - """ - This test reproduces some invalid usage of the schema-creation function - """ - with pytest.raises(ValueError): - create_schema_for_single_task( - task_function=task_function, - executable=__file__, - package="something", - verbose=True, - ) - with pytest.raises(ValueError): - create_schema_for_single_task( - task_function=task_function, - executable="non_absolute/path/module.py", - package=None, - verbose=True, - ) - with pytest.raises(ValueError): - create_schema_for_single_task( - executable="/absolute/path/cellpose_segmentation.py", - package="fractal_tasks_core", - verbose=True, - ) - with pytest.raises(ValueError): - create_schema_for_single_task( - executable="cellpose_segmentation.py", - package=None, - verbose=True, - )