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)
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)
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()))
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')
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)
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)
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)
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
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)
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()))
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)
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
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
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
def test_erase_with_all(self): eraser = Erase() ret = eraser.erase(target_id='all', method='simple') self.assertEqual(ret, EXIT_CODE_SUCCESS)
def test_erase_with_none(self): eraser = Erase() ret = eraser.erase(target_id=None, method='simple') self.assertEqual(ret, 34)
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)