예제 #1
0
    def test_erase_with_wrong_target_id(self):
        eraser = Erase()
        with self.assertRaises(EraseError) as cm:
            eraser.erase(target_id='555', method='simple')

        self.assertEqual(cm.exception.return_code,
                         EXIT_CODE_COULD_NOT_MAP_TARGET_ID_TO_DEVICE)
예제 #2
0
    def test_erase_with_all_no_devices(self, mock_device_mapping):
        mock_device_mapping.return_value = []
        eraser = Erase()
        with self.assertRaises(EraseError) as cm:
            eraser.erase(target_id='all', method='simple')

        self.assertEqual(cm.exception.return_code, EXIT_CODE_COULD_NOT_MAP_TARGET_ID_TO_DEVICE)
예제 #3
0
    def test_erase_failed_serial_port_missing(self, _, mock_device_mapping):
        devices = [{"target_id": "123",
                    "platform_name": "K64F",
                    "mount_point": "/mnt/k64f"}]
        mock_device_mapping.return_value = devices
        eraser = Erase()
        with self.assertRaises(EraseError) as cm:
            eraser.erase(target_id="123", method='simple')

        self.assertEqual(cm.exception.return_code, EXIT_CODE_SERIAL_PORT_MISSING)
예제 #4
0
    def test_erase_with_all_no_devices(self):
        with mock.patch.object(FlasherMbed,
                               "get_available_devices") as mocked_get:
            mocked_get.return_value = []
            eraser = Erase()
            with self.assertRaises(EraseError) as cm:
                eraser.erase(target_id='all', method='simple')

            self.assertEqual(cm.exception.return_code,
                             EXIT_CODE_COULD_NOT_MAP_TARGET_ID_TO_DEVICE)
예제 #5
0
    def test_erase_failed_non_supported_method(self):
        devices = EraseTestCaseHW.erase_allowed_devices
        eraser = Erase()
        for item in devices:
            if item['target_id']:
                with self.assertRaises(EraseError) as cm:
                    eraser.erase(target_id=item['target_id'], method='unknown')

                self.assertEqual(cm.exception.return_code, EXIT_CODE_MISUSE_CMD)
                break
예제 #6
0
    def test_erase_failed_non_supported_devices(self, _, mock_device_mapping):
        devices = [{"target_id": "123",
                    "platform_name": "K64F",
                    "mount_point": "/mnt/k64f",
                    "serial_port": "/dev/uart"}]
        mock_device_mapping.return_value = devices
        eraser = Erase()
        with self.assertRaises(EraseError) as cm:
            eraser.erase(target_id="123", method='simple')

        self.assertEqual(cm.exception.return_code, EXIT_CODE_IMPLEMENTATION_MISSING)
예제 #7
0
 def test_erase_with_all(self):
     eraser = Erase()
     mbeds = mbed_lstools.create()
     device_amount_before = len(mbeds.list_mbeds())
     ret = eraser.erase(target_id='all', method='simple')
     self.assertEqual(ret, 0)
     self.assertEqual(device_amount_before, len(mbeds.list_mbeds()))
예제 #8
0
 def test_erase_with_all_no_devices(self, mock_stdout):
     eraser = Erase()
     ret = eraser.erase(target_id='all', method='simple')
     self.assertEqual(ret, 21)
     if mock_stdout:
         self.assertEqual(
             mock_stdout.getvalue(),
             'Could not map given target_id(s) to available devices\n')
예제 #9
0
 def test_erase_with_target_id_list(self):
     devices = EraseTestCaseHW.erase_allowed_devices
     eraser = Erase()
     ret = None
     for item in devices:
         if item['target_id']:
             ret = eraser.erase(target_id=[item['target_id']], method='simple')
             break
     self.assertEqual(ret, EXIT_CODE_SUCCESS)
예제 #10
0
    def test_erase_failed_mount_point_missing(self, _):
        with mock.patch.object(FlasherMbed,
                               "get_available_devices") as mocked_get:
            devices = [{
                "target_id": "123",
                "platform_name": "K64F",
                "serial_port": "/dev/uart"
            }]
            mocked_get.return_value = devices
            eraser = Erase()
            for item in devices:
                if item['target_id']:
                    with self.assertRaises(EraseError) as cm:
                        eraser.erase(target_id=item['target_id'],
                                     method='simple')

                    self.assertEqual(cm.exception.return_code,
                                     EXIT_CODE_MOUNT_POINT_MISSING)
                    break
예제 #11
0
 def test_erase_with_target_id(self):
     mbeds = mbed_lstools.create()
     devices = mbeds.list_mbeds()
     eraser = Erase()
     ret = None
     for item in devices:
         if item['target_id']:
             ret = eraser.erase(target_id=item['target_id'],
                                method='simple')
             break
     self.assertEqual(ret, 0)
     self.assertEqual(len(devices), len(mbeds.list_mbeds()))
예제 #12
0
    def subcmd_erase_handler(self, args):
        """
        erase command handler
        """
        eraser = Erase()
        if not args.tid:
            msg = "Target_id is missing"
            raise EraseError(message=msg,
                             return_code=EXIT_CODE_TARGET_ID_MISSING)

        ids = self.parse_id_to_devices(args.tid)
        return eraser.erase(target_id=ids,
                            no_reset=args.no_reset,
                            method=args.method)
예제 #13
0
    def subcmd_erase_handler(self, args):
        """
        erase command handler
        """
        eraser = Erase()
        if args.tid:
            ids = self.parse_id_to_devices(args.tid)
            if isinstance(ids, int):
                retcode = ids
            else:
                retcode = eraser.erase(target_id=ids,
                                       no_reset=args.no_reset,
                                       method=args.method)
        else:
            print("Target_id is missing")
            return EXIT_CODE_NO_TARGET_ID

        return retcode
예제 #14
0
    def subcmd_erase_handler(self, args):
        """
        erase command handler
        """
        eraser = Erase()
        if args.tid:
            ids = self.parse_id_to_devices(args.tid)
            if isinstance(ids, int):
                retcode = ids
            else:
                retcode = eraser.erase(target_id=ids,
                                       no_reset=args.no_reset,
                                       method=args.method)
        else:
            msg = "Target_id is missing"
            print(msg)
            raise EraseError(message=msg,
                             return_code=EXIT_CODE_TARGET_ID_MISSING)

        return retcode
예제 #15
0
 def test_erase_with_all(self):
     eraser = Erase()
     ret = eraser.erase(target_id='all', method='simple')
     self.assertEqual(ret, EXIT_CODE_SUCCESS)
예제 #16
0
 def test_erase_with_none(self):
     eraser = Erase()
     ret = eraser.erase(target_id=None, method='simple')
     self.assertEqual(ret, 34)
예제 #17
0
    def test_erase_with_none(self):
        eraser = Erase()
        with self.assertRaises(EraseError) as cm:
            eraser.erase(target_id=None, method='simple')

        self.assertEqual(cm.exception.return_code, EXIT_CODE_TARGET_ID_MISSING)