예제 #1
0
    def test_update_no_lock(self, mock_commands):
        """Verify 'update' can be called without locking."""
        plugin.main(['--update', '--no-lock'])

        assert [
            call.update(root=None,
                        clean=False, force=False, recurse=False, lock=False),
            call.update().__bool__(),  # command status check
        ] == mock_commands.mock_calls
예제 #2
0
    def test_update_recursive(self, mock_commands):
        """Verify 'update' can be called recursively."""
        plugin.main(['--update', '--all'])

        assert [
            call.update(root=None,
                        clean=False, force=False, recurse=True, lock=True),
            call.update().__bool__(),  # command status check
        ] == mock_commands.mock_calls
예제 #3
0
    def test_update_no_lock(self, mock_commands):
        """Verify 'update' can be called without locking."""
        mock_commands.update.__name__ = 'mock'

        plugin.main(['--update', '--no-lock'])

        assert [
            call.update(root=None, depth=None,
                        clean=False, force=False, recurse=False, lock=False),
            call.update().__bool__(),  # command status check
        ] == mock_commands.mock_calls
예제 #4
0
    def test_update_recursive(self, mock_commands):
        """Verify 'update' can be called recursively."""
        mock_commands.update.__name__ = 'mock'

        plugin.main(['--update', '--all'])

        assert [
            call.update(root=None, depth=None,
                        clean=False, force=False, recurse=True, lock=True),
            call.update().__bool__(),  # command status check
        ] == mock_commands.mock_calls
예제 #5
0
    def test_update(self, mock_commands):
        """Verify 'update' can be called with cleaning."""
        mock_commands.update.__name__ = 'mock'

        plugin.main(['--update', '--clean'])

        assert [
            call.update(root=None, depth=None,
                        clean=True, force=False, recurse=False, lock=True),
            call.update().__bool__(),  # command status check
        ] == mock_commands.mock_calls
예제 #6
0
def test_init_download(monkeypatch):
    mocked_api = Mock()
    mocked_rmtree = Mock()
    mocked_url = Mock()
    monkeypatch.setattr('koneko.api.myapi', mocked_api)
    monkeypatch.setattr('koneko.files.dir_not_empty', lambda x: False)
    monkeypatch.setattr('koneko.download.rmtree', mocked_rmtree)
    monkeypatch.setattr('koneko.download.itertools.filterfalse',
                        lambda *a: [mocked_url] * 2)
    monkeypatch.setattr('koneko.download.os.makedirs',
                        lambda *a, **k: True)  # Disable

    mocked_data = Mock()
    mocked_data.all_urls = [Mock()] * 2
    mocked_tracker = Mock()
    download.init_download(mocked_data, mocked_tracker)

    assert mocked_rmtree.call_args_list == [call(mocked_data.download_path)]
    assert mocked_data.method_calls == [call.download_path.is_dir()]
    assert 'page_num' in dir(mocked_data)
    assert 'newnames_with_ext' in dir(mocked_data)

    assert mocked_tracker.method_calls == [call.update(mocked_url)] * 2

    assert mocked_api.method_calls == [
        call.protected_download(mocked_data.all_urls[0],
                                mocked_data.download_path, mocked_url),
        call.protected_download(mocked_data.all_urls[1],
                                mocked_data.download_path, mocked_url)
    ]
예제 #7
0
    def test_update(self):
        """Remove a skill

        Test that the remove method was called on the skill being installed
        and that the new skill was removed from the device's skill state.
        """
        skill_to_update = self.skill_entry_mock()
        skill_to_update.name = 'skill-foo'
        skill_to_update.is_beta = False
        pre_install_hash = device_skill_state_hash(self.msm.device_skill_state)
        with patch('msm.mycroft_skills_manager.time') as time_mock:
            time_mock.time.return_value = 100
            self.msm.update(skill_to_update)

        with open(self.skills_json_path) as skills_json:
            device_skill_state = json.load(skills_json)

        skill_names = [skill['name'] for skill in device_skill_state['skills']]
        self.assertIn('skill-foo', skill_names)

        for skill in self.msm.device_skill_state['skills']:
            if skill['name'] == 'skill-foo':
                self.assertEqual(100, skill['updated'])
        self.assertListEqual([call.update()], skill_to_update.method_calls)
        self.assertNotIn('all_skills', self.msm._cache)
        self.assertIsNone(self.msm._local_skills)
        post_install_hash = device_skill_state_hash(
            self.msm.device_skill_state)
        self.assertNotEqual(pre_install_hash, post_install_hash)
