Skip to content
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

Merged

Conversation

WilliamJamieson
Copy link
Contributor

@WilliamJamieson WilliamJamieson commented Jun 2, 2023

When developing tests in romancal it was a little annoying to construct the datamodel you needed, as the maker_utils/testing.factories all construct the stnode objects, not the actual datamodels themselves.

This PR provides a convenience function (maker_utils.mk_datamodel) to do this for you. For any datamodel type (in the MODEL_REGISTRY) it automatically grabs the correct maker_util and then uses the it to construct data which it then feeds into the datamodel class to construct a full fledged datamodel of the desired type.

For example if one wants a RampModel the following will construct a RampModel filled with dummy data:

from roman_datamodels.datamodels import RampModel
from roman_datamodels.maker_utils import mk_datamodel

model = mk_datamodel(RampModel)

Note that this is based on #193 and so it will remain a draft for now.

Checklist

Comment on lines +51 to +67
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))
Copy link
Contributor Author

@WilliamJamieson WilliamJamieson Jun 2, 2023

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.

@codecov
Copy link

codecov bot commented Jun 2, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.10 🎉

Comparison is base (4a8f808) 97.84% compared to head (26c45e5) 97.94%.

❗ Current head 26c45e5 differs from pull request most recent head e2d3f86. Consider uploading reports for the commit e2d3f86 to get more accurate results

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              
Impacted Files Coverage Δ
tests/test_maker_utils.py 97.82% <100.00%> (+0.26%) ⬆️
tests/test_models.py 98.32% <100.00%> (ø)

... and 2 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@WilliamJamieson WilliamJamieson force-pushed the feature/datamodel_makers branch 6 times, most recently from f111e52 to 26c45e5 Compare June 6, 2023 19:36
@WilliamJamieson WilliamJamieson marked this pull request as ready for review June 6, 2023 19:37
@WilliamJamieson WilliamJamieson requested a review from a team as a code owner June 6, 2023 19:37
Copy link
Collaborator

@PaulHuwe PaulHuwe left a 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

@WilliamJamieson WilliamJamieson enabled auto-merge (squash) June 6, 2023 20:20
@WilliamJamieson WilliamJamieson merged commit fded05d into spacetelescope:main Jun 6, 2023
@WilliamJamieson WilliamJamieson deleted the feature/datamodel_makers branch June 6, 2023 20:33
mairanteodoro pushed a commit to mairanteodoro/roman_datamodels that referenced this pull request Jun 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants