11import unittest
2+ from typing import Any
23
34import pytest
45
5- from chartlets .callback import Input , Callback , Output
6+ from chartlets .channel import Input , State , Output
7+ from chartlets .callback import Callback
68
79
810# noinspection PyUnusedLocal
@@ -13,6 +15,7 @@ def my_callback(
1315 b : str | int = "" ,
1416 c : bool | None = False ,
1517 d : list [str ] = (),
18+ e : dict [str , Any ] = (),
1619) -> str :
1720 return f"{ a } -{ b } -{ c } -{ d } "
1821
@@ -31,7 +34,9 @@ def test_make_function_args(self):
3134
3235 def test_to_dict_with_no_outputs (self ):
3336 callback = Callback (
34- my_callback , [Input ("a" ), Input ("b" ), Input ("c" ), Input ("d" )], []
37+ my_callback ,
38+ [Input ("a" ), Input ("b" ), Input ("c" ), Input ("d" ), State ("e" )],
39+ [],
3540 )
3641 d = callback .to_dict ()
3742 # print(json.dumps(d, indent=2))
@@ -44,38 +49,32 @@ def test_to_dict_with_no_outputs(self):
4449 {
4550 "default" : "" ,
4651 "name" : "b" ,
47- "type" : {"type" : [{ "type" : " string"}, { "type" : " integer"} ]},
52+ "type" : {"type" : [" string", " integer" ]},
4853 },
4954 {
5055 "default" : False ,
5156 "name" : "c" ,
52- "type" : {"type" : [{ "type" : " boolean"}, { "type" : " null"} ]},
57+ "type" : {"type" : [" boolean", " null" ]},
5358 },
5459 {
5560 "default" : (),
5661 "name" : "d" ,
5762 "type" : {"items" : {"type" : "string" }, "type" : "array" },
5863 },
64+ {
65+ "default" : (),
66+ "name" : "e" ,
67+ "type" : {"additionalProperties" : {}, "type" : "object" },
68+ },
5969 ],
6070 "returnType" : {"type" : "string" },
6171 },
6272 "inputs" : [
63- {
64- "id" : "a" ,
65- "property" : "value" ,
66- },
67- {
68- "id" : "b" ,
69- "property" : "value" ,
70- },
71- {
72- "id" : "c" ,
73- "property" : "value" ,
74- },
75- {
76- "id" : "d" ,
77- "property" : "value" ,
78- },
73+ {"id" : "a" , "property" : "value" },
74+ {"id" : "b" , "property" : "value" },
75+ {"id" : "c" , "property" : "value" },
76+ {"id" : "d" , "property" : "value" },
77+ {"id" : "e" , "noTrigger" : True , "property" : "value" },
7978 ],
8079 },
8180 d ,
@@ -100,26 +99,15 @@ def test_to_dict_with_two_outputs(self):
10099 "returnType" : {
101100 "items" : [
102101 {"items" : {"type" : "string" }, "type" : "array" },
103- {"type" : [{ "type" : " string"}, { "type" : " null"} ]},
102+ {"type" : [" string", " null" ]},
104103 ],
105104 "type" : "array" ,
106105 },
107106 },
108- "inputs" : [
109- {
110- "id" : "n" ,
111- "property" : "value" ,
112- }
113- ],
107+ "inputs" : [{"id" : "n" , "property" : "value" }],
114108 "outputs" : [
115- {
116- "id" : "select" ,
117- "property" : "options" ,
118- },
119- {
120- "id" : "select" ,
121- "property" : "value" ,
122- },
109+ {"id" : "select" , "property" : "options" },
110+ {"id" : "select" , "property" : "value" },
123111 ],
124112 },
125113 d ,
@@ -133,18 +121,18 @@ def test_too_few_inputs(self):
133121 with pytest .raises (
134122 TypeError ,
135123 match = "too few inputs in decorator 'test' for function"
136- " 'my_callback': expected 4 , but got 0" ,
124+ " 'my_callback': expected 5 , but got 0" ,
137125 ):
138126 Callback .from_decorator ("test" , (), my_callback )
139127
140128 def test_too_many_inputs (self ):
141129 with pytest .raises (
142130 TypeError ,
143131 match = "too many inputs in decorator 'test' for function"
144- " 'my_callback': expected 4 , but got 5 " ,
132+ " 'my_callback': expected 5 , but got 7 " ,
145133 ):
146134 Callback .from_decorator (
147- "test" , tuple (Input (c ) for c in "abcde " ), my_callback
135+ "test" , tuple (Input (c ) for c in "abcdefg " ), my_callback
148136 )
149137
150138 def test_decorator_target (self ):
0 commit comments