-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from jluethi/manifest_update
Update manifest and add test that manifest matches function signature
- Loading branch information
Showing
4 changed files
with
123 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import json | ||
from pathlib import Path | ||
|
||
import fractal_faim_hcs | ||
import pytest | ||
from devtools import debug | ||
from fractal_tasks_core.dev.lib_args_schemas import ( | ||
create_schema_for_single_task, | ||
) | ||
from fractal_tasks_core.dev.lib_signature_constraints import ( | ||
_extract_function, | ||
_validate_function_signature, | ||
) | ||
from jsonschema.validators import ( | ||
Draft7Validator, | ||
Draft201909Validator, | ||
Draft202012Validator, | ||
) | ||
|
||
FRACTAL_TASKS_CORE_DIR = Path(fractal_faim_hcs.__file__).parent | ||
with (FRACTAL_TASKS_CORE_DIR / "__FRACTAL_MANIFEST__.json").open("r") as f: | ||
MANIFEST = json.load(f) | ||
TASK_LIST = MANIFEST["task_list"] | ||
PACKAGE = "fractal_faim_hcs" | ||
|
||
|
||
def test_manifest_has_args_schemas_is_true(): | ||
debug(MANIFEST) | ||
assert MANIFEST["has_args_schemas"] | ||
|
||
|
||
def test_task_functions_have_valid_signatures(): | ||
""" | ||
Test that task functions have valid signatures. | ||
""" | ||
for _ind_task, task in enumerate(TASK_LIST): | ||
function_name = Path(task["executable"]).with_suffix("").name | ||
task_function = _extract_function( | ||
task["executable"], function_name, package_name=PACKAGE | ||
) | ||
_validate_function_signature(task_function) | ||
|
||
|
||
def test_args_schemas_are_up_to_date(): | ||
""" | ||
Test that args_schema attributes in the manifest are up-to-date | ||
""" | ||
for ind_task, task in enumerate(TASK_LIST): | ||
print(f"Now handling {task['executable']}") | ||
old_schema = TASK_LIST[ind_task]["args_schema"] | ||
new_schema = create_schema_for_single_task(task["executable"], package=PACKAGE) | ||
# The following step is required because some arguments may have a | ||
# default which has a non-JSON type (e.g. a tuple), which we need to | ||
# convert to JSON type (i.e. an array) before comparison. | ||
new_schema = json.loads(json.dumps(new_schema)) | ||
assert new_schema == old_schema | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"jsonschema_validator", | ||
[Draft7Validator, Draft201909Validator, Draft202012Validator], | ||
) | ||
def test_args_schema_comply_with_jsonschema_specs(jsonschema_validator): | ||
""" | ||
FIXME: it is not clear whether this test is actually useful | ||
""" | ||
for ind_task, task in enumerate(TASK_LIST): | ||
schema = TASK_LIST[ind_task]["args_schema"] | ||
my_validator = jsonschema_validator(schema=schema) | ||
my_validator.check_schema(my_validator.schema) | ||
print( | ||
f"Schema for task {task['executable']} is valid for " | ||
f"{jsonschema_validator}." | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import json | ||
import sys | ||
from pathlib import Path | ||
|
||
import fractal_tasks_core | ||
import requests | ||
from devtools import debug | ||
|
||
|
||
def test_valid_manifest(tmp_path): | ||
""" | ||
NOTE: to avoid adding a fractal-server dependency, we simply download the | ||
relevant file. In the future we may have a fractal-common package, and that | ||
one could be easily added as a `dev` dependency. | ||
""" | ||
|
||
url = ( | ||
"https://raw.githubusercontent.com/fractal-analytics-platform/" | ||
"fractal-common/main/schemas/manifest.py" | ||
) | ||
r = requests.get(url) | ||
debug(tmp_path) | ||
with (tmp_path / "fractal_manifest.py").open("wb") as fout: | ||
fout.write(r.content) | ||
|
||
sys.path.append(str(tmp_path)) | ||
from fractal_manifest import ManifestV1 | ||
|
||
module_dir = Path(fractal_tasks_core.__file__).parent | ||
with (module_dir / "__FRACTAL_MANIFEST__.json").open("r") as fin: | ||
manifest_dict = json.load(fin) | ||
manifest = ManifestV1(**manifest_dict) | ||
debug(manifest) |