Skip to content

Commit

Permalink
tried to add test
Browse files Browse the repository at this point in the history
  • Loading branch information
evalott100 committed Sep 30, 2024
1 parent 6ecc29e commit 5012385
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
13 changes: 11 additions & 2 deletions event_model/documents/event_descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@ class Limits(TypedDict):
warning: NotRequired[Annotated[LimitsRange, Field(description="Warning limits.")]]
alarm: NotRequired[Annotated[LimitsRange, Field(description="Alarm limits.")]]

_ConstrainedDtype = Annotated[str, Field(description="A numpy dtype e.g `<U9` `<f16`" ,pattern="[|<>][tbiufcmMOSUV][0-9]+")]
_ConstrainedDtype = Annotated[
str,
Field(
description="A numpy dtype e.g `<U9`, `<f16`",
pattern="[|<>][tbiufcmMOSUV][0-9]+"
)
]
_ConstrainedDtypeNpStructure = Tuple[str, _ConstrainedDtype]
class DataKey(TypedDict):
"""Describes the objects in the data property of Event documents"""

Expand All @@ -48,7 +55,9 @@ class DataKey(TypedDict):
Annotated[
Union[
_ConstrainedDtype,
List[Tuple[str, _ConstrainedDtype]],
List[
_ConstrainedDtypeNpStructure
]
],
Field(
description="The type of the data in the event, given as a numpy dtype string (or, for structured dtypes, array).",
Expand Down
4 changes: 2 additions & 2 deletions event_model/schemas/event_descriptor.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"description": "The type of the data in the event, given as a numpy dtype string (or, for structured dtypes, array).",
"anyOf": [
{
"description": "A numpy dtype e.g `<U9` `<f16`",
"description": "A numpy dtype e.g `<U9`, `<f16`",
"pattern": "[|<>][tbiufcmMOSUV][0-9]+",
"type": "string"
},
Expand All @@ -78,7 +78,7 @@
"type": "string"
},
{
"description": "A numpy dtype e.g `<U9` `<f16`",
"description": "A numpy dtype e.g `<U9`, `<f16`",
"pattern": "[|<>][tbiufcmMOSUV][0-9]+",
"type": "string"
}
Expand Down
26 changes: 26 additions & 0 deletions event_model/tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,29 @@ def test_dots_not_allowed_in_keys():
doc.update({".b": "c"})
with pytest.raises(jsonschema.ValidationError):
schema_validators[DocumentNames.stop].validate(doc)


@pytest.mark.parametrize(
"dtype_numpy", [
"Z",
"i",
"i4",
"4i",
"i>4",
">i",
[("some_str", "Z")],
]
)
def test_bad_numpy_datakeys(dtype_numpy):
descriptor = {
"time": 0,
"uid": new_uid(),
"data_keys": {
"a": {
"source": "", "dtype": "number", "shape": [], "dtype_numpy": dtype_numpy
}
},
"run_start": new_uid(),
}
with pytest.raises(jsonschema.ValidationError):
schema_validators[DocumentNames.descriptor].validate(descriptor)

0 comments on commit 5012385

Please sign in to comment.