Skip to content

Commit cd126d1

Browse files
committed
test(core)(measurement): Simplified tests in test_experiment.py for saving too fast test cases to: use repeat scan for fastest subsequent experiments, only run expts 3 times, ensure the time stamp is the same for all three, ensure that the names are incremented as expected, and ensure that the file names are the same.
1 parent be625fc commit cd126d1

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

test/measurement/test_experiment.py

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import shutil
99
import numpy as np
1010
import pytest
11+
import re
12+
import os
1113

1214

1315
##################### FUNCTIONS USED BY TEST CASES #####################
@@ -1121,21 +1123,33 @@ def get_voltage_data(expt):
11211123

11221124
# Create RunInfo instance and set scan0 to PropertyScan
11231125
runinfo = ps.RunInfo()
1124-
runinfo.scan0 = ps.PropertyScan({'v1': ps.drange(0, 0.1, 1)}, prop='voltage', dt=0.000000001)
1126+
runinfo.scan0 = ps.RepeatScan(1, dt=0.0000001)
11251127

11261128
# Set RunInfo measure_function (remember, it takes a Experiment object as a parameter and
11271129
# returns an ItemAttribute containing data).
11281130
runinfo.measure_function = get_voltage_data
11291131

11301132
# Create a Experiment class with the RunInfo and Devices just created
11311133
expt = ps.Experiment(runinfo, devices, time=True)
1132-
try:
1133-
expt.run()
1134-
expt.run()
1135-
expt.run()
1136-
expt.run()
1137-
expt.run()
1138-
expt.run()
1134+
1135+
long_names = []
1136+
1137+
while len(long_names) < 3:
11391138
expt.run()
1140-
except Exception:
1141-
assert False, f"Fast experiments did not run properly, possible file name overlap. Exception: {Exception}"
1139+
if len(long_names) == 0:
1140+
long_names.append(expt.runinfo.long_name)
1141+
elif (expt.runinfo.long_name[:15] == long_names[0][:15]):
1142+
long_names.append(expt.runinfo.long_name)
1143+
else:
1144+
long_names = [expt.runinfo.long_name]
1145+
1146+
err_str = f"First long name '{long_names[0]}' does not match expected date/time format."
1147+
assert re.match(r'^\d{8}T\d{6}$', long_names[0]), err_str
1148+
err_str = f"-1 long name '{long_names[1]}' does not match expected increment or format."
1149+
assert long_names[1] == long_names[0] + '-1', err_str
1150+
err_str = f"-2 long name '{long_names[1]}' does not match expected increment or format."
1151+
assert long_names[2] == long_names[0] + '-2', err_str
1152+
1153+
for name in long_names:
1154+
save_path = expt.runinfo.data_path / '{}.hdf5'.format(name)
1155+
assert os.path.exists(save_path), f"Expected file at path'{save_path}' was not found."

0 commit comments

Comments
 (0)