mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-11-02 19:52:14 +08:00
Found by running: ``` make pyupgrade ruff check --fix . ruff check --preview --unsafe-fixes --select=F401 --fix . make format make update-client-api-schema ``` The bulk of the changes are replacements of typing deprecated aliases such as `Dict` and `List` with the standard library classes. These aliases became redundant in Python 3.9 when the corresponding pre-existing classes were enhanced to support `[]`, see https://docs.python.org/3/library/typing.html#deprecated-aliases Also: - Update the `pyupgrade` Makefile target to use `--py38-plus` for the packages needed by Pulsar, including the new galaxy-tool-util-models package.
33 lines
1.0 KiB
Python
33 lines
1.0 KiB
Python
from typing import (
|
|
Any,
|
|
)
|
|
|
|
import jsonschema
|
|
|
|
from galaxy.util import requests
|
|
from galaxy_test.base import api_asserts
|
|
|
|
schema_store: dict[str, Any] = {}
|
|
|
|
|
|
class JsonSchemaValidator:
|
|
@staticmethod
|
|
def validate_using_schema_url(instance: dict, schema_url: str):
|
|
schema = schema_store.get(schema_url, None)
|
|
if not schema:
|
|
response = requests.get(schema_url)
|
|
api_asserts.assert_status_code_is_ok(response)
|
|
schema = response.json()
|
|
schema_store[schema_url] = schema
|
|
JsonSchemaValidator.validate(instance, schema)
|
|
|
|
@staticmethod
|
|
def validate(instance: dict, schema: dict):
|
|
try:
|
|
schema_version = schema.get("$id", "Unknown schema version")
|
|
jsonschema.validate(instance=instance, schema=schema)
|
|
except jsonschema.exceptions.ValidationError as err:
|
|
raise AssertionError(
|
|
f"The instance does not validate against the schema: {schema_version}.\nReasons:\n{err}"
|
|
)
|