Beispiel #1
0
    def setUp(self):
        self.uri = uri_helper.uri_from_env(default='radio://0/80/2M/E7E7E7E7E7')

        self.cf_mock = MagicMock(spec=Crazyflie)
        self.cf_mock.connected = Caller()
        self.cf_mock.connection_failed = Caller()
        self.cf_mock.disconnected = Caller()

        self.cf_mock.open_link = AsyncCallbackCaller(
            cb=self.cf_mock.connected,
            args=[self.uri],
            delay=0.2
        ).trigger

        self.close_link_mock = AsyncCallbackCaller(
            cb=self.cf_mock.disconnected,
            args=[self.uri],
            delay=0.2
        )
        self.cf_mock.close_link = self.close_link_mock.trigger

        # Mock the behaviour that param values are updated(downloaded) after connection
        self.param_mock = MagicMock(spec=Param)
        self.param_mock.all_updated = Caller()
        self.cf_mock.param = self.param_mock

        # Register a callback to be called when connected. Use it to trigger a callback
        # to trigger the call to the param.all_updated() callback
        self.cf_mock.connected.add_callback(self._connected_callback)

        self.sut = SyncCrazyflie(self.uri, cf=self.cf_mock)
Beispiel #2
0
    def setUp(self):
        self.uri = 'radio://0/60/2M'

        self.cf_mock = MagicMock(spec=Crazyflie)
        self.cf_mock.connected = Caller()
        self.cf_mock.connection_failed = Caller()
        self.cf_mock.disconnected = Caller()

        self.cf_mock.open_link = AsyncCallbackCaller(cb=self.cf_mock.connected,
                                                     args=[self.uri],
                                                     delay=0.2).trigger

        self.close_link_mock = AsyncCallbackCaller(
            cb=self.cf_mock.disconnected, args=[self.uri], delay=0.2)
        self.cf_mock.close_link = self.close_link_mock.trigger

        self.sut = SyncCrazyflie(self.uri, self.cf_mock)
Beispiel #3
0
    def test_lost_connection_in_crazyflie_disconnects(self):
        # Fixture
        self.sut.connect()

        # Test
        AsyncCallbackCaller(cb=self.cf_mock.disconnected,
                            args=['Some uri']).call_and_wait()

        # Assert
        self.assertFalse(self.sut.is_connected())
    def test_closed_if_connection_is_lost(self):
        # Fixture
        self.sut.open_link()

        # Test
        AsyncCallbackCaller(cb=self.cf_mock.disconnected,
                            args=[self.uri]).call_and_wait()

        # Assert
        self.assertFalse(self.sut.is_link_open())
Beispiel #5
0
    def setUp(self):
        self.uri = 'radio://0/60/2M'

        self.ed_mock = MagicMock(spec=Espdrone)
        self.ed_mock.connected = Caller()
        self.ed_mock.connection_failed = Caller()
        self.ed_mock.disconnected = Caller()

        self.ed_mock.open_link = AsyncCallbackCaller(cb=self.ed_mock.connected,
                                                     args=[self.uri]).trigger

        self.sut = SyncEspdrone(self.uri, self.ed_mock)
Beispiel #6
0
    def test_that_data_is_received(self):
        # Fixture
        self.sut.connect()

        expected = ('Some ts', 'Some data', 'Some logblock')
        AsyncCallbackCaller(cb=self.log_config_mock.data_received_cb,
                            args=[expected[0], expected[1], expected[2]]
                            ).trigger()

        # Test
        actual = self.sut.__next__()

        # Assert
        self.assertEqual(expected, actual)
Beispiel #7
0
    def test_lost_connection_in_crazyflie_raises_exception_in_iterator(self):
        # Fixture
        self.sut.connect()

        # Note this is not foolproof, the disconnected callback may be called
        # before we are waiting on data. It will raise the same exception
        # though and will pass
        AsyncCallbackCaller(cb=self.cf_mock.disconnected,
                            delay=0.5,
                            args=['Some uri']).trigger()

        # Test
        # Assert
        with self.assertRaises(StopIteration):
            self.sut.__next__()
    def test_failed_open_link_raises_exception(self):
        # Fixture
        expected = 'Some error message'
        self.cf_mock.open_link = AsyncCallbackCaller(
            cb=self.cf_mock.connection_failed, args=[self.uri,
                                                     expected]).trigger

        # Test
        try:
            self.sut.open_link()
        except Exception as e:
            actual = e.args[0]
        else:
            self.fail('Expect exception')

        # Assert
        self.assertEqual(expected, actual)
Beispiel #9
0
 def _connected_callback(self, uri):
     AsyncCallbackCaller(
         cb=self.param_mock.all_updated,
         delay=0.2
     ).trigger()
Beispiel #10
0
 def _connected_callback(self, uri):
     AsyncCallbackCaller(cb=self.cf_mock.fully_connected,
                         args=[self.uri],
                         delay=0.2).trigger()