Skip to content

Commit e129eac

Browse files
authored
Fill out the rest of the metadata test functionality and add publish batch/condition tests (#49)
* Add first few acceptance tests that run against the actual datastore service Signed-off-by: Michael Johansen <michael.johansen@emerson.com> * Add tests for batch publishing Signed-off-by: Michael Johansen <michael.johansen@emerson.com> * More work on metadata tests. Add batch publish tests. Signed-off-by: Michael Johansen <michael.johansen@emerson.com> * Add to the metadata test. Signed-off-by: Michael Johansen <michael.johansen@emerson.com> * Update metadata test to use all greenboxes and extensions. Signed-off-by: Michael Johansen <michael.johansen@emerson.com> * Add tests for Publish Condition Signed-off-by: Michael Johansen <michael.johansen@emerson.com> * Rename test file for consistency Signed-off-by: Michael Johansen <michael.johansen@emerson.com> * Address review feedback. Signed-off-by: Michael Johansen <michael.johansen@emerson.com> --------- Signed-off-by: Michael Johansen <michael.johansen@emerson.com>
1 parent 20c7c3b commit e129eac

7 files changed

+579
-71
lines changed

CONTRIBUTING.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ can also install the Measurement Data Services installer on a test machine. If t
4040
is not running, these tests will fail. To run the acceptance tests, run this command:
4141
`poetry run pytest tests\acceptance`
4242

43+
> Warning! Running the acceptance tests will publish data and metadata to the default global
44+
> MDS data store location in the Documents folder.
45+
4346

4447
# Publishing on PyPI
4548

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
id = "https://acceptancetests.com/custommetadata.schema.toml"
2+
3+
[uut]
4+
u1 = "*"
5+
u2 = "*"
6+
7+
[uut_instance]
8+
ui1 = "*"
9+
ui2 = "*"
10+
11+
[operator]
12+
o1 = "*"
13+
o2 = "*"
14+
15+
[test_station]
16+
ts1 = "*"
17+
ts2 = "*"
18+
19+
[test_description]
20+
td1 = "*"
21+
td2 = "*"
22+
23+
[software_item]
24+
sw1 = "*"
25+
sw2 = "*"
26+
27+
[hardware_item]
28+
hw1 = "*"
29+
hw2 = "*"
30+
31+
[test_result]
32+
tr1 = "*"
33+
tr2 = "*"
34+
35+
[step]
36+
s1 = "*"
37+
s2 = "*"
38+
39+
[test]
40+
t1 = "*"
41+
t2 = "*"
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
"""Acceptance tests that publish various condition values then read the data back."""
2+
3+
from ni.datastore.data import (
4+
DataStoreClient,
5+
Step,
6+
TestResult,
7+
)
8+
from nitypes.scalar import Scalar
9+
from nitypes.vector import Vector
10+
11+
12+
def test___publish_float_condition___read_data_returns_vector() -> None:
13+
with DataStoreClient() as data_store_client:
14+
step_id = _create_step(data_store_client, "float condition")
15+
published_condition = data_store_client.publish_condition(
16+
condition_name="python float condition",
17+
type="Upper Limit",
18+
value=123.45,
19+
step_id=step_id,
20+
)
21+
22+
# A published float will be read back as a Vector.
23+
vector = data_store_client.read_data(published_condition, expected_type=Vector)
24+
assert len(vector) == 1
25+
assert vector[0] == 123.45
26+
assert vector.units == ""
27+
28+
29+
def test___publish_integer_condition___read_data_returns_vector() -> None:
30+
with DataStoreClient() as data_store_client:
31+
step_id = _create_step(data_store_client, "integer condition")
32+
published_condition = data_store_client.publish_condition(
33+
condition_name="python integer condition",
34+
type="Lower Limit",
35+
value=123,
36+
step_id=step_id,
37+
)
38+
39+
# A published integer will be read back as a Vector.
40+
vector = data_store_client.read_data(published_condition, expected_type=Vector)
41+
assert len(vector) == 1
42+
assert vector[0] == 123
43+
assert vector.units == ""
44+
45+
46+
def test___publish_bool_condition___read_data_returns_vector() -> None:
47+
with DataStoreClient() as data_store_client:
48+
step_id = _create_step(data_store_client, "bool condition")
49+
published_condition = data_store_client.publish_condition(
50+
condition_name="python bool condition",
51+
type="Flag",
52+
value=True,
53+
step_id=step_id,
54+
)
55+
56+
# A published bool will be read back as a Vector.
57+
vector = data_store_client.read_data(published_condition, expected_type=Vector)
58+
assert len(vector) == 1
59+
assert vector[0] is True
60+
assert vector.units == ""
61+
62+
63+
def test___publish_str_condition___read_data_returns_vector() -> None:
64+
with DataStoreClient() as data_store_client:
65+
step_id = _create_step(data_store_client, "str condition")
66+
published_condition = data_store_client.publish_condition(
67+
condition_name="python str condition",
68+
type="Environment",
69+
value="condition value",
70+
step_id=step_id,
71+
)
72+
73+
# A published str will be read back as a Vector.
74+
vector = data_store_client.read_data(published_condition, expected_type=Vector)
75+
assert len(vector) == 1
76+
assert vector[0] == "condition value"
77+
assert vector.units == ""
78+
79+
80+
def test___publish_scalar_condition___read_data_returns_vector() -> None:
81+
with DataStoreClient() as data_store_client:
82+
step_id = _create_step(data_store_client, "scalar condition")
83+
expected_scalar = Scalar(value=25, units="Volts")
84+
published_condition = data_store_client.publish_condition(
85+
condition_name="python scalar condition",
86+
type="Lower Limit",
87+
value=expected_scalar,
88+
step_id=step_id,
89+
)
90+
91+
# A published Scalar will be read back as a Vector.
92+
vector = data_store_client.read_data(published_condition, expected_type=Vector)
93+
assert vector[0] == expected_scalar.value
94+
assert vector.units == expected_scalar.units
95+
96+
97+
def _create_step(data_store_client: DataStoreClient, datatype_string: str) -> str:
98+
test_result_name = f"python publish {datatype_string} acceptance test"
99+
test_result = TestResult(test_result_name=test_result_name)
100+
test_result_id = data_store_client.create_test_result(test_result)
101+
102+
# Publish the waveform data
103+
step = Step(step_name=f"Initial step: {datatype_string}", test_result_id=test_result_id)
104+
step_id = data_store_client.create_step(step)
105+
return step_id
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
"""Acceptance tests that publish various batch condition values then read the data back."""
2+
3+
from ni.datastore.data import (
4+
DataStoreClient,
5+
Step,
6+
TestResult,
7+
)
8+
from nitypes.vector import Vector
9+
10+
11+
def test___publish_batch_float_condition___read_data_returns_vector() -> None:
12+
expected_value = [1.0, 2.0, 3.0]
13+
with DataStoreClient() as data_store_client:
14+
step_id = _create_step(data_store_client, "float condition batch")
15+
published_condition = data_store_client.publish_condition_batch(
16+
condition_name="python float condition batch",
17+
type="Upper Limits",
18+
values=expected_value,
19+
step_id=step_id,
20+
)
21+
22+
# A batch published float will be read back as a Vector.
23+
vector = data_store_client.read_data(published_condition, expected_type=Vector)
24+
assert vector._values == expected_value
25+
assert vector.units == ""
26+
27+
28+
def test___publish_batch_integer_condition___read_data_returns_vector() -> None:
29+
expected_value = [5, 6, 7, 8]
30+
with DataStoreClient() as data_store_client:
31+
step_id = _create_step(data_store_client, "integer condition batch")
32+
published_condition = data_store_client.publish_condition_batch(
33+
condition_name="python integer condition batch",
34+
type="Lower Limits",
35+
values=expected_value,
36+
step_id=step_id,
37+
)
38+
39+
# A batch published integer will be read back as a Vector.
40+
vector = data_store_client.read_data(published_condition, expected_type=Vector)
41+
assert vector._values == expected_value
42+
assert vector.units == ""
43+
44+
45+
def test___publish_batch_bool_condition___read_data_returns_vector() -> None:
46+
expected_value = [True, False, True]
47+
with DataStoreClient() as data_store_client:
48+
step_id = _create_step(data_store_client, "bool condition batch")
49+
published_condition = data_store_client.publish_condition_batch(
50+
condition_name="python bool condition batch",
51+
type="Flags",
52+
values=expected_value,
53+
step_id=step_id,
54+
)
55+
56+
# A batch published bool will be read back as a Vector.
57+
vector = data_store_client.read_data(published_condition, expected_type=Vector)
58+
assert vector._values == expected_value
59+
assert vector.units == ""
60+
61+
62+
def test___publish_batch_str_condition___read_data_returns_vector() -> None:
63+
expected_value = ["one", "two", "three"]
64+
with DataStoreClient() as data_store_client:
65+
step_id = _create_step(data_store_client, "str condition batch")
66+
published_condition = data_store_client.publish_condition_batch(
67+
condition_name="python str condition batch",
68+
type="Environments",
69+
values=expected_value,
70+
step_id=step_id,
71+
)
72+
73+
# A published str will be read back as a Vector.
74+
vector = data_store_client.read_data(published_condition, expected_type=Vector)
75+
assert vector._values == expected_value
76+
assert vector.units == ""
77+
78+
79+
def test___publish_batch_vector_condition___read_data_returns_vector() -> None:
80+
with DataStoreClient() as data_store_client:
81+
step_id = _create_step(data_store_client, "scalar condition batch")
82+
expected_vector = Vector(values=[25, 50, 75], units="Amps")
83+
published_condition = data_store_client.publish_condition_batch(
84+
condition_name="python vector condition batch",
85+
type="Upper Limit",
86+
values=expected_vector,
87+
step_id=step_id,
88+
)
89+
90+
# A batch published Vector will be read back as a Vector.
91+
vector = data_store_client.read_data(published_condition, expected_type=Vector)
92+
assert vector == expected_vector
93+
94+
95+
def _create_step(data_store_client: DataStoreClient, datatype_string: str) -> str:
96+
test_result_name = f"python publish {datatype_string} acceptance test"
97+
test_result = TestResult(test_result_name=test_result_name)
98+
test_result_id = data_store_client.create_test_result(test_result)
99+
100+
# Publish the waveform data
101+
step = Step(step_name=f"Initial step: {datatype_string}", test_result_id=test_result_id)
102+
step_id = data_store_client.create_step(step)
103+
return step_id

tests/acceptance/test_publish_measurement_and_read_data.py

Lines changed: 7 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import numpy as np
44
from ni.datastore.data import (
55
DataStoreClient,
6-
PublishedMeasurement,
76
Step,
87
TestResult,
98
)
@@ -22,12 +21,8 @@ def test___publish_float___read_data_returns_vector() -> None:
2221
step_id=step_id,
2322
)
2423

