Skip to content

Commit 94c7801

Browse files
committed
tried to add test
1 parent 6ecc29e commit 94c7801

File tree

3 files changed

+51
-6
lines changed

3 files changed

+51
-6
lines changed

event_model/documents/event_descriptor.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,16 @@ class Limits(TypedDict):
2323
warning: NotRequired[Annotated[LimitsRange, Field(description="Warning limits.")]]
2424
alarm: NotRequired[Annotated[LimitsRange, Field(description="Alarm limits.")]]
2525

26-
_ConstrainedDtype = Annotated[str, Field(description="A numpy dtype e.g `<U9` `<f16`" ,pattern="[|<>][tbiufcmMOSUV][0-9]+")]
26+
_ConstrainedDtype = Annotated[
27+
str,
28+
Field(
29+
description="A numpy dtype e.g `<U9`, `<f16`",
30+
pattern="[|<>][tbiufcmMOSUV][0-9]+"
31+
)
32+
]
33+
34+
_ConstrainedDtypeNpStructure = Tuple[str, _ConstrainedDtype]
35+
2736
class DataKey(TypedDict):
2837
"""Describes the objects in the data property of Event documents"""
2938

@@ -42,16 +51,26 @@ class DataKey(TypedDict):
4251
]
4352
dtype: Annotated[
4453
Dtype,
45-
Field(description="The type of the data in the event, given as a broad JSON schema type."),
54+
Field(
55+
description=(
56+
"The type of the data in the event, given as a broad "
57+
"JSON schema type."
58+
)
59+
)
4660
]
4761
dtype_numpy: NotRequired[
4862
Annotated[
4963
Union[
5064
_ConstrainedDtype,
51-
List[Tuple[str, _ConstrainedDtype]],
65+
List[
66+
_ConstrainedDtypeNpStructure
67+
]
5268
],
5369
Field(
54-
description="The type of the data in the event, given as a numpy dtype string (or, for structured dtypes, array).",
70+
description=(
71+
"The type of the data in the event, given as a "
72+
"numpy dtype string (or, for structured dtypes, array).",
73+
)
5574
),
5675
]
5776
]

event_model/schemas/event_descriptor.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
"description": "The type of the data in the event, given as a numpy dtype string (or, for structured dtypes, array).",
6666
"anyOf": [
6767
{
68-
"description": "A numpy dtype e.g `<U9` `<f16`",
68+
"description": "A numpy dtype e.g `<U9`, `<f16`",
6969
"pattern": "[|<>][tbiufcmMOSUV][0-9]+",
7070
"type": "string"
7171
},
@@ -78,7 +78,7 @@
7878
"type": "string"
7979
},
8080
{
81-
"description": "A numpy dtype e.g `<U9` `<f16`",
81+
"description": "A numpy dtype e.g `<U9`, `<f16`",
8282
"pattern": "[|<>][tbiufcmMOSUV][0-9]+",
8383
"type": "string"
8484
}

event_model/tests/test_auth.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,29 @@ def test_dots_not_allowed_in_keys():
7373
doc.update({".b": "c"})
7474
with pytest.raises(jsonschema.ValidationError):
7575
schema_validators[DocumentNames.stop].validate(doc)
76+
77+
78+
@pytest.mark.parametrize(
79+
"dtype_numpy", [
80+
"Z",
81+
"i",
82+
"i4",
83+
"4i",
84+
"i>4",
85+
">i",
86+
[("some_str", "Z")],
87+
]
88+
)
89+
def test_bad_numpy_datakeys(dtype_numpy):
90+
descriptor = {
91+
"time": 0,
92+
"uid": new_uid(),
93+
"data_keys": {
94+
"a": {
95+
"source": "", "dtype": "number", "shape": [], "dtype_numpy": dtype_numpy
96+
}
97+
},
98+
"run_start": new_uid(),
99+
}
100+
with pytest.raises(jsonschema.ValidationError):
101+
schema_validators[DocumentNames.descriptor].validate(descriptor)

0 commit comments

Comments
 (0)