示例#1
0
    def test_run_fail_file(self, mock_stdout):
        mbeds = mbed_lstools.create()
        targets = mbeds.list_mbeds()
        mount_point = None
        target_to_test = None
        fail_txt_path = os.path.join('test', 'failing.txt')
        for target in targets:
            if target['platform_name'] == 'K64F':
                if 'target_id' in target and 'mount_point' in target:
                    target_to_test = target
                    mount_point = target['mount_point']
                    break

        with open(fail_txt_path, 'w') as new_file:
            new_file.write("0000000000000000000000000000000000")

        with self.assertRaises(FlashError) as cm:
            flasher = FlasherMbed()
            flasher.flash(source=fail_txt_path,
                          target=target_to_test,
                          method='simple',
                          no_reset=False)

        if platform.system() == 'Windows':
            os.system('del %s' % os.path.join(mount_point, 'failing.txt'))
            os.system('del %s' % os.path.join(os.getcwd(), fail_txt_path))
        else:
            os.system('rm %s' % os.path.join(mount_point, 'failing.txt'))
            os.system('rm %s' % os.path.join(os.getcwd(), fail_txt_path))

        self.assertEqual(cm.exception.return_code,
                         EXIT_CODE_FILE_STILL_PRESENT)
示例#2
0
    def test_retries_on_os_error(self, mock_copy_file, mock_reset_board,
                                 mock_refresh_target, mock_sleep):
        target = {"target_id": "a", "mount_point": ""}
        mock_copy_file.side_effect = OSError("")
        mock_reset_board.return_value = True
        mock_refresh_target.return_value = target
        flasher = FlasherMbed()

        with self.assertRaises(FlashError) as cm:
            flasher.flash(source="",
                          target=target,
                          method="simple",
                          no_reset=False)

        self.assertEqual(cm.exception.return_code, EXIT_CODE_OS_ERROR)
        self.assertEqual(mock_copy_file.call_count, 5)
示例#3
0
 def test_run_fail_file(self, mock_stdout):
     mbeds = mbed_lstools.create()
     targets = mbeds.list_mbeds()
     mount_point = None
     target_to_test = None
     fail_txt_path = os.path.join('test', 'failing.txt')
     for target in targets:
         if target['platform_name'] == 'K64F':
             if 'target_id' in target and 'mount_point' in target:
                 target_to_test = target
                 mount_point = target['mount_point']
                 break
     if target_to_test:
         flasher = FlasherMbed()
         flasher.FLASHING_VERIFICATION_TIMEOUT = 2
         with open(fail_txt_path, 'w') as new_file:
             new_file.write("0000000000000000000000000000000000")
         ret = flasher.flash(source=fail_txt_path,
                             target=target_to_test,
                             method='simple',
                             no_reset=False)
         if platform.system() == 'Windows':
             os.system('del %s' % os.path.join(mount_point, 'failing.txt'))
             os.system('del %s' % os.path.join(os.getcwd(), fail_txt_path))
         else:
             os.system('rm %s' % os.path.join(mount_point, 'failing.txt'))
             os.system('rm %s' % os.path.join(os.getcwd(), fail_txt_path))
         self.assertEqual(ret, -15)
     if mock_stdout:
         pass
示例#4
0
    def test_does_not_retry_on_daplink_user_error(self, mock_copy_file,
                                                  mock_reset_board,
                                                  mock_refresh_target):
        target = {"target_id": "a", "mount_point": ""}
        mock_copy_file.side_effect = FlashError(
            message="", return_code=EXIT_CODE_DAPLINK_USER_ERROR)
        mock_reset_board.return_value = True
        mock_refresh_target.return_value = target
        flasher = FlasherMbed()

        with self.assertRaises(FlashError) as cm:
            flasher.flash(source="",
                          target=target,
                          method="simple",
                          no_reset=False)

        self.assertEqual(cm.exception.return_code,
                         EXIT_CODE_DAPLINK_USER_ERROR)
        self.assertEqual(mock_copy_file.call_count, 1)
示例#5
0
    def test_flash_with_target_filename(self, copy_file, mock_refresh_target,
                                        mock_wait_for_file_disappear):
        flasher = FlasherMbed()
        flasher.return_value = True
        copy_file.return_value = True
        target = {"target_id": "a", "mount_point": ""}
        mock_refresh_target.return_value = target
        flasher.verify_flash_success = mock.MagicMock()
        flasher.verify_flash_success.return_value = EXIT_CODE_SUCCESS
        mock_wait_for_file_disappear.return_value = {
            "target_id": "a",
            "mount_point": ""
        }
        flasher.flash(source=__file__,
                      target=target,
                      method='simple',
                      no_reset=True,
                      target_filename="test.ext")

        target_filename = os.path.abspath(
            os.path.join(os.path.dirname(__file__), "../..", "test.ext"))
        copy_file.assert_called_once_with(__file__, target_filename)