@@ -19,6 +19,14 @@ def modify(self, prop: schema.Property):
1919 prop .name = self .name .rstrip ("_" )
2020
2121
22+ def _get_name (x : typing .Optional [typing .Union [str , type ]]):
23+ if x is None :
24+ return None
25+ if isinstance (x , str ):
26+ return x
27+ return x .__name__
28+
29+
2230def _get_class (cls : type ) -> schema .Class :
2331 if not isinstance (cls , type ):
2432 raise schema .Error (f"Only class definitions allowed in schema, found { cls } " )
@@ -38,6 +46,7 @@ def _get_class(cls: type) -> schema.Class:
3846 # getattr to inherit from bases
3947 group = getattr (cls , "_group" , "" ),
4048 hideable = getattr (cls , "_hideable" , False ),
49+ test_with = _get_name (getattr (cls , "_test_with" , None )),
4150 # in the following we don't use `getattr` to avoid inheriting
4251 pragmas = cls .__dict__ .get ("_pragmas" , []),
4352 synth = cls .__dict__ .get ("_synth" , None ),
@@ -107,6 +116,13 @@ def _fill_hideable_information(classes: typing.Dict[str, schema.Class]):
107116 todo .append (supercls )
108117
109118
119+ def _check_test_with (classes : typing .Dict [str , schema .Class ]):
120+ for cls in classes .values ():
121+ if cls .test_with is not None and classes [cls .test_with ].test_with is not None :
122+ raise schema .Error (f"{ cls .name } has test_with { cls .test_with } which in turn "
123+ f"has test_with { classes [cls .test_with ].test_with } , use that directly" )
124+
125+
110126def load (m : types .ModuleType ) -> schema .Schema :
111127 includes = set ()
112128 classes = {}
@@ -136,6 +152,7 @@ def load(m: types.ModuleType) -> schema.Schema:
136152
137153 _fill_synth_information (classes )
138154 _fill_hideable_information (classes )
155+ _check_test_with (classes )
139156
140157 return schema .Schema (includes = includes , classes = _toposort_classes_by_group (classes ), null = null )
141158
0 commit comments