From d2b29bbf522fdfb575cda9aa183c9d3cfc902083 Mon Sep 17 00:00:00 2001 From: CamDavidsonPilon Date: Sun, 9 Jul 2023 08:50:35 -0400 Subject: [PATCH] types and tests --- pioreactor/actions/self_test.py | 9 +++++---- pioreactor/automations/led/base.py | 4 ++-- pioreactor/background_jobs/od_reading.py | 14 +++++++------- pioreactor/pubsub.py | 2 +- pioreactor/tests/test_dosing_control.py | 2 +- pioreactor/tests/test_temperature_control.py | 12 ++++++++++-- 6 files changed, 26 insertions(+), 17 deletions(-) diff --git a/pioreactor/actions/self_test.py b/pioreactor/actions/self_test.py index a238533d..b1034a4b 100644 --- a/pioreactor/actions/self_test.py +++ b/pioreactor/actions/self_test.py @@ -24,6 +24,7 @@ from pioreactor.background_jobs import stirring from pioreactor.background_jobs.od_reading import ADCReader from pioreactor.background_jobs.od_reading import ALL_PD_CHANNELS +from pioreactor.background_jobs.od_reading import average_over_pd_channel_to_voltages from pioreactor.background_jobs.od_reading import IR_keyword from pioreactor.background_jobs.od_reading import REF_keyword from pioreactor.background_jobs.od_reading import start_od_reading @@ -153,13 +154,13 @@ def test_all_positive_correlations_between_pds_and_leds( ) # record from ADC, we'll average them - readings1 = adc_reader.take_reading() - readings2 = adc_reader.take_reading() + avg_reading = average_over_pd_channel_to_voltages( + adc_reader.take_reading(), adc_reader.take_reading() + ) # Add to accumulating list for pd_channel in ALL_PD_CHANNELS: - reading = 0.5 * (readings1[pd_channel] + readings2[pd_channel]) - varying_intensity_results[pd_channel].append(reading) + varying_intensity_results[pd_channel].append(avg_reading[pd_channel]) # compute the linear correlation between the intensities and observed PD measurements for pd_channel in ALL_PD_CHANNELS: diff --git a/pioreactor/automations/led/base.py b/pioreactor/automations/led/base.py index 976085da..d2ebf4df 100644 --- a/pioreactor/automations/led/base.py +++ b/pioreactor/automations/led/base.py @@ -174,7 +174,7 @@ def execute(self) -> Optional[events.AutomationEvent]: def most_stale_time(self) -> datetime: return min(self.latest_normalized_od_at, self.latest_growth_rate_at) - def set_led_intensity(self, channel: pt.LedChannel, intensity: float) -> bool: + def set_led_intensity(self, channel: pt.LedChannel, intensity: pt.LedIntensityValue) -> bool: """ This first checks the lock on the LED channel, and will wait a few seconds for it to clear, and error out if it waits too long. @@ -262,7 +262,7 @@ def on_disconnected(self) -> None: self.run_thread.join() led_intensity( - {channel: 0 for channel in self.edited_channels}, + {channel: 0.0 for channel in self.edited_channels}, unit=self.unit, experiment=self.experiment, source_of_event=f"{self.job_name}:{self.automation_name}", diff --git a/pioreactor/background_jobs/od_reading.py b/pioreactor/background_jobs/od_reading.py index 5e4fd531..308ab0ad 100644 --- a/pioreactor/background_jobs/od_reading.py +++ b/pioreactor/background_jobs/od_reading.py @@ -825,7 +825,7 @@ def __init__( # setup the ADC by turning off all LEDs. with led_utils.change_leds_intensities_temporarily( - self.ir_led_on_and_rest_off_state, + {ch: 0.0 for ch in led_utils.ALL_LED_CHANNELS}, unit=self.unit, experiment=self.experiment, source_of_event=self.job_name, @@ -834,19 +834,19 @@ def __init__( ): with led_utils.lock_leds_temporarily(self.non_ir_led_channels): # IR led is on - sleep(0.1) - + self.start_ir_led() + sleep(0.10) self.adc_reader.setup_adc() # determine best gain, max-signal, etc. + # IR led is off so we can set blanks self.stop_ir_led() - sleep(0.15) + sleep(0.10) - blank_reading = average_over_pd_channel_to_voltages( - self.adc_reader.take_reading(), + avg_blank_reading = average_over_pd_channel_to_voltages( self.adc_reader.take_reading(), self.adc_reader.take_reading(), ) - self.adc_reader.set_offsets(blank_reading) # determine offset + self.adc_reader.set_offsets(avg_blank_reading) # set dark offset # clear the history in adc_reader, so that we don't blank readings in later inference. self.adc_reader.clear_batched_readings() diff --git a/pioreactor/pubsub.py b/pioreactor/pubsub.py index fc09acc2..c7a7c571 100644 --- a/pioreactor/pubsub.py +++ b/pioreactor/pubsub.py @@ -397,7 +397,7 @@ def publish_to_pioreactor_cloud( from pioreactor.utils.timing import current_utc_timestamp from json import dumps - assert data_dict is not None and data_str is not None + assert (data_dict is not None) or (data_str is not None) if is_testing_env(): return diff --git a/pioreactor/tests/test_dosing_control.py b/pioreactor/tests/test_dosing_control.py index 70bdf5ff..e5ed17c0 100644 --- a/pioreactor/tests/test_dosing_control.py +++ b/pioreactor/tests/test_dosing_control.py @@ -278,7 +278,7 @@ def test_changing_morbidostat_parameters_over_mqtt() -> None: ) pause() assert algo.target_growth_rate == new_target - assert algo.pid.pid.setpoint == new_target + assert algo.pid.setpoint == new_target algo.clean_up() diff --git a/pioreactor/tests/test_temperature_control.py b/pioreactor/tests/test_temperature_control.py index 4efbd12e..7650a070 100644 --- a/pioreactor/tests/test_temperature_control.py +++ b/pioreactor/tests/test_temperature_control.py @@ -115,7 +115,11 @@ def test_heating_is_reduced_when_set_temp_is_exceeded() -> None: with temperature_control.TemperatureController( "only_record_temperature", unit=unit, experiment=experiment ) as t: - setattr(t.tmp_driver, "get_temperature", lambda *args: t.MAX_TEMP_TO_REDUCE_HEATING + 0.1) + setattr( + t.heating_pcb_tmp_driver, + "get_temperature", + lambda *args: t.MAX_TEMP_TO_REDUCE_HEATING + 0.1, + ) pause() t._update_heater(50) pause() @@ -146,7 +150,11 @@ def test_heating_stops_when_max_temp_is_exceeded() -> None: target_temperature=25, ) as t: # monkey patch the driver - setattr(t.tmp_driver, "get_temperature", lambda *args: t.MAX_TEMP_TO_DISABLE_HEATING + 0.1) + setattr( + t.heating_pcb_tmp_driver, + "get_temperature", + lambda *args: t.MAX_TEMP_TO_DISABLE_HEATING + 0.1, + ) pause() pause() t._update_heater(50)