Skip to content

Commit

Permalink
Simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
tcompa committed Dec 19, 2024
1 parent f312873 commit bb418d7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 69 deletions.
18 changes: 8 additions & 10 deletions fractal_tasks_core/dev/lib_signature_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
59 changes: 0 additions & 59 deletions tests/dev/test_create_schema_for_single_task.py
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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,
)

0 comments on commit bb418d7

Please sign in to comment.