예제 #8
0
    async def test_update_expense(
        self,
        get_repository_mock,
        expense_response_mock,
    ):
        #Arrange
        expense_mock = Mock()
        repository_mock = Mock()
        repository_mock.get_by_id = Mock(return_value=expense_mock)
        get_repository_mock.return_value = repository_mock
        expense_response_mock.from_domain.return_value = 'expense_response'

        #Action
        response = await update_expense('id', 'request')

        #Asserts
        self.assertEqual(response, 'expense_response')
        repository_mock_calls = repository_mock.mock_calls
        self.assertEqual(len(repository_mock_calls), 2)
        repository_mock.assert_has_calls([
            call.get_by_id(Expense, 'id'),
            call.save(expense_mock),
        ])
        expense_mock_calls = expense_mock.mock_calls
        self.assertEqual(len(expense_mock_calls), 1)
        expense_mock.assert_has_calls([call.update('request')])
        expense_response_mock_calls = expense_response_mock.mock_calls
        self.assertEqual(len(expense_response_mock_calls), 1)
        expense_response_mock.assert_has_calls(
            [call.from_domain(expense_mock)])
    def test_process_measurement_calls_predict_then_update_on_ekf_for_subsequent_LASER_measurements(self):
        self._ekf.predict = MagicMock()
        self._ekf.update = MagicMock()

        ekf_sequence = Mock()
        ekf_sequence.attach_mock(self._ekf.predict, 'predict')
        ekf_sequence.attach_mock(self._ekf.update, 'update')

        fusionEKF = FusionEKF(self._ekf, self._tools)

        meas_package = MeasurementPackage(1477010443000000, 
                                          MeasurementPackage.SensorType.LASER,
                                          Matrix([[0.463227], [0.607415]]))
        fusionEKF.process_measurement(meas_package)

        meas_package = MeasurementPackage(1477010443100000, 
                                          MeasurementPackage.SensorType.LASER,
                                          Matrix([[0.968521], [0.40545]]))
        fusionEKF.process_measurement(meas_package)

        expected_R = Matrix([[0.0225, 0],
                             [0, 0.0225]])
        expected_H = Matrix([[1, 0, 0, 0],
			                 [0, 1, 0, 0]])

        self.assertEqual(self._ekf._R.value, expected_R.value)
        self.assertEqual(self._ekf._H.value, expected_H.value)

        assert ekf_sequence.mock_calls == [call.predict(), call.update(Matrix([[0.968521], [0.40545]]))]
예제 #10
0
    def test_update_skip_changes(self, mock_commands):
        """Verify the 'update' command with skip changes option."""
        mock_commands.update.__name__ = 'mock'

        plugin.main(['--update', '--skip-changes'])

        assert [
            call.update(
                root=None,
                depth=None,
                clean=False,
                force=False,
                recurse=False,
                lock=True,
                skip_changes=True,
            ),
            call.update().__bool__(),  # command status check
        ] == mock_commands.mock_calls
예제 #11
0
    def test_update(self, mock_commands):
        """Verify 'update' can be called with cleaning."""
        mock_commands.update.__name__ = 'mock'

        plugin.main(['--update', '--clean'])

        assert [
            call.update(
                root=None,
                depth=None,
                clean=True,
                force=False,
                recurse=False,
                lock=True,
                skip_changes=False,
            ),
            call.update().__bool__(),  # command status check
        ] == mock_commands.mock_calls
예제 #12
0
 def test_report_download_finished(self, _error, _info, _confirm, tqdm, _position_after_bars):
     items = [NonCallableMagicMock(), NonCallableMagicMock()]
     tqdm.side_effect = items
     with thespiae.cli.CLI('thespiae') as ui:
         ui.feedback.confirm_operations([DownloadSpec(name='test'), DownloadSpec(name='test2')], [], [])
         ui.feedback.report_entry_download_initiated(DownloadSpec(name='test'))
         ui.feedback.report_entry_download_initiated(DownloadSpec(name='test2'))
         ui.feedback.report_entry_download_started(DownloadSpec(name='test'), 5)
         ui.feedback.report_entry_download_started(DownloadSpec(name='test2'), 10)
         ui.feedback.report_entry_download_progress(DownloadSpec(name='test'), 5)
         ui.feedback.report_entry_download_progress(DownloadSpec(name='test2'), 10)
         ui.feedback.report_download_finished()
     _info.assert_called()
     _error.assert_not_called()
     _confirm.assert_called()
     self.assertEqual(tqdm.call_count, 2)
     _position_after_bars.assert_called_once_with(2)
     self.assertSequenceEqual(items[0].method_calls, [call.refresh(), call.update(5), call.refresh(), call.close()])
     self.assertSequenceEqual(items[1].method_calls, [call.refresh(), call.update(10), call.refresh(), call.close()])
예제 #13
0
def test_async_download_no_rename(monkeypatch, tmp_path):
    mocked_url = Mock()
    mocked_tracker = Mock()
    mocked_api = Mock()
    monkeypatch.setattr('koneko.api.myapi', mocked_api)

    download.async_download_no_rename(tmp_path, [mocked_url] * 2,
                                      mocked_tracker)

    assert mocked_tracker.method_calls == [call.update(None)] * 2
    assert mocked_api.method_calls == [
        call.protected_download(mocked_url, tmp_path, None)
    ] * 2
    assert tmp_path.exists()
 def test_delete_not_in_urls(self, mock_client, urls):
     """--delete-not-mentioned deletes these resources before crawling."""
     mock_client.assert_main_calls(
        ["--delete-not-mentioned", "server-url"] + urls,
        [call.delete_resources_not_from(urls), call.update(urls)])
 def test_delete_all(self, mock_client):
     """--delete-all deletes all resources before the crawling."""
     mock_client.assert_main_calls(["--delete-all", "server-url"], [call.delete_resources(), call.update([])])
 def test_only_update_is_default(self, mock_client):
     """By default only the update function is called."""
     mock_client.assert_main_calls(["server-url"], [call.update([])])