-
Notifications
You must be signed in to change notification settings - Fork 3
[WIP] Utilize serialize_as_any instead of Metaclass to adjust annotations #127
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
Open
NeejWeej
wants to merge
2
commits into
main
Choose a base branch
from
nk/serialize_as_any_updates
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| import json | ||
| from datetime import date | ||
|
|
||
| from ccflow import DateContext | ||
| from ccflow.callable import ModelEvaluationContext | ||
| from ccflow.evaluators import GraphEvaluator, LoggingEvaluator, MultiEvaluator | ||
| from ccflow.tests.evaluators.util import NodeModel | ||
|
|
||
| # NOTE: for these tests, round-tripping via JSON does not work | ||
| # because the ModelEvaluationContext just has an InstanceOf validation check | ||
| # and so we do not actually construct a full MEC on load. | ||
|
|
||
|
|
||
| def _make_nested_mec(model): | ||
| ctx = DateContext(date=date(2022, 1, 1)) | ||
| mec = model.__call__.get_evaluation_context(model, ctx) | ||
| assert isinstance(mec, ModelEvaluationContext) | ||
| # ensure nested: outer model is an evaluator, inner is a ModelEvaluationContext | ||
| assert isinstance(mec.context, ModelEvaluationContext) | ||
| return mec | ||
|
|
||
|
|
||
| def test_mec_model_dump_basic(): | ||
| m = NodeModel() | ||
| mec = _make_nested_mec(m) | ||
|
|
||
| d = mec.model_dump() | ||
| assert isinstance(d, dict) | ||
| assert "fn" in d and "model" in d and "context" in d and "options" in d | ||
|
|
||
| s = mec.model_dump_json() | ||
| parsed = json.loads(s) | ||
| assert parsed["fn"] == d["fn"] | ||
| # Also verify mode-specific dumps | ||
| d_py = mec.model_dump(mode="python") | ||
| assert isinstance(d_py, dict) | ||
| d_json = mec.model_dump(mode="json") | ||
| assert isinstance(d_json, dict) | ||
| json.dumps(d_json) | ||
|
|
||
|
|
||
| def test_mec_model_dump_diamond_graph(): | ||
| n0 = NodeModel() | ||
| n1 = NodeModel(deps_model=[n0]) | ||
| n2 = NodeModel(deps_model=[n0]) | ||
| root = NodeModel(deps_model=[n1, n2]) | ||
|
|
||
| mec = _make_nested_mec(root) | ||
|
|
||
| d = mec.model_dump() | ||
| assert isinstance(d, dict) | ||
| assert set(["fn", "model", "context", "options"]).issubset(d.keys()) | ||
|
|
||
| s = mec.model_dump_json() | ||
| json.loads(s) | ||
| # verify mode dumps | ||
| d_py = mec.model_dump(mode="python") | ||
| assert isinstance(d_py, dict) | ||
| d_json = mec.model_dump(mode="json") | ||
| assert isinstance(d_json, dict) | ||
| json.dumps(d_json) | ||
|
|
||
|
|
||
| def test_mec_model_dump_with_multi_evaluator(): | ||
| m = NodeModel() | ||
| _ = LoggingEvaluator() # ensure import/validation | ||
| evaluator = MultiEvaluator(evaluators=[LoggingEvaluator(), GraphEvaluator()]) | ||
|
|
||
| # Simulate how Flow builds evaluation context with a custom evaluator | ||
| ctx = DateContext(date=date(2022, 1, 1)) | ||
| mec = ModelEvaluationContext(model=evaluator, context=m.__call__.get_evaluation_context(m, ctx)) | ||
|
|
||
| d = mec.model_dump() | ||
| assert isinstance(d, dict) | ||
| assert "fn" in d and "model" in d and "context" in d | ||
| s = mec.model_dump_json() | ||
| json.loads(s) | ||
| # verify mode dumps | ||
| d_py = mec.model_dump(mode="python") | ||
| assert isinstance(d_py, dict) | ||
| d_json = mec.model_dump(mode="json") | ||
| assert isinstance(d_json, dict) | ||
| json.dumps(d_json) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.