25-
found_measurement = _get_first_measurement(
26-
data_store_client, published_measurement.published_measurement_id
27-
)
28-
2924
# A published integer will be read back as a Vector.
30-
vector = data_store_client.read_data(found_measurement, expected_type=Vector)
25+
vector = data_store_client.read_data(published_measurement, expected_type=Vector)
3126
assert vector[0] == 123.45
3227
assert vector.units == ""
3328

@@ -42,12 +37,8 @@ def test___publish_scalar___read_data_returns_vector() -> None:
4237
step_id=step_id,
4338
)
4439

45-
found_measurement = _get_first_measurement(
46-
data_store_client, published_measurement.published_measurement_id
47-
)
48-
4940
# A published Scalar will be read back as a Vector.
50-
vector = data_store_client.read_data(found_measurement, expected_type=Vector)
41+
vector = data_store_client.read_data(published_measurement, expected_type=Vector)
5142
assert vector[0] == expected_scalar.value
5243
assert vector.units == expected_scalar.units
5344

@@ -68,10 +59,7 @@ def test___publish_xydata___read_data_returns_xydata() -> None:
6859
step_id=step_id,
6960
)
7061

71-
found_measurement = _get_first_measurement(
72-
data_store_client, published_measurement.published_measurement_id
73-
)
74-
xydata = data_store_client.read_data(found_measurement, expected_type=XYData)
62+
xydata = data_store_client.read_data(published_measurement, expected_type=XYData)
7563
assert xydata == expected_xydata
7664

