11import inspect
22
33from unittest import TestCase
4- import _models # type: ignore # did not set types for this
4+ import tableauserverclient . models as TSC_models # type: ignore # did not set types for this
55import tableauserverclient as TSC
66
77from typing import Any
88
99
10- # ensure that all models that don't need parameters can be instantiated
11- # todo....
10+ # ensure that all models can be instantiated
1211def instantiate_class (name : str , obj : Any ):
1312 # Get the constructor (init) of the class
1413 constructor = getattr (obj , "__init__" , None )
@@ -31,14 +30,38 @@ def instantiate_class(name: str, obj: Any):
3130 print (f"Class '{ name } ' does not have a constructor (__init__ method)." )
3231
3332
33+ not_yet_done = [
34+ "DQWItem" ,
35+ "UnpopulatedPropertyError" ,
36+ "FavoriteItem" ,
37+ "FileuploadItem" ,
38+ "FlowRunItem" ,
39+ "IntervalItem" ,
40+ "LinkedTaskItem" ,
41+ "LinkedTaskStepItem" ,
42+ "LinkedTaskFlowRunItem" ,
43+ "Permission" ,
44+ "SiteAuthConfiguration" ,
45+ "Resource" ,
46+ "TagItem" ,
47+ "ExtractItem" ,
48+ ]
49+
50+
3451class TestAllModels (TestCase ):
35- # not all models have __repr__ yet: see above list
52+
53+ # confirm that all models can be instantiated without params, and have __repr__ implemented
54+ # not all do have __repr__ yet: see above list 'not_yet_done'
3655 def test_repr_is_implemented (self ):
37- m = _models .get_defined_models ()
38- for model in m :
39- with self .subTest (model .__name__ , model = model ):
40- print (model .__name__ , type (model .__repr__ ).__name__ )
41- self .assertEqual (type (model .__repr__ ).__name__ , "function" )
56+ m = TSC_models
57+ for type_name in m .__dict__ :
58+ if type_name in not_yet_done :
59+ continue
60+ model = getattr (m , type_name )
61+ if inspect .isclass (model ):
62+ with self .subTest (type_name ):
63+ self .assertTrue (hasattr (model , "__repr__" ))
64+ self .assertEqual (type (model .__repr__ ).__name__ , "function" )
4265
4366 # 2 - Iterate through the objects in the module
4467 def test_by_reflection (self ):
0 commit comments