Пример #1
0
 def test_broken(self):
     gpio = DeterministicGate("broken")
     ctrl = GateController(gpio, TESTLOGGER)
     with self.assertRaises(ValueError):
         ctrl.get_state()
     with self.assertRaises(ValueError):
         ctrl.move_to_state("up")
Пример #2
0
 def test_already_closed(self):
     gpio = DeterministicGate("down")
     ctrl = GateController(gpio, TESTLOGGER)
     self.assertEqual(ctrl.get_state(), "down")
     ctrl.move_to_state("down")
     self.assertEqual(ctrl.get_state(), "down")
     self.assertEqual(gpio.triggered, 0)
Пример #3
0
 def test_simple_close(self):
     gpio = DeterministicGate("up")
     ctrl = GateController(gpio, TESTLOGGER)
     self.assertEqual(ctrl.get_state(), "up")
     gpio.states_after_trigger.extend([(1, "unknown"), (20, "down")])
     ctrl.move_to_state("down")
     self.assertEqual(ctrl.get_state(), "down")
     self.assertEqual(gpio.triggered, 1)
Пример #4
0
 def test_trigger(self):
     gpio = DeterministicGate("unknown")
     ctrl = GateController(gpio, TESTLOGGER)
     self.assertFalse(gpio.motor_pin_state)
     self.assertEqual(gpio.triggered, 0)
     ctrl.trigger()
     self.assertFalse(gpio.motor_pin_state)
     self.assertEqual(gpio.triggered, 1)
     ctrl.trigger()
     self.assertFalse(gpio.motor_pin_state)
     self.assertEqual(gpio.triggered, 2)
Пример #5
0
 def test_unknown_open(self):
     gpio = DeterministicGate("unknown")
     ctrl = GateController(gpio, TESTLOGGER)
     self.assertEqual(ctrl.get_state(), "transitioning")
     gpio.states_after_trigger.extend([
         (20, "down"),
         None,  # gate closes
         (1, "unknown"),
         (20, "up")
     ])  # gate opens
     ctrl.move_to_state("up")
     self.assertEqual(ctrl.get_state(), "up")
     self.assertEqual(gpio.triggered, 2)
Пример #6
0
 def test_interrupted_close(self):
     gpio = DeterministicGate("up")
     ctrl = GateController(gpio, TESTLOGGER)
     self.assertEqual(ctrl.get_state(), "up")
     gpio.states_after_trigger.extend([
         (1, "unknown"),
         None,  # gate starts moving, but someone stops it so it never arrives anywhere
         (1, "unknown"),
         (20, "down")
     ])
     ctrl.move_to_state("down")
     self.assertEqual(ctrl.get_state(), "down")
     self.assertEqual(gpio.triggered, 2)
Пример #7
0
 def test_get_state_transitioning(self):
     gpio = DeterministicGate("unknown")
     ctrl = GateController(gpio, TESTLOGGER)
     self.assertEqual(ctrl.get_state(), "transitioning")
Пример #8
0
 def test_get_state_up(self):
     gpio = DeterministicGate("up")
     ctrl = GateController(gpio, TESTLOGGER)
     self.assertEqual(ctrl.get_state(), "up")
Пример #9
0
    def test_trigger(self):
        gpio = DeterministicGate("unknown")

        # Test normal triggering -- init...
        self.assertEqual(gpio.motor_pin_state, False)
        self.assertEqual(gpio.triggered, 0)

        # Test normal triggering -- trigger once...
        gpio.output(GateController.PIN_MOTOR, True)
        self.assertEqual(gpio.motor_pin_state, True)
        self.assertEqual(gpio.triggered, 0)
        gpio.output(GateController.PIN_MOTOR, False)
        self.assertEqual(gpio.motor_pin_state, False)
        self.assertEqual(gpio.triggered, 1)
        self.assertEqual(gpio.state, "unknown")

        # Test normal triggering -- trigger twice, with a new state...
        gpio.states_after_trigger.append((0, "up"))
        gpio.output(GateController.PIN_MOTOR, True)
        self.assertEqual(gpio.motor_pin_state, True)
        self.assertEqual(gpio.triggered, 1)
        gpio.output(GateController.PIN_MOTOR, False)
        self.assertEqual(gpio.motor_pin_state, False)
        self.assertEqual(gpio.triggered, 2)
        self.assertEqual(gpio.state, "up")

        # Try to output something on the input ports
        with self.assertRaises(KeyError):
            gpio.output(GateController.PIN_LOWER, True)
        with self.assertRaises(KeyError):
            gpio.output(GateController.PIN_UPPER, True)

        # Try switching off the motor port while it's off already
        with self.assertRaises(ValueError):
            gpio.output(GateController.PIN_MOTOR, False)

        # Try switching on the motor port while it's on already
        gpio.output(GateController.PIN_MOTOR, True)
        with self.assertRaises(ValueError):
            gpio.output(GateController.PIN_MOTOR, True)
Пример #10
0
 def test_get_state_broken(self):
     gpio = DeterministicGate("broken")
     self.assertFalse(gpio.input(GateController.PIN_LOWER))
     self.assertFalse(gpio.input(GateController.PIN_UPPER))
Пример #11
0
 def test_get_state_transitioning(self):
     gpio = DeterministicGate("unknown")
     self.assertTrue(gpio.input(GateController.PIN_LOWER))
     self.assertTrue(gpio.input(GateController.PIN_UPPER))
Пример #12
0
 def test_get_state_up(self):
     gpio = DeterministicGate("up")
     self.assertTrue(gpio.input(GateController.PIN_LOWER))
     self.assertFalse(gpio.input(GateController.PIN_UPPER))