7765

@@ -91,10 +79,7 @@ def test___publish_spectrum___read_data_returns_spectrum() -> None:
9179
step_id=step_id,
9280
)
9381

94-
found_measurement = _get_first_measurement(
95-
data_store_client, published_measurement.published_measurement_id
96-
)
97-
spectrum = data_store_client.read_data(found_measurement, expected_type=Spectrum)
82+
spectrum = data_store_client.read_data(published_measurement, expected_type=Spectrum)
9883
assert spectrum == expected_spectrum
9984

10085

@@ -112,10 +97,7 @@ def test___publish_analog_waveform___read_data_returns_analog_waveform() -> None
11297
step_id=step_id,
11398
)
11499

115-
found_measurement = _get_first_measurement(
116-
data_store_client, published_measurement.published_measurement_id
117-
)
118-
waveform = data_store_client.read_data(found_measurement, expected_type=AnalogWaveform)
100+
waveform = data_store_client.read_data(published_measurement, expected_type=AnalogWaveform)
119101
assert waveform == expected_waveform
120102

121103

@@ -129,10 +111,7 @@ def test___publish_digital_waveform___read_data_returns_digital_waveform() -> No
129111
step_id=step_id,
130112
)
131113

132-
found_measurement = _get_first_measurement(
133-
data_store_client, published_measurement.published_measurement_id
134-
)
135-
waveform = data_store_client.read_data(found_measurement, expected_type=DigitalWaveform)
114+
waveform = data_store_client.read_data(published_measurement, expected_type=DigitalWaveform)
136115
assert waveform == expected_waveform
137116

