Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tcompa committed Jul 19, 2024
1 parent c7a60d0 commit aec104f
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,70 +4,29 @@
"name": "Task Name",
"executable": "tasks/my_task.py",
"args_schema": {
"title": "MyTask",
"type": "object",
"properties": {
"x": {
"title": "X",
"type": "integer",
"description": "Missing description"
},
"y": {
"$ref": "#/definitions/OmeroChannel",
"description": "Missing description"
},
"z": {
"$ref": "#/definitions/CustomModel",
"description": "Missing description"
}
},
"required": [
"x",
"y",
"z"
],
"additionalProperties": false,
"definitions": {
"Window": {
"title": "Window",
"description": "Custom class for Omero-channel window, based on OME-NGFF v0.4.",
"type": "object",
"$defs": {
"CustomModel": {
"description": "Short description",
"properties": {
"min": {
"title": "Min",
"type": "integer",
"description": "Do not change. It will be set to ``0`` by default."
},
"max": {
"title": "Max",
"type": "integer",
"description": "Do not change. It will be set according to bit-depth of the images by default (e.g. 65535 for 16 bit images)."
},
"start": {
"title": "Start",
"type": "integer",
"description": "Lower-bound rescaling value for visualization."
},
"end": {
"title": "End",
"x": {
"title": "X",
"type": "integer",
"description": "Upper-bound rescaling value for visualization."
"description": "Description of `x`"
}
},
"required": [
"start",
"end"
]
"x"
],
"title": "CustomModel",
"type": "object"
},
"OmeroChannel": {
"title": "OmeroChannel",
"description": "Custom class for Omero channels, based on OME-NGFF v0.4.",
"type": "object",
"properties": {
"wavelength_id": {
"title": "Wavelength Id",
"type": "string",
"description": "Unique ID for the channel wavelength, e.g. ``A01_C01``."
"description": "Unique ID for the channel wavelength, e.g. `A01_C01`."
},
"index": {
"title": "Index",
Expand All @@ -77,58 +36,107 @@
"label": {
"title": "Label",
"type": "string",
"description": "Name of the channel"
"description": "Name of the channel."
},
"window": {
"$ref": "#/definitions/Window",
"description": "Optional ``Window`` object to set default display settings for napari."
"allOf": [
{
"$ref": "#/$defs/Window"
}
],
"title": "Window",
"description": "Optional `Window` object to set default display settings for napari."
},
"color": {
"title": "Color",
"type": "string",
"description": "Optional hex colormap to display the channel in napari (e.g. ``00FFFF``)."
"description": "Optional hex colormap to display the channel in napari (it must be of length 6, e.g. `00FFFF`)."
},
"active": {
"title": "Active",
"default": true,
"title": "Active",
"type": "boolean",
"description": "Should this channel be shown in the viewer?"
},
"coefficient": {
"title": "Coefficient",
"default": 1,
"title": "Coefficient",
"type": "integer",
"description": "Do not change. Omero-channel attribute. "
"description": "Do not change. Omero-channel attribute."
},
"inverted": {
"title": "Inverted",
"default": false,
"title": "Inverted",
"type": "boolean",
"description": "Do not change. Omero-channel attribute."
}
},
"required": [
"wavelength_id"
]
],
"title": "OmeroChannel",
"type": "object"
},
"CustomModel": {
"title": "CustomModel",
"type": "object",
"Window": {
"description": "Custom class for Omero-channel window, based on OME-NGFF v0.4.",
"properties": {
"x": {
"title": "X",
"min": {
"title": "Min",
"type": "integer",
"description": "Do not change. It will be set to `0` by default."
},
"max": {
"title": "Max",
"type": "integer",
"description": "Do not change. It will be set according to bit-depth of the images by default (e.g. 65535 for 16 bit images)."
},
"start": {
"title": "Start",
"type": "integer",
"description": "Lower-bound rescaling value for visualization."
},
"end": {
"title": "End",
"type": "integer",
"description": "Missing description"
"description": "Upper-bound rescaling value for visualization."
}
},
"required": [
"x"
]
"start",
"end"
],
"title": "Window",
"type": "object"
}
},
"additionalProperties": false,
"properties": {
"x": {
"title": "X",
"type": "integer",
"description": "Missing description"
},
"y": {
"$ref": "#/$defs/OmeroChannel",
"title": "Y",
"description": "Missing description"
},
"z": {
"$ref": "#/$defs/CustomModel",
"title": "Z",
"description": "Missing description"
}
}
},
"required": [
"x",
"y",
"z"
],
"type": "object",
"title": "MyTask"
}
}
],
"has_args_schemas": true,
"args_schema_version": "pydantic_v1"
"args_schema_version": "pydantic_v2"
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
from pydantic.v1 import BaseModel
from pydantic import BaseModel


class CustomModel(BaseModel):
"""
Short description
Attributes:
x: Description of `x`
"""

x: int
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

# Set global properties of manifest
manifest["has_args_schemas"] = True
manifest["args_schema_version"] = "pydantic_v1"
manifest["args_schema_version"] = "pydantic_v2"

# Loop over tasks and set args schemas
task_list = manifest["task_list"]
Expand Down
18 changes: 3 additions & 15 deletions tests/dev/test_optional_argument.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import json
from typing import Optional

from pydantic.v1.decorator import validate_arguments
from pydantic.validate_call_decorator import validate_call

from fractal_tasks_core.dev.lib_args_schemas import (
create_schema_for_single_task,
)


@validate_call
def task_function(
arg1: Optional[str] = None,
arg2: Optional[list[str]] = None,
Expand All @@ -25,23 +25,11 @@ def task_function(

def test_optional_argument():

schema1 = create_schema_for_single_task(
task_function=validate_arguments(task_function),
executable=__file__,
package=None,
args_schema_version="pydantic_v1",
verbose=True,
)

schema2 = create_schema_for_single_task(
schema = create_schema_for_single_task(
task_function=validate_call(task_function),
executable=__file__,
package=None,
args_schema_version="pydantic_v2",
verbose=True,
)

print(json.dumps(schema1, indent=2, sort_keys=True))
print(json.dumps(schema2, indent=2, sort_keys=True))
print(json.dumps(schema, indent=2, sort_keys=True))
print()
assert schema1 == schema2

0 comments on commit aec104f

Please sign in to comment.