33
44import pytest
55from pydantic import create_model
6+ from pytest_mock import MockerFixture
67from typer .testing import CliRunner
78
89from fastcs .controller import Controller
@@ -40,7 +41,23 @@ def __init__(self, arg: SomeConfig, too_many):
4041runner = CliRunner ()
4142
4243
43- def test_is_hinted_schema ():
44+ def test_single_arg_schema ():
45+ target_model = create_model (
46+ "SingleArg" ,
47+ transport = (EpicsOptions | TangoOptions , ...),
48+ __config__ = {"extra" : "forbid" },
49+ )
50+ target_dict = target_model .model_json_schema ()
51+
52+ app = _launch (SingleArg )
53+ result = runner .invoke (app , ["schema" ])
54+ assert result .exit_code == 0
55+ result_dict = json .loads (result .stdout )
56+
57+ assert result_dict == target_dict
58+
59+
60+ def test_is_hinted_schema (data ):
4461 target_model = create_model (
4562 "IsHinted" ,
4663 controller = (SomeConfig , ...),
@@ -56,6 +73,10 @@ def test_is_hinted_schema():
5673
5774 assert result_dict == target_dict
5875
76+ # # store a schema to use for debugging
77+ # with open(data / "schema.json", mode="w") as f:
78+ # json.dump(result_dict, f, indent=2)
79+
5980
6081def test_not_hinted_schema ():
6182 error = (
@@ -78,3 +99,31 @@ def test_over_defined_schema():
7899 with pytest .raises (LaunchError ) as exc_info :
79100 launch (ManyArgs )
80101 assert str (exc_info .value ) == error
102+
103+
104+ def test_launch_minimal (mocker : MockerFixture , data ):
105+ run = mocker .patch ("fastcs.main.FastCS.run" )
106+ gui = mocker .patch ("fastcs.main.FastCS.create_gui" )
107+ docs = mocker .patch ("fastcs.main.FastCS.create_docs" )
108+
109+ app = _launch (SingleArg )
110+ result = runner .invoke (app , ["run" , str (data / "config_minimal.yaml" )])
111+ assert result .exit_code == 0
112+
113+ run .assert_called_once ()
114+ gui .assert_not_called ()
115+ docs .assert_not_called ()
116+
117+
118+ def test_launch_full (mocker : MockerFixture , data ):
119+ run = mocker .patch ("fastcs.main.FastCS.run" )
120+ gui = mocker .patch ("fastcs.main.FastCS.create_gui" )
121+ docs = mocker .patch ("fastcs.main.FastCS.create_docs" )
122+
123+ app = _launch (IsHinted )
124+ result = runner .invoke (app , ["run" , str (data / "config_full.yaml" )])
125+ assert result .exit_code == 0
126+
127+ run .assert_called_once ()
128+ gui .assert_called_once ()
129+ docs .assert_called_once ()
0 commit comments