138117

@@ -146,10 +125,7 @@ def test___publish_complex_waveform___read_data_returns_complex_waveform() -> No
146125
step_id=step_id,
147126
)
148127

149-
found_measurement = _get_first_measurement(
150-
data_store_client, published_measurement.published_measurement_id
151-
)
152-
waveform = data_store_client.read_data(found_measurement, expected_type=ComplexWaveform)
128+
waveform = data_store_client.read_data(published_measurement, expected_type=ComplexWaveform)
153129
assert waveform == expected_waveform
154130

155131

@@ -162,15 +138,3 @@ def _create_step(data_store_client: DataStoreClient, datatype_string: str) -> st
162138
step = Step(step_name=f"Initial step: {datatype_string}", test_result_id=test_result_id)
163139
step_id = data_store_client.create_step(step)
164140
return step_id
165-
166-
167-
def _get_first_measurement(
168-
data_store_client: DataStoreClient, published_measurement_id: str
169-
) -> PublishedMeasurement:
170-
# Query for the measurement id and read/validate data
171-
published_measurements = data_store_client.query_measurements(
172-
odata_query=f"$filter=id eq {published_measurement_id}"
173-
)
174-
found_measurement = next(iter(published_measurements), None)
175-
assert found_measurement is not None
176-
return found_measurement

0 commit comments

Comments
 (0)