Closed tuopuu closed 7 years ago
@stefanoborini , @mehdisadeghi any comments / quick workarounds to this?
I need to be able to read the shapes to recreate CUDSComponents from yaml files, and also to write proper test cases for yaml serialisation methods.
If you are setting a condition, you know what type it must be. If you parse the yaml file, get the info for the condition, and stuff it in, it should raise an exception and if so, the yaml is corrupted.
Yes, I'll get an exception if I'm trying to set a condition with data that not exactly in a correct shape and type. That is good enough in the case when the model is read from yaml file back to SimPhoNy, and the yaml file itself has some issues (for instance, an unsupported change made by the user).
However, I need to write a test for the serialisation methods that generates a complicated model, that has all currently defined CUDSComponents (with complicated subcomponent references) in it, and stores/load that to/from a yaml file. In order to do it, I need to dynamically generate CUDSComponents which requires shape information on their required/supported parameters. I have two complicated solutions in mind which I'm not happy with: 1) Read through the metadata and extract the shape information from there. 2) use try/exception blocks to guess the correct shape for each parameter of the components.
I'd like to have a method for each generated class that returns the shape of the parameters. We could modify the supported_parameters method so that instead of a list it would return a dictionary that has the shape information as values.
Can't you generate a complicated one once and for all? Why do you need to create it procedurally?
Because new Cuba-keys are constantly added and these need to be tested as well...
When a new key is added, a test for that key is added as well. You are proposing to modify the code specifically to accommodate a need that is exclusively for the test.
Yes, this is a use case. Admittedly it sounds kind of irrelevant, but a good thing with it is that having a generated test model for serialisation helps future development so that people don't have to touch serialisation code when adding new keys.
If you think it's too much work or unnecessary with only this use case, we could leave the serialisation tests incomplete so that only simple cases are tested, or that I could exclude certain keys from the tests that are failing right now (because of no shape information available). What do you think?
Without something like traits, I wouldn't know where to put this information without polluting every individual class with a method that provides this information, plus a global method that provides the information about the cuba types.
In fact I think shape information should be in the generated class docstrings, which are essentially absent at this point anyway. It could be extracted from there easily, and it would provide information about the class for the user. However, automatically generating docstrings would be another mess... ;)
I'll go with imcomplete tests.
Shape information of the supported and required parameters should be easily accessible from the generated classes. For instance,
Box
class has a supported parametercondition
that has a shape(3)
. Currently it cannot be read from anywhere else than metadata itself.