|
- import unittest
- import time
- from mc_control.mc_statemachine import mc_state_machine,\
- mc_event, mc_states
-
- class MotorControl_BaseUnitTest(unittest.TestCase):
-
- def setUp(self):
- Port_Up = 0
- Port_Down = 1
- self.sm = mc_state_machine(Port_Up, Port_Down, 3)
- self.delay=1
-
- def tearDown(self):
- self.sm.Stop()
- pass
-
- class MotorControl_UnitTest_IDLE(MotorControl_BaseUnitTest):
-
- def test_MotorDown(self):
- # state changed from idle over move down to down
- self.assertEqual(self.sm.current_state , mc_states.idle ,"Check State")
- self.sm.MailBox.put(mc_event.Down)
- time.sleep(self.sm.timeout_value-0.5)
- self.assertEqual(self.sm.current_state , mc_states.move_down ,"Check State")
- time.sleep(self.delay)
- self.assertEqual(self.sm.current_state , mc_states.state_down ,"Check State")
-
-
- def test_MotorUp(self):
- # state changed from idle over move down to down
- self.assertEqual(self.sm.current_state , mc_states.idle ,"Check State")
- self.sm.MailBox.put(mc_event.Up)
- time.sleep(self.sm.timeout_value-0.5)
- self.assertEqual(self.sm.current_state , mc_states.move_up ,"Check State")
- time.sleep(self.delay)
- self.assertEqual(self.sm.current_state , mc_states.state_up ,"Check State")
-
-
- def test_Motor_Up_and_Down(self):
- # move up and down
- self.assertEqual(self.sm.current_state , mc_states.idle ,"Check State")
- self.sm.MailBox.put(mc_event.Up)
- time.sleep(self.sm.timeout_value-0.5)
- self.assertEqual(self.sm.current_state , mc_states.move_up ,"Check State")
- time.sleep(self.delay)
- self.assertEqual(self.sm.current_state , mc_states.state_up ,"Check State")
-
- self.sm.MailBox.put(mc_event.Down)
- time.sleep(self.sm.timeout_value-0.5)
- self.assertEqual(self.sm.current_state , mc_states.move_down ,"Check State")
- time.sleep(self.delay)
- self.assertEqual(self.sm.current_state , mc_states.state_down ,"Check State")
-
- def test_Motor_Down_and_Up(self):
- # state changed from idle over move down to down
- self.assertEqual(self.sm.current_state , mc_states.idle ,"Check State")
- self.sm.MailBox.put(mc_event.Down)
- time.sleep(self.sm.timeout_value-0.5)
- self.assertEqual(self.sm.current_state , mc_states.move_down ,"Check State")
- time.sleep(self.delay)
- self.assertEqual(self.sm.current_state , mc_states.state_down ,"Check State")
- self.sm.MailBox.put(mc_event.Up)
- time.sleep(self.sm.timeout_value-0.5)
- self.assertEqual(self.sm.current_state , mc_states.move_up ,"Check State")
- time.sleep(self.delay)
- self.assertEqual(self.sm.current_state , mc_states.state_up ,"Check State")
-
- def test_Stop(self):
- # state changed from idle over move down to down
- self.assertEqual(self.sm.current_state , mc_states.idle ,"Check State")
- self.sm.MailBox.put(mc_event.Stop)
-
- time.sleep(self.delay)
- self.assertEqual(self.sm.current_state , mc_states.idle ,"Check State")
-
- class MotorControl_UnitTest_MoveUP(MotorControl_BaseUnitTest):
-
- def setUp(self):
- super().setUp()
- self.sm.MailBox.put(mc_event.Up)
- time.sleep(self.delay)
-
- def test_Stop(self):
- self.assertEqual(self.sm.current_state , mc_states.move_up ,"Check State")
- self.sm.MailBox.put(mc_event.Stop)
- time.sleep(self.delay)
- self.assertEqual(self.sm.current_state , mc_states.idle ,"Check State")
-
- def test_Up(self):
- self.assertEqual(self.sm.current_state , mc_states.move_up ,"Check State")
- self.sm.MailBox.put(mc_event.Up)
- time.sleep(self.delay)
- self.assertEqual(self.sm.current_state , mc_states.move_up ,"Check State")
- pass
-
- def test_Down(self):
- self.assertEqual(self.sm.current_state , mc_states.move_up ,"Check State")
- self.sm.MailBox.put(mc_event.Down)
- time.sleep(self.delay)
- self.assertEqual(self.sm.current_state , mc_states.move_down ,"Check State")
-
- def test_Timeout(self):
- self.assertEqual(self.sm.current_state , mc_states.move_up ,"Check State")
- time.sleep(self.delay+self.sm.timeout_value)
- self.assertEqual(self.sm.current_state , mc_states.state_up ,"Check State")
-
- class MotorControl_UnitTest_UP(MotorControl_BaseUnitTest):
-
- def setUp(self):
- super().setUp()
- self.sm.MailBox.put(mc_event.Up)
- time.sleep(self.delay+self.sm.timeout_value)
-
- def test_Stop(self):
- # state changed from idle over move down to down
- self.assertEqual(self.sm.current_state , mc_states.state_up ,"Check State")
- self.sm.MailBox.put(mc_event.Stop)
- time.sleep(self.delay)
- self.assertEqual(self.sm.current_state , mc_states.idle ,"Check State")
-
- class MotorControl_Events(MotorControl_BaseUnitTest):
-
- def setUp(self):
- super().setUp()
- #self.sm.MailBox.put(mc_event.Up)
-
- def test_Stop(self):
- # state changed from idle over move down to down
- # self.sm.MailBox.put(mc_event.Up)
- time.sleep(0.5)
-
-
|