-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add datamodel
maker
#198
Add datamodel
maker
#198
Conversation
def mk_datamodel(model_class, **kwargs): | ||
""" | ||
Create a dummy datamodel of the specified class with valid values | ||
for all attributes required by the schema. | ||
|
||
Parameters | ||
---------- | ||
model_class : type | ||
One of the datamodel subclasses from datamodel | ||
**kwargs | ||
Additional or overridden attributes. | ||
|
||
Returns | ||
------- | ||
`roman_datamodels.datamodels.Datamodel` | ||
""" | ||
return model_class(mk_node(NODE_REGISTRY[model_class], **kwargs)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the actual magic of this whole PR. This will automatically pick up any new Datamodels
added to the MODEL_REGISTRY
with no additional developer input outside of providing a maker_utils
function for the stnode
structure, which the other tests require them to do.
3e59cd5
to
d43c056
Compare
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #198 +/- ##
==========================================
+ Coverage 97.84% 97.94% +0.10%
==========================================
Files 8 9 +1
Lines 1204 1263 +59
==========================================
+ Hits 1178 1237 +59
Misses 26 26
☔ View full report in Codecov by Sentry. |
f111e52
to
26c45e5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - like this addition
It is a constant, so it should be in all caps per pep8
26c45e5
to
e2d3f86
Compare
When developing tests in
romancal
it was a little annoying to construct thedatamodel
you needed, as themaker_utils
/testing.factories
all construct thestnode
objects, not the actualdatamodels
themselves.This PR provides a convenience function (
maker_utils.mk_datamodel
) to do this for you. For anydatamodel
type
(in theMODEL_REGISTRY
) it automatically grabs the correctmaker_util
and then uses the it to construct data which it then feeds into thedatamodel
class to construct a full fledgeddatamodel
of the desired type.For example if one wants a
RampModel
the following will construct aRampModel
filled with dummy data:Note that this is based on #193 and so it will remain a draft for now.
Checklist
CHANGES.rst
under the corresponding subsection