def test_flash_returns_non_zero_when_target_is_invalid(self, logger): jlink = FlasherJLink(logger) target = {"target_id": "test_target_id"} with self.assertRaises(FlashError) as cm: jlink.flash("test_source", target, "", False) self.assertEqual(cm.exception.return_code, EXIT_CODE_FLASH_FAILED) target = {"jlink_device_name": "test_jlink"} with self.assertRaises(FlashError) as cm: jlink.flash("test_source", target, "", False) self.assertEqual(cm.exception.return_code, EXIT_CODE_FLASH_FAILED)
def test_flash_constructs_correct_args(self, logger): jlink = FlasherJLink(logger) executable = "JLink.exe" if sys.platform.startswith( "win") else "JLinkExe" expected_args = [ executable, "-if", "swd", "-speed", "auto", "-device", "test_jlink", "-SelectEmuBySN", "test_target_id", "-commanderscript", "not_tested" ] # pylint: disable=unused-argument def mock_start(args, exe): self.assertEqual(args[0], expected_args[0]) self.assertEqual(args[1], expected_args[1]) self.assertEqual(args[2], expected_args[2]) self.assertEqual(args[3], expected_args[3]) self.assertEqual(args[4], expected_args[4]) self.assertEqual(args[5], expected_args[5]) self.assertEqual(args[6], expected_args[6]) self.assertEqual(args[7], expected_args[7]) self.assertEqual(args[8], expected_args[8]) self.assertEqual(args[9], expected_args[9]) return 0, "" # pylint: disable=protected-access jlink._start_and_wait_flash = mock_start target = { "jlink_device_name": "test_jlink", "target_id": "test_target_id" } returncode = jlink.flash("test_source", target, None, "", False) self.assertEqual(returncode, 0)
def test_flash_returns_non_zero_when_process_fails(self, logger): jlink = FlasherJLink(logger) # pylint: disable=unused-argument def mock_start(args, exe): return 1, "" # pylint: disable=protected-access jlink._start_and_wait_flash = mock_start target = { "jlink_device_name": "test_jlink", "target_id": "test_target_id" } with self.assertRaises(FlashError) as cm: jlink.flash("test_source", target, "", False) self.assertEqual(cm.exception.return_code, EXIT_CODE_FLASH_FAILED)