From e89cbdc2aa2efa978c66b634fd9f4011113d5c66 Mon Sep 17 00:00:00 2001 From: Romain Bazile Date: Tue, 6 Oct 2020 11:42:07 +0200 Subject: [PATCH] python: reminder to add tests --- scripts/planktoscope/imager.py | 5 +++++ scripts/planktoscope/light.py | 1 + scripts/planktoscope/mqtt.py | 8 +++++++- scripts/planktoscope/segmenter.py | 5 +++++ scripts/planktoscope/stepper.py | 23 ++++++++++++----------- 5 files changed, 30 insertions(+), 12 deletions(-) diff --git a/scripts/planktoscope/imager.py b/scripts/planktoscope/imager.py index 2f1a564..80c4feb 100644 --- a/scripts/planktoscope/imager.py +++ b/scripts/planktoscope/imager.py @@ -526,3 +526,8 @@ class ImagerProcess(multiprocessing.Process): # self.streaming_thread.kill() logger.success("Imager process shut down! See you!") + +# This is called if this script is launched directly +if __name__ == "__main__": + # TODO This should be a test suite for this library + pass \ No newline at end of file diff --git a/scripts/planktoscope/light.py b/scripts/planktoscope/light.py index c455f96..fe18db1 100644 --- a/scripts/planktoscope/light.py +++ b/scripts/planktoscope/light.py @@ -90,6 +90,7 @@ def light(state): # This is called if this script is launched directly if __name__ == "__main__": + # TODO This should be a test suite for this library import RPi.GPIO as GPIO import sys diff --git a/scripts/planktoscope/mqtt.py b/scripts/planktoscope/mqtt.py index 5e7ff8f..1a5414f 100644 --- a/scripts/planktoscope/mqtt.py +++ b/scripts/planktoscope/mqtt.py @@ -164,4 +164,10 @@ class MQTT_Client: def shutdown(self, topic="", message=""): logger.info(f"Shutting down mqtt client {self.name}") self.client.loop_stop() - logger.debug(f"Mqtt client {self.name} shut down") \ No newline at end of file + logger.debug(f"Mqtt client {self.name} shut down") + + +# This is called if this script is launched directly +if __name__ == "__main__": + # TODO This should be a test suite for this library + pass \ No newline at end of file diff --git a/scripts/planktoscope/segmenter.py b/scripts/planktoscope/segmenter.py index 3c74ae6..cf895a3 100644 --- a/scripts/planktoscope/segmenter.py +++ b/scripts/planktoscope/segmenter.py @@ -361,3 +361,8 @@ class SegmenterProcess(multiprocessing.Process): self.segmenter_client.shutdown() logger.success("Segmenter process shut down! See you!") + +# This is called if this script is launched directly +if __name__ == "__main__": + # TODO This should be a test suite for this library + pass \ No newline at end of file diff --git a/scripts/planktoscope/stepper.py b/scripts/planktoscope/stepper.py index e62811e..555774e 100644 --- a/scripts/planktoscope/stepper.py +++ b/scripts/planktoscope/stepper.py @@ -209,15 +209,15 @@ class StepperProcess(multiprocessing.Process): # define the names for the 2 exsting steppers if self.stepper_type == "adafruit": logger.info("Loading the adafruit configuration") - kit = adafruit_motorkit.MotorKit() - if reverse: - self.pump_stepper = stepper(kit.stepper2, adafruit_motor.stepper.DOUBLE) - self.focus_stepper = stepper( + kit = adafruit_motorkit.MotorKit() + if reverse: + self.pump_stepper = stepper(kit.stepper2, adafruit_motor.stepper.DOUBLE) + self.focus_stepper = stepper( kit.stepper1, adafruit_motor.stepper.MICROSTEP, size=45 - ) - else: - self.pump_stepper = stepper(kit.stepper1, adafruit_motor.stepper.DOUBLE) - self.focus_stepper = stepper( + ) + else: + self.pump_stepper = stepper(kit.stepper1, adafruit_motor.stepper.DOUBLE) + self.focus_stepper = stepper( kit.stepper2, adafruit_motor.stepper.MICROSTEP, size=45 ) elif self.stepper_type == "waveshare": @@ -237,7 +237,7 @@ class StepperProcess(multiprocessing.Process): self.focus_stepper = stepper( StepperWaveshare(dir_pin=24, step_pin=18, enable_pin=4), size=45, - ) + ) else: logger.error( "The stepper control type is not recognized. Should be 'adafruit' or 'waveshare'" @@ -398,7 +398,7 @@ class StepperProcess(multiprocessing.Process): # However we have a fixed delay of at least 2.5ms per step due to the library # Our maximum speed is thus about 400 pulses per second or 0.5mm/sec of stage speed if self.stepper_type == "adafruit": - delay = max((1 / steps_per_second) - 0.0025, 0) + delay = max((1 / steps_per_second) - 0.0025, 0) else: delay = 1 / steps_per_second logger.debug(f"The delay between two steps is {delay}s") @@ -459,7 +459,7 @@ class StepperProcess(multiprocessing.Process): # nb_steps = 5200 * 15 = 78000 # sps = 3mL/min * 5200s/mL = 15600s/min / 60 => 260sps if self.stepper_type == "adafruit": - delay = max((1 / steps_per_second) - 0.0025, 0) + delay = max((1 / steps_per_second) - 0.0025, 0) else: delay = 1 / steps_per_second logger.debug(f"The delay between two steps is {delay}s") @@ -523,6 +523,7 @@ class StepperProcess(multiprocessing.Process): # This is called if this script is launched directly if __name__ == "__main__": + # TODO This should be a test suite for this library # Starts the stepper thread for actuators # This needs to be in a threading or multiprocessing wrapper stepper_thread = StepperProcess()