Пример #1
0
 def test_update_pilots_valid_pilots(self):
     evse1 = EVSE("PS-001")
     self.network.register_evse(evse1, 240, 0)
     evse2 = EVSE("PS-002")
     self.network.register_evse(evse2, 240, 0)
     evse3 = EVSE("PS-003")
     self.network.register_evse(evse3, 240, 0)
     evse1.set_pilot = create_autospec(evse1.set_pilot)
     evse2.set_pilot = create_autospec(evse2.set_pilot)
     evse3.set_pilot = create_autospec(evse3.set_pilot)
     self.network.update_pilots(np.array([[24, 16], [16, 24], [0, 0]]), 0, 5)
     evse1.set_pilot.assert_any_call(24, 240, 5)
     evse2.set_pilot.assert_any_call(16, 240, 5)
     evse3.set_pilot.assert_any_call(0, 240, 5)
Пример #2
0
class TestEVSE(TestCase):
    def setUp(self):
        self.evse = EVSE('0001')

    def test_allowable_pilot_signals(self):
        self.assertEqual(self.evse.allowable_pilot_signals, [0, float('inf')])

    def test_plugin_unoccupied(self):
        ev = create_autospec(EV)
        self.evse.plugin(ev)
        self.assertEqual(self.evse.ev, ev)

    def test_plugin_occupied(self):
        ev = create_autospec(EV)
        ev2 = create_autospec(EV)
        self.evse.plugin(ev)
        self.assertEqual(self.evse.ev, ev)
        with self.assertRaises(StationOccupiedError):
            self.evse.plugin(ev2)

    def test_unplug_occupied(self):
        ev = create_autospec(EV)
        self.evse.plugin(ev)
        self.evse.unplug()
        self.assertIsNone(self.evse.ev)

    def test_unplug_unoccupied(self):
        self.evse.unplug()
        self.assertIsNone(self.evse.ev)

    def test_set_pilot_has_ev_valid_rate(self):
        ev = create_autospec(EV)
        self.evse.plugin(ev)
        self.evse.set_pilot(16, 240, 5)
        self.assertEqual(self.evse.current_pilot, 16)
        self.evse.ev.charge.assert_called_once()

    def test_set_pilot_has_ev_negative_rate(self):
        ev = create_autospec(EV)
        self.evse.plugin(ev)
        with self.assertRaises(InvalidRateError):
            self.evse.set_pilot(-1, 240, 5)

    def test_set_pilot_no_ev_negative_rate(self):
        with self.assertRaises(InvalidRateError):
            self.evse.set_pilot(-1, 240, 5)
Пример #3
0
class TestEVSE(TestCase):
    def setUp(self):
        self.max_rate = 32
        self.mid_rate = 16
        self.atol = 1e-3
        self.evse = EVSE("0001", max_rate=self.max_rate)

    def test_allowable_pilot_signals_default(self):
        inf_evse = EVSE("0001")
        self.assertEqual(inf_evse.allowable_pilot_signals, [0, float("inf")])

    def test_allowable_pilot_signals(self):
        self.assertEqual(self.evse.allowable_pilot_signals, [0, self.max_rate])

    def test_plugin_unoccupied(self):
        ev = create_autospec(EV)
        self.evse.plugin(ev)
        self.assertEqual(self.evse.ev, ev)

    def test_plugin_occupied(self):
        ev = create_autospec(EV)
        ev2 = create_autospec(EV)
        self.evse.plugin(ev)
        self.assertEqual(self.evse.ev, ev)
        with self.assertRaises(StationOccupiedError):
            self.evse.plugin(ev2)

    def test_unplug_occupied(self):
        ev = create_autospec(EV)
        self.evse.plugin(ev)
        self.evse.unplug()
        self.assertIsNone(self.evse.ev)

    def test_unplug_unoccupied(self):
        self.evse.unplug()
        self.assertIsNone(self.evse.ev)

    def _set_pilot_has_ev_valid_rate_helper(self, pilot):
        ev = create_autospec(EV)
        self.evse.plugin(ev)
        self.evse.set_pilot(pilot, 240, 5)
        self.assertEqual(self.evse.current_pilot, pilot)
        self.evse.ev.charge.assert_called_once()

    def test_set_pilot_has_ev_valid_rate(self):
        self._set_pilot_has_ev_valid_rate_helper(self.mid_rate)

    def test_set_pilot_has_ev_almost_large_rate(self):
        self._set_pilot_has_ev_valid_rate_helper(
            self.max_rate + self.atol - self.atol / 1e2
        )

    def test_set_pilot_has_ev_almost_small_rate(self):
        self._set_pilot_has_ev_valid_rate_helper(-self.atol + self.atol / 1e2)

    def test_set_pilot_has_ev_negative_rate(self):
        ev = create_autospec(EV)
        self.evse.plugin(ev)
        with self.assertRaises(InvalidRateError):
            self.evse.set_pilot(-1, 240, 5)

    def _set_pilot_no_ev_invalid_rate_helper(self, pilot):
        with self.assertRaises(InvalidRateError):
            self.evse.set_pilot(pilot, 240, 5)

    def test_set_pilot_no_ev_negative_rate(self):
        self._set_pilot_no_ev_invalid_rate_helper(-1)

    def test_set_pilot_no_ev_large_rate(self):
        self._set_pilot_no_ev_invalid_rate_helper(self.max_rate + 1)

    def test_set_pilot_no_ev_barely_large_rate(self):
        self._set_pilot_no_ev_invalid_rate_helper(
            self.max_rate + self.atol + self.atol / 1e2
        )

    def test_set_pilot_no_ev_barely_small_rate(self):
        self._set_pilot_no_ev_invalid_rate_helper(-self.atol - self.atol / 1e2)