예제 #1
0
 def test_init_with_invalid_parameter(self, mock_log):
     with self.assertRaises(SystemExit) as se:
         light_controller.LightController()
     mock_log.assert_called_with(
         "Error: getopt error: option -k not recognized")
     self.assertTrue(mock_log.called)
     self.assertEqual(se.exception.code, -1)
예제 #2
0
 def test_init_with_syslog(self, mock_log):
     with self.assertRaises(SystemExit) as se:
         light_controller.LightController()
     mock_log.assert_called_with(
         "ERROR: config file config.json not found.")
     self.assertEqual(se.exception.code, -1)
     self.assertTrue(light_controller.dlogger.use_syslog)
예제 #3
0
    def test_list_projects(self, mock_import_module):
        lc = light_controller.LightController()

        with patch.object(lc.ci, 'list_projects') as mock_ci:
            mock_ci.return_value = ["project1", "project2"]
            projects = lc.list_projects()

        self.assertIsNotNone(projects)
        self.assertEquals(len(projects), 2)
예제 #4
0
 def test_fails_to_write_pid_file_on_non_existing_location(
         self, mock_import_module, mock_log):
     light_controller.LightController()._write_pid(
         '/non-existing/location/pid')
     self.assertFalse(os.path.isfile('/non-existing/location/pid'))
     mock_log.assert_called_with(
         "ERROR: unable to write pid file /non-existing/location/pid: [Errno 2] No such file or directory: \'/non-existing/location/pid\'"
     )
     self.assertTrue(mock_import_module.called)
예제 #5
0
 def test_writes_pid_file(self, mock_import_module):
     light_controller.LightController()._write_pid('/tmp/pid')
     self.assertTrue(mock_import_module.called)
     self.assertTrue(os.path.isfile('/tmp/pid'))
예제 #6
0
 def test_init_successful(self, mock_import_module):
     lc = light_controller.LightController()
     self.assertIsNotNone(lc.conf)
     self.assertEqual(lc.poll_interval_seconds, 3)
     self.assertTrue(mock_import_module.called)
     self.assertIsNotNone(lc.ci)
예제 #7
0
 def test_init_with_invalid_file(self, mock_log):
     with self.assertRaises(SystemExit) as se:
         light_controller.LightController()
     mock_log.assert_called_with(
         "ERROR: config file /pat/to/config.json not found.")
     self.assertEqual(se.exception.code, -1)
예제 #8
0
                        keys = ["wiper_speed"]
                        self.update(message, keys)

                    elif r is self.light_sock:
                        message, _ = self.light_sock.recvfrom(2000)
                        message = message.decode('utf-8')
                        print(message)
                        message = json.loads(message)
                        print(message)
                        keys = ["light"]
                        self.update(message, keys)


communication_device = communication_device.aodv()
#listener = listener.listener()
#mqtt_client=mqtt_client.MQTTClient()
speed_sensor = speed_sensor.SpeedSensor()
wiper_controller = wiper_controller.WiperController(1)
light_controller = light_controller.LightController(1)
headway_sensor = headway_sensor.HeadwaySensor()

V = Vehicle(
    x,
    y,
    communication_device,  #listener,#mqtt_client,
    speed_sensor,
    wiper_controller,
    light_controller,
    headway_sensor)
V.drive()