Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/fastcs/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import inspect
import json
from pathlib import Path
from typing import Annotated, Optional, TypeAlias, get_type_hints
from typing import Annotated, Any, Optional, TypeAlias, get_type_hints

import typer
from pydantic import BaseModel, create_model
Expand Down Expand Up @@ -231,3 +231,9 @@ def _extract_options_model(controller_class: type[Controller]) -> type[BaseModel
f".__init__' but received {len(args)} as `{sig}`"
)
return fastcs_options


def get_controller_schema(target: type[Controller]) -> dict[str, Any]:
options_model = _extract_options_model(target)
target_schema = options_model.model_json_schema()
return target_schema
4 changes: 2 additions & 2 deletions tests/data/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"EpicsDocsOptions": {
"properties": {
"path": {
"default": "/home/esq51579/WIP/FastCS",
"default": ".",
"format": "path",
"title": "Path",
"type": "string"
Expand Down Expand Up @@ -35,7 +35,7 @@
"EpicsGUIOptions": {
"properties": {
"output_path": {
"default": "/home/esq51579/WIP/FastCS/output.bob",
"default": "output.bob",
"format": "path",
"title": "Output Path",
"type": "string"
Expand Down
9 changes: 8 additions & 1 deletion tests/test_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
import pytest
from pydantic import create_model
from pytest_mock import MockerFixture
from ruamel.yaml import YAML
from typer.testing import CliRunner

from fastcs.__main__ import __version__
from fastcs.attributes import AttrR
from fastcs.controller import Controller
from fastcs.datatypes import Int
from fastcs.exceptions import LaunchError
from fastcs.launch import TransportOptions, _launch, launch
from fastcs.launch import TransportOptions, _launch, get_controller_schema, launch


@dataclass
Expand Down Expand Up @@ -133,3 +134,9 @@ def test_launch(mocker: MockerFixture, data):
run.assert_called_once()
gui.assert_called_once()
docs.assert_called_once()


def test_get_schema(data):
ref_schema = YAML(typ="safe").load(data / "schema.json")
target_schema = get_controller_schema(IsHinted)
assert target_schema == ref_schema
Loading