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 ability for ComposeDescriptor to accept arbitrary kwargs to create descriptor #286

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions event_model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2402,6 +2402,7 @@ def __call__(
time=None,
uid=None,
validate=True,
**kwargs,
Copy link
Contributor

@evalott100 evalott100 Aug 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should handle this the same way as RunStart (without the unpacking in the __call__ kwargs)

metadata: Optional[Dict] = None,

I'm happy to change it to unpacking if others prefer, but I think they should be consistent

) -> ComposeDescriptorBundle:
if time is None:
time = ttime.time()
Expand All @@ -2423,6 +2424,7 @@ def __call__(
time=time,
uid=uid,
hints=hints,
**kwargs,
)
if validate:
if name in self.streams and self.streams[name] != set(data_keys):
Expand Down
22 changes: 21 additions & 1 deletion event_model/tests/test_schema_generation.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
# type: ignore

import sys
from time import time

import pytest

from event_model import ComposeDescriptor
from event_model.documents import RunStart
from event_model.documents.event_descriptor import DataKey

if sys.version_info[:2] >= (3, 9):
# Test schema generation
import json
Expand All @@ -17,7 +22,6 @@
EventDescriptor,
EventPage,
Resource,
RunStart,
RunStop,
StreamDatum,
StreamResource,
Expand Down Expand Up @@ -68,3 +72,19 @@ def test_schema_generation_import_throws_error():
from event_model.documents.generate import typeddict_to_schema

typeddict_to_schema


def test_descriptor_creation_with_metadata():
start = RunStart(time=time(), uid="abcdef")
cd = ComposeDescriptor(start, {}, {})
kwargs = {
"field1": "extra field",
"field2": 123,
"field3": DataKey(source="", shape=[], dtype="array"),
}
bundle = cd(
"primary", {"motor": DataKey(source="", shape=[], dtype="number")}, **kwargs
)

for key, value in kwargs.items():
assert bundle.descriptor_doc.get(key) == value
Loading