-
Notifications
You must be signed in to change notification settings - Fork 9
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
Update References with pointer to target object #34
Conversation
I just realized I didn't write any tests for this. I understand if you want to hold off accepting this until I get around to that. |
Codecov Report
@@ Coverage Diff @@
## master #34 +/- ##
==========================================
- Coverage 95.20% 95.13% -0.07%
==========================================
Files 1 1
Lines 396 473 +77
==========================================
+ Hits 377 450 +73
- Misses 19 23 +4
Continue to review full report at Codecov.
|
just noticing that we're building a fair amount of string literals in #ome_types/model/ome.py
from ome_types._model.ome import OME as _OME
class OME(_OME):
def __post_init_post_parse__(self: Any, *args: Any) -> None:
ids = collect_ids(self)
references = collect_references(self)
for ref_id, ref in references.items():
ref.ref_ = weakref.ref(ids[ref_id]) thoughts? |
Good idea. Or maybe the reverse, where the bases are committed and the
generated classes extend those. Another option might be to write “loose”
functions in a committed module and bind them to the classes rather than
using inheritance. We’ll have to see which works best.
|
What do you think about this PR as it stands? Maybe I add some tests and if you're happy with the API and approach we can merge it, and the next PR will work on moving all this fixed code into a separate module. |
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.
sorry for the delay, I'm happy working with this approach. Couple basic tests would be good and then we can merge
just tried to write a very basic test for this: def test_collect_ref(model):
from ome_types import from_xml
from ome_types.util import collect_references
ome = from_xml(TESTING_DIR / "data" / "filter.ome.xml", model.OME)
expected = {
"Dichroic:1",
"Filter:5",
"Filter:1",
"Filter:Dichroic:2",
"FilterSet:2",
"Filter:6",
"Instrument:0",
"Objective:0:0",
"Filter:2",
"Filter:3",
"Filter:4",
}
assert set(collect_references(ome)) == expected that "expected" set is what I get when I run that exact code interactively... but for some reason when I run it in the test, |
The |
ah, ok. thanks, will see what I can do to clean up that testing arrangement. |
since most of the testing difficulty here is unrelated to this PR, and has more to do with the way I setup testing a dynamically generated import, it's fine with me if you want to just merge this PR when you're happy with it, and we can create an issue to add tests later |
Adds a
.ref
to allReference
subclasses that returns the referenced modelobject. There is an underlying
ref_
field to support this that is only filledin by the root
OME
object's constructor. A future API addition will becreated to support proper creation of References.
Closes #27