Пример #1
0
 def test_unplug_station_exists_session_id_mismatch(self,
                                                    choice_mock) -> None:
     ev = EV(0, 10, 10, "", "Session-01", Battery(100, 0, 6.6))
     choice_mock.return_value = "PS-002"
     self.network.plugin(ev)
     self.network._EVSEs["PS-002"].unplug = Mock()
     self.network.unplug(ev.station_id, "Incorrect ID")
     # noinspection PyUnresolvedReferences
     self.network._EVSEs["PS-002"].unplug.assert_not_called()
Пример #2
0
    def test_unplug_station_exists_session_id_matches_queue_empty(
            self, choice_mock) -> None:
        ev = EV(0, 10, 10, "", "Session-01", Battery(100, 0, 6.6))
        choice_mock.return_value = "PS-002"

        self.network.plugin(ev)

        self.network._EVSEs["PS-002"].unplug = Mock()
        self.network.unplug(ev.station_id, ev.session_id)
        self.network._EVSEs["PS-002"].unplug.assert_called()
Пример #3
0
class TestBatteryBase(TestCase):
    def setUp(self):
        self.batt = Battery(100, 50, 32)

    def test_charge_negative_voltage(self):
        with self.assertRaises(ValueError):
            self.batt.charge(32, -240, 5)

    def test_charge_negative_period(self):
        with self.assertRaises(ValueError):
            self.batt.charge(32, 240, -5)

    def test_valid_reset(self):
        self.batt.charge(16, 240, 5)
        self.batt.reset(45)
        self.assertEqual(self.batt.current_charging_power, 0)
        self.assertEqual(self.batt._current_charge, 45)

    def test_reset_over_capacity(self):
        with self.assertRaises(ValueError):
            self.batt.reset(110)
Пример #4
0
    def test_plugin_ev_no_spot_available_evs_in_waiting_queue(self) -> None:
        ev1 = EV(0, 10, 10, "", "Session-01", Battery(100, 0, 6.6))
        ev2 = EV(0, 10, 10, "", "Session-02", Battery(100, 0, 6.6))

        # Mock available_evses to behavior like the network is full.
        self.network.available_evses = Mock(return_value=[])

        # Add ev1 to the waiting queue
        self.network.waiting_queue[ev1.session_id] = ev1
        self.network.waiting_queue.move_to_end(ev1.session_id)

        self.network.plugin(ev2)

        # EV should be added to waiting_queue
        self.assertEqual(len(self.network.waiting_queue), 2)

        # ev1 should be after ev2 in the queue
        _, first_in_queue = self.network.waiting_queue.popitem(last=False)
        _, second_in_queue = self.network.waiting_queue.popitem(last=False)
        self.assertIs(first_in_queue, ev1)
        self.assertIs(second_in_queue, ev2)
Пример #5
0
    def test_plugin_ev_no_spot_available_empty_waiting_queue(self) -> None:
        ev = EV(0, 10, 10, "", "Session-01", Battery(100, 0, 6.6))

        # Mock available_evses to behavior like the network is full.
        self.network.available_evses = Mock(return_value=[])

        self.network.plugin(ev)

        # EV should be added to waiting_queue
        self.assertEqual(len(self.network.waiting_queue), 1)
        self.assertIn(ev.session_id, self.network.waiting_queue)
        self.assertIs(self.network.waiting_queue[ev.session_id], ev)
Пример #6
0
class TestBattery(TestBatteryBase):
    def setUp(self):
        self.batt = Battery(100, 50, 7.68)

    def test_valid_charge(self):
        rate = self.batt.charge(16, 240, 5)
        self.assertEqual(rate, 16)
        self.assertEqual(self.batt.current_charging_power, 3.84)
        self.assertAlmostEqual(self.batt._current_charge, 50.32)

    def test_charge_over_max_rate(self):
        rate = self.batt.charge(55, 240, 5)
        self.assertEqual(rate, 32)
        self.assertEqual(self.batt.current_charging_power, 7.68)
        self.assertAlmostEqual(self.batt._current_charge, 50.64)

    def test_charge_over_capacity(self):
        self.batt = Battery(50, 49.8, 7.68)
        rate = self.batt.charge(32, 240, 5)
        self.assertAlmostEqual(rate, 10)
        self.assertAlmostEqual(self.batt.current_charging_power, 2.4)
        self.assertAlmostEqual(self.batt._current_charge, 50)
Пример #7
0
    def test_post_charging_update_early_departure_ev_not_full(
            self, choice_mock):
        self.network.early_departure = True

        ev1 = EV(0, 10, 10, "", "Session-01", Battery(100, 0, 6.6))
        ev2 = EV(0, 10, 10, "", "Session-02", Battery(100, 0, 6.6))

        # Plug ev1 into space PS-001
        choice_mock.return_value = "PS-002"
        self.network.plugin(ev1)

        # ev1 not fully charged
        ev1._energy_delivered = 5

        # Add ev2 to the waiting queue
        self.network.waiting_queue[ev2.session_id] = ev2
        self.network.waiting_queue.move_to_end(ev2.session_id)

        # Test that unplug is called during post_charging_update.
        self.network.unplug = Mock()
        self.network.post_charging_update()
        self.network.unplug.assert_not_called()
Пример #8
0
    def test_unplug_station_exists_session_id_matches_ev_in_queue(
            self, choice_mock) -> None:
        ev1 = EV(0, 10, 10, "", "Session-01", Battery(100, 0, 6.6))
        ev2 = EV(0, 10, 10, "", "Session-02", Battery(100, 0, 6.6))

        # Plug ev1 into space PS-001
        choice_mock.return_value = "PS-002"
        self.network.plugin(ev1)

        # Add ev2 to the waiting queue
        self.network.waiting_queue[ev2.session_id] = ev2
        self.network.waiting_queue.move_to_end(ev2.session_id)

        # Mock the plugin method so we can assert it was called.
        self.network._EVSEs["PS-002"].plugin = Mock()

        # Unplug ev1
        self.network.unplug(ev1.station_id, ev1.session_id)

        # ev2 should be plugged in after ev1 leaves
        self.network._EVSEs["PS-002"].plugin.assert_called_with(ev2)

        # swaps counter should be incremented
        self.assertEqual(self.network.swaps, 1)
Пример #9
0
    def test_unplug_when_ev_in_waiting_queue(self):
        ev1 = EV(0, 10, 10, "", "Session-01", Battery(100, 0, 6.6))

        # Add ev2 to the waiting queue
        self.network.waiting_queue[ev1.session_id] = ev1
        self.network.waiting_queue.move_to_end(ev1.session_id)

        self.assertEqual(len(self.network.waiting_queue), 1)

        self.network.unplug(ev1.station_id, ev1.session_id)

        # ev1 should be removed from the waiting queue
        self.assertEqual(len(self.network.waiting_queue), 0)

        # never_charged counter should be incremented
        self.assertEqual(self.network.never_charged, 1)
Пример #10
0
    def test_post_charging_update_early_departure_no_ev_in_queue(
            self, choice_mock):
        self.network.early_departure = True

        ev1 = EV(0, 10, 10, "", "Session-01", Battery(100, 0, 6.6))

        # Plug ev1 into space PS-001
        choice_mock.return_value = "PS-002"
        self.network.plugin(ev1)

        # Fully charge ev1
        ev1._energy_delivered = 10

        # Test that unplug is called during post_charging_update.
        self.network.unplug = Mock()
        self.network.post_charging_update()
        self.network.unplug.assert_not_called()
Пример #11
0
 def setUp(self):
     self.batt = Battery(100, 50, 32)
Пример #12
0
 def test_charge_over_capacity(self):
     self.batt = Battery(50, 49.8, 7.68)
     rate = self.batt.charge(32, 240, 5)
     self.assertAlmostEqual(rate, 10)
     self.assertAlmostEqual(self.batt.current_charging_power, 2.4)
     self.assertAlmostEqual(self.batt._current_charge, 50)
Пример #13
0
 def setUp(self):
     self.init_charge = 50
     self.batt = Battery(100, self.init_charge, 32)
Пример #14
0
 def test_plugin_ev_with_spot_available(self, choice_mock) -> None:
     ev = EV(0, 10, 10, "", "Session-01", Battery(100, 0, 6.6))
     choice_mock.return_value = "PS-002"
     self.network.plugin(ev)
     self.assertEqual(ev.station_id, "PS-002")
     self.assertIs(self.network.get_ev("PS-002"), ev)