|
8 | 8 | import shutil |
9 | 9 | import numpy as np |
10 | 10 | import pytest |
| 11 | +import re |
| 12 | +import os |
11 | 13 |
|
12 | 14 |
|
13 | 15 | ##################### FUNCTIONS USED BY TEST CASES ##################### |
@@ -1093,3 +1095,61 @@ def check_load_expt(temp): |
1093 | 1095 | check_load_expt(temp) |
1094 | 1096 |
|
1095 | 1097 | shutil.rmtree('./backup') |
| 1098 | + |
| 1099 | + |
| 1100 | +def test_fast_experiments(): |
| 1101 | + devices = ps.ItemAttribute() |
| 1102 | + |
| 1103 | + devices.v1 = ps.TestVoltage() # Device 1 |
| 1104 | + devices.v2 = ps.TestVoltage() # Device 2 |
| 1105 | + devices.v3 = ps.TestVoltage() # Device 3 |
| 1106 | + |
| 1107 | + def get_voltage_data(expt): |
| 1108 | + """ |
| 1109 | + Reads the voltage from v1, v2, and v3 devices. Also adds a calculated value vsum. |
| 1110 | + """ |
| 1111 | + |
| 1112 | + devices = expt.devices |
| 1113 | + |
| 1114 | + d = ps.ItemAttribute() |
| 1115 | + |
| 1116 | + d.v1_readout = devices.v1.voltage |
| 1117 | + d.v2_readout = devices.v2.voltage |
| 1118 | + d.v3_readout = devices.v3.voltage |
| 1119 | + |
| 1120 | + d.vsum = d.v1_readout + d.v2_readout + d.v3_readout |
| 1121 | + |
| 1122 | + return d |
| 1123 | + |
| 1124 | + # Create RunInfo instance and set scan0 to PropertyScan |
| 1125 | + runinfo = ps.RunInfo() |
| 1126 | + runinfo.scan0 = ps.RepeatScan(1, dt=0.0000001) |
| 1127 | + |
| 1128 | + # Set RunInfo measure_function (remember, it takes a Experiment object as a parameter and |
| 1129 | + # returns an ItemAttribute containing data). |
| 1130 | + runinfo.measure_function = get_voltage_data |
| 1131 | + |
| 1132 | + # Create a Experiment class with the RunInfo and Devices just created |
| 1133 | + expt = ps.Experiment(runinfo, devices, time=True) |
| 1134 | + |
| 1135 | + long_names = [] |
| 1136 | + |
| 1137 | + while len(long_names) < 3: |
| 1138 | + expt.run() |
| 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