44import time
55
66import pytest
7- from pioreactor .background_jobs .led_control import LEDController
87from pioreactor .exc import CalibrationError
98from pioreactor .utils import local_intermittent_storage
109from pioreactor .utils import local_persistent_storage
1110from pioreactor .utils .timing import current_utc_timestamp
1211from pioreactor .whoami import get_unit_name
1312
13+ from .calibrated_light_dark_cycle import CalibratedLightDarkCycle
1414from .led_calibration import LEDCalibration
1515
1616
@@ -22,16 +22,15 @@ def test_led_fails_if_calibration_not_present():
2222 experiment = "test_led_fails_if_calibration_not_present"
2323 unit = get_unit_name ()
2424
25- with local_persistent_storage ("current_led_calibration " ) as cache :
26- if "C " in cache :
27- del cache ["C " ]
28- if "D " in cache :
29- del cache ["D " ]
25+ with local_persistent_storage ("active_calibrations " ) as cache :
26+ if "led_C " in cache :
27+ del cache ["led_C " ]
28+ if "led_D " in cache :
29+ del cache ["led_D " ]
3030
3131 with pytest .raises (CalibrationError ):
3232
33- with LEDController (
34- "calibrated_light_dark_cycle" ,
33+ with CalibratedLightDarkCycle (
3534 duration = 0.01 ,
3635 light_intensity = - 1 ,
3736 light_duration_hours = 16 ,
@@ -49,8 +48,8 @@ def test_set_intensity_au_above_max() -> None:
4948
5049 cal = LEDCalibration (
5150 created_at = current_utc_timestamp (),
52- pioreactor_unit = unit ,
53- name = experiment ,
51+ calibrated_on_pioreactor_unit = unit ,
52+ calibration_name = experiment ,
5453 curve_data_ = [1 , 0 ],
5554 curve_type = "poly" ,
5655 recorded_data = {"x" : [0 , 1 ], "y" : [0 , 1 ]},
@@ -60,8 +59,7 @@ def test_set_intensity_au_above_max() -> None:
6059 cal .set_as_active_calibration_for_device ("led_C" )
6160 cal .set_as_active_calibration_for_device ("led_D" )
6261
63- with LEDController (
64- "calibrated_light_dark_cycle" ,
62+ with CalibratedLightDarkCycle (
6563 duration = 0.01 ,
6664 light_intensity = 1500 ,
6765 light_duration_hours = 16 ,
@@ -70,11 +68,11 @@ def test_set_intensity_au_above_max() -> None:
7068 experiment = experiment ,
7169 ) as lc :
7270
73- assert lc .automation_job . light_intensity == 1500 # test returns light_intensity (au)
71+ assert lc .light_intensity == 1500 # test returns light_intensity (au)
7472
75- lc .automation_job . set_light_intensity (2000 )
73+ lc .set_light_intensity (2000 )
7674
77- assert lc .automation_job . light_intensity == 2000
75+ assert lc .light_intensity == 2000
7876
7977
8078def test_set_intensity_au_negative () -> None :
@@ -83,8 +81,8 @@ def test_set_intensity_au_negative() -> None:
8381
8482 cal = LEDCalibration (
8583 created_at = current_utc_timestamp (),
86- pioreactor_unit = unit ,
87- name = experiment ,
84+ calibrated_on_pioreactor_unit = unit ,
85+ calibration_name = experiment ,
8886 curve_data_ = [1 , 0 ],
8987 curve_type = "poly" ,
9088 recorded_data = {"x" : [0 , 1 ], "y" : [0 , 1 ]},
@@ -94,8 +92,7 @@ def test_set_intensity_au_negative() -> None:
9492 cal .set_as_active_calibration_for_device ("led_C" )
9593 cal .set_as_active_calibration_for_device ("led_D" )
9694
97- with LEDController (
98- "calibrated_light_dark_cycle" ,
95+ with CalibratedLightDarkCycle (
9996 duration = 0.01 ,
10097 light_intensity = - 1 ,
10198 light_duration_hours = 16 ,
@@ -104,55 +101,9 @@ def test_set_intensity_au_negative() -> None:
104101 experiment = experiment ,
105102 ) as lc :
106103
107- assert lc .automation_job . light_intensity == - 1
104+ assert lc .light_intensity == - 1
108105 pause (8 )
109106
110107 with local_intermittent_storage ("leds" ) as led_cache :
111108 assert float (led_cache ["C" ]) == 0.0
112109 assert float (led_cache ["D" ]) == 0.0
113-
114-
115- def test_set_curve_data_negative () -> None :
116- experiment = "test_set_curve_data_negative"
117- unit = get_unit_name ()
118-
119- cal = LEDCalibration (
120- created_at = current_utc_timestamp (),
121- pioreactor_unit = unit ,
122- name = experiment ,
123- curve_data_ = [1 , - 4 ],
124- curve_type = "poly" ,
125- recorded_data = {"x" : [0 , 1 ], "y" : [0 , 1 ]},
126- x = "LED intensity" ,
127- y = "Light sensor reading" ,
128- )
129- cal .set_as_active_calibration_for_device ("led_C" )
130- cal .set_as_active_calibration_for_device ("led_D" )
131-
132- with LEDController (
133- "calibrated_light_dark_cycle" ,
134- duration = 60 ,
135- light_intensity = 1 ,
136- light_duration_hours = 16 ,
137- dark_duration_hours = 8 ,
138- unit = unit ,
139- experiment = experiment ,
140- ) as lc :
141- assert lc .automation_job .light_intensity == 1
142- pause (8 )
143-
144- with local_intermittent_storage ("leds" ) as led_cache :
145- assert float (led_cache ["C" ]) == 5.0
146- assert float (led_cache ["D" ]) == 5.0
147-
148- lc .automation_job .set_light_intensity (150 )
149-
150- with local_intermittent_storage ("leds" ) as led_cache :
151- assert float (led_cache ["C" ]) == 100
152- assert float (led_cache ["D" ]) == 100
153-
154- lc .automation_job .set_light_intensity (- 5 )
155-
156- with local_intermittent_storage ("leds" ) as led_cache :
157- assert float (led_cache ["C" ]) == 0
158- assert float (led_cache ["D" ]) == 0
0 commit comments