Ejemplo n.º 1
0
 def test_shutsdown_cleanly(self):
     self.tdza = TimedDripZAxis(1, 0.0)
     self.tdza.start()
     time.sleep(0.1)
     self.tdza.close()
     time.sleep(0.1)
     self.assertFalse(self.tdza.is_alive())
Ejemplo n.º 2
0
 def test_current_z_location_mm_returns_the_correct_number(self):
     self.tdza = TimedDripZAxis(1000.0, 0.0, drips_per_second=4000)
     expected_mm = 2.0
     start = time.time()
     self.tdza.start()
     while time.time() - start < 0.5:
         time.sleep(0.01)
     result = self.tdza.current_z_location_mm()
     self.tdza.close()
     self.assertAlmostEquals(expected_mm, result, places=0)
Ejemplo n.º 3
0
    def test_move_to_does_nothing(self):
        expected_drips_per_second = 12
        self.tdza = TimedDripZAxis(
            1,
            0.0,
            drips_per_second=expected_drips_per_second,
            calls_back_per_second=100
            )

        self.tdza.start()
        self.tdza.move_to(7.0)
Ejemplo n.º 4
0
    def test_can_set_call_back(self):
        self.tdza = TimedDripZAxis(
            1,
            0.0,
            drips_per_second=10,
            calls_back_per_second=100
            )

        self.tdza.set_call_back(self.call_back)
        self.tdza.start()
        time.sleep(0.1)
        self.tdza.close()

        self.assertTrue(self.calls > 0)
Ejemplo n.º 5
0
    def test_set_drips_per_second(self):
        expected_drips_per_second = 12
        self.tdza = TimedDripZAxis(
            1,
            0.0,
            drips_per_second=expected_drips_per_second,
            calls_back_per_second=100
            )

        self.tdza.start()
        actual = self.tdza.get_drips_per_second()
        self.tdza.close()

        self.assertEquals(expected_drips_per_second, actual)
Ejemplo n.º 6
0
    def test_cset_drips_per_mm_returns_the_new_correct_height(self):
        original_drips_per_mm = 1
        new_drips_per_mm = 0.1

        self.tdza = TimedDripZAxis(original_drips_per_mm, 0.0, drips_per_second=100)
        start = time.time()
        self.tdza.start()
        while time.time() - start < 0.1:
            time.sleep(0.01)
        self.tdza.close()
        time.sleep(0.01)
        original_result = self.tdza.current_z_location_mm()
        self.tdza.set_drips_per_mm(new_drips_per_mm)
        new_result = self.tdza.current_z_location_mm()
        self.assertAlmostEquals(original_result * 10, new_result, places=0)
Ejemplo n.º 7
0
    def test_current_z_location_mm_returns_the_correct_number_given_starting_height(self):
        starting_height = 7.7
        expected_height = starting_height + 2
        self.tdza = TimedDripZAxis(5, starting_height, drips_per_second=100)

        self.assertEquals(starting_height, self.tdza.current_z_location_mm())

        start = time.time()
        self.tdza.start()
        while time.time() - start < 0.1:
            time.sleep(0.01)
        result = self.tdza.current_z_location_mm()
        self.tdza.close()

        self.assertAlmostEquals(expected_height, result, places=0)
Ejemplo n.º 8
0
    def test_can_change_drips_per_second_with_out_altering_existing_data(self):
        self.tdza = TimedDripZAxis(
            1,
            0.0,
            drips_per_second=100,
            calls_back_per_second=100
            )

        self.tdza.set_call_back(self.call_back)
        self.tdza.start()
        time.sleep(0.5)
        before_drips = self.drips
        before_cb_height = self.height
        before_height = self.tdza.current_z_location_mm()
        self.tdza.set_drips_per_second(10)
        time.sleep(0.5)
        self.assertTrue(before_height <= self.tdza.current_z_location_mm(), "%s !<= %s" % (before_height, self.tdza.current_z_location_mm()))
        self.assertTrue(before_cb_height <= self.height)
        self.assertTrue(before_drips <= self.drips)
        self.tdza.close()

        self.assertTrue(self.calls > 0)
Ejemplo n.º 9
0
 def _get_zaxis(self, dry_run):
     if dry_run:
         return None
     elif self._configuration.dripper.dripper_type == 'photo':
         logger.info("Photo Zaxis")
         return PhotoZAxis(self._start_height,
                           self._configuration.dripper.photo_zaxis_delay)
     elif self._configuration.dripper.dripper_type == 'emulated':
         logger.info("Emulated Zaxis")
         return TimedDripZAxis(self._configuration.dripper.drips_per_mm,
                               self._start_height,
                               drips_per_second=self._configuration.dripper.
                               emulated_drips_per_second)
     elif self._configuration.dripper.dripper_type == 'microcontroller':
         logger.info("Micro Controller Zaxis")
         return SerialDripZAxis(
             self._get_communicator(dry_run),
             self._configuration.dripper.drips_per_mm,
             self._start_height,
         )
Ejemplo n.º 10
0
class TimedDripZaxisTests(unittest.TestCase):
    def setUp(self):
        self.tdza = None

        self.calls = 0
        self.drips = 0
        self.height = 0
        self.drips_per_second = 0

    def tearDown(self):
        if self.tdza:
            self.tdza.close()

    def call_back(self, drips, height, drips_per_second, drip_history):
        self.calls += 1
        self.drips = drips
        self.height = height
        self.drips_per_second = drips_per_second
        self.drip_history = drip_history

    def test_shutsdown_cleanly(self):
        self.tdza = TimedDripZAxis(1, 0.0)
        self.tdza.start()
        time.sleep(0.1)
        self.tdza.close()
        time.sleep(0.1)
        self.assertFalse(self.tdza.is_alive())

    def test_current_z_location_mm_returns_the_correct_number(self):
        self.tdza = TimedDripZAxis(1000.0, 0.0, drips_per_second=4000)
        expected_mm = 2.0
        start = time.time()
        self.tdza.start()
        while time.time() - start < 0.5:
            time.sleep(0.01)
        result = self.tdza.current_z_location_mm()
        self.tdza.close()
        self.assertAlmostEquals(expected_mm, result, places=0)

    def test_current_z_location_mm_returns_the_correct_number_given_starting_height(self):
        starting_height = 7.7
        expected_height = starting_height + 2
        self.tdza = TimedDripZAxis(5, starting_height, drips_per_second=100)

        self.assertEquals(starting_height, self.tdza.current_z_location_mm())

        start = time.time()
        self.tdza.start()
        while time.time() - start < 0.1:
            time.sleep(0.01)
        result = self.tdza.current_z_location_mm()
        self.tdza.close()

        self.assertAlmostEquals(expected_height, result, places=0)

    def test_cset_drips_per_mm_returns_the_new_correct_height(self):
        original_drips_per_mm = 1
        new_drips_per_mm = 0.1

        self.tdza = TimedDripZAxis(original_drips_per_mm, 0.0, drips_per_second=100)
        start = time.time()
        self.tdza.start()
        while time.time() - start < 0.1:
            time.sleep(0.01)
        self.tdza.close()
        time.sleep(0.01)
        original_result = self.tdza.current_z_location_mm()
        self.tdza.set_drips_per_mm(new_drips_per_mm)
        new_result = self.tdza.current_z_location_mm()
        self.assertAlmostEquals(original_result * 10, new_result, places=0)

    def test_can_set_call_back(self):
        self.tdza = TimedDripZAxis(
            1,
            0.0,
            drips_per_second=10,
            calls_back_per_second=100
            )

        self.tdza.set_call_back(self.call_back)
        self.tdza.start()
        time.sleep(0.1)
        self.tdza.close()

        self.assertTrue(self.calls > 0)

    def test_can_change_drips_per_second_with_out_altering_existing_data(self):
        self.tdza = TimedDripZAxis(
            1,
            0.0,
            drips_per_second=100,
            calls_back_per_second=100
            )

        self.tdza.set_call_back(self.call_back)
        self.tdza.start()
        time.sleep(0.5)
        before_drips = self.drips
        before_cb_height = self.height
        before_height = self.tdza.current_z_location_mm()
        self.tdza.set_drips_per_second(10)
        time.sleep(0.5)
        self.assertTrue(before_height <= self.tdza.current_z_location_mm(), "%s !<= %s" % (before_height, self.tdza.current_z_location_mm()))
        self.assertTrue(before_cb_height <= self.height)
        self.assertTrue(before_drips <= self.drips)
        self.tdza.close()

        self.assertTrue(self.calls > 0)

    def test_set_drips_per_second(self):
        expected_drips_per_second = 12
        self.tdza = TimedDripZAxis(
            1,
            0.0,
            drips_per_second=expected_drips_per_second,
            calls_back_per_second=100
            )

        self.tdza.start()
        actual = self.tdza.get_drips_per_second()
        self.tdza.close()

        self.assertEquals(expected_drips_per_second, actual)

    def test_move_to_does_nothing(self):
        expected_drips_per_second = 12
        self.tdza = TimedDripZAxis(
            1,
            0.0,
            drips_per_second=expected_drips_per_second,
            calls_back_per_second=100
            )

        self.tdza.start()
        self.tdza.move_to(7.0)