def test_erase_tid_missing(self, mock_stdout): fcli = FlasherCLI(["erase"]) with self.assertRaises(EraseError) as cm: fcli.execute() self.assertEqual(cm.exception.return_code, EXIT_CODE_TARGET_ID_MISSING) self.assertEqual(mock_stdout.getvalue(), "Target_id is missing\n")
def test_erase_wrong_tid_with_device(self, mock_stdout): fcli = FlasherCLI(["erase", "--tid", "555"]) with self.assertRaises(GeneralFatalError) as cm: fcli.execute() self.assertEqual(cm.exception.return_code, EXIT_CODE_COULD_NOT_MAP_DEVICE)
def test_erase_tid_missing(self): fcli = FlasherCLI(["erase"]) with self.assertRaises(EraseError) as cm: fcli.execute() self.assertEqual(cm.exception.return_code, EXIT_CODE_TARGET_ID_MISSING) self.assertEqual(cm.exception.message, "Target_id is missing")
def test_file_not_given(self, mock_stdout): fcli = FlasherCLI(["flash", "-i", None, "--tid", "target"]) with self.assertRaises(FlashError) as cm: fcli.execute() self.assertEqual(cm.exception.return_code, EXIT_CODE_FILE_MISSING) self.assertEqual(mock_stdout.getvalue(), 'File is missing\n')
def test_file_does_not_exist(self, mock_stdout): fcli = FlasherCLI(["flash", "-i", "None", "--tid", "target"]) with self.assertRaises(FlashError) as cm: fcli.execute() self.assertEqual(cm.exception.return_code, EXIT_CODE_FILE_MISSING) self.assertEqual(mock_stdout.getvalue(), 'Could not find given file: None\n')
def test_tid_missing(self, mock_stdout): bin_path = os.path.join('test', 'helloworld.bin') fcli = FlasherCLI(["flash", "-i", bin_path, "-t", "K64F"]) with self.assertRaises(FlashError) as cm: fcli.execute() self.assertEqual(cm.exception.return_code, EXIT_CODE_TARGET_ID_MISSING) self.assertEqual(mock_stdout.getvalue(), "Target_id is missing\n")
def test_file_not_given(self): fcli = FlasherCLI(["flash", "-i", None, "--tid", "target"]) with self.assertRaises(FlashError) as cm: fcli.execute() self.assertEqual(cm.exception.return_code, EXIT_CODE_FILE_MISSING) self.assertEqual(cm.exception.message, 'File to be flashed was not given')
def test_erase_wrong_tid_with_device(self, mock_stdout): fcli = FlasherCLI(["erase", "--tid", "555"]) self.assertEqual(fcli.execute(), 25) six.assertRegex(self, mock_stdout.getvalue(), r"Could not find given target_id from attached devices" r"\nAvailable target_ids:\n\[(\'[0-9a-fA-F]+\')" r"(,\s\'[0-9a-fA-F]+\')*\]", "Regex match failed")
def test_reset_all(self, mock_device_mapping): fcli = FlasherCLI(["reset", "--tid", "all"]) mock_device_mapping.return_value = [] with self.assertRaises(GeneralFatalError) as cm: fcli.execute() self.assertEqual(cm.exception.return_code, EXIT_CODE_DEVICES_MISSING) self.assertEqual(cm.exception.message, "Could not find any connected device")
def test_erase_wrong_tid(self, mock_stdout, mock_device_mapping): fcli = FlasherCLI(["erase", "--tid", "555"]) mock_device_mapping.return_value = [] with self.assertRaises(GeneralFatalError) as cm: fcli.execute() self.assertEqual(cm.exception.return_code, EXIT_CODE_DEVICES_MISSING) self.assertEqual(mock_stdout.getvalue(), "Could not find any connected device\n")
def test_wrong_platform(self, mock_stdout): bin_path = os.path.join('test', 'helloworld.bin') fcli = FlasherCLI( ["flash", "-i", bin_path, "-t", "K65G", "--tid", "target"]) with self.assertRaises(FlashError) as cm: fcli.execute() self.assertEqual(cm.exception.return_code, EXIT_CODE_NOT_SUPPORTED_PLATFORM) self.assertIn("Not supported platform: K65G", mock_stdout.getvalue())
def test_wrong_tid(self, mock_stdout, mock_device_mapping): bin_path = os.path.join('test', 'helloworld.bin') fcli = FlasherCLI( ["flash", "-i", bin_path, "--tid", "555", "-t", "K64F"]) mock_device_mapping.return_value = [] with self.assertRaises(FlashError) as cm: fcli.execute() self.assertEqual(cm.exception.return_code, EXIT_CODE_DEVICES_MISSING) self.assertEqual(mock_stdout.getvalue(), "Could not find any connected device\n")
def test_erase_wrong_tid_with_device(self, mock_stdout): fcli = FlasherCLI(["erase", "--tid", "555"]) with self.assertRaises(GeneralFatalError) as cm: fcli.execute() self.assertEqual(cm.exception.return_code, EXIT_CODE_COULD_NOT_MAP_DEVICE) six.assertRegex(self, mock_stdout.getvalue(), r"Could not find given target_id from attached devices" r"\nAvailable target_ids:\n\[u?(\'[0-9a-fA-F]+\')" r"(,\su?\'[0-9a-fA-F]+\')*\]", "Regex match failed")
def test_wrong_platform(self, mock_device_mapping): mock_device_mapping.return_value = [] bin_path = os.path.join('test', 'helloworld.bin') fcli = FlasherCLI( ["flash", "-i", bin_path, "-t", "K65G", "--tid", "target"]) with self.assertRaises(FlashError) as cm: fcli.execute() self.assertEqual(cm.exception.return_code, EXIT_CODE_NOT_SUPPORTED_PLATFORM) self.assertIn(cm.exception.message, "Platform K65G not supported")
def test_tid_missing(self, mock_stdout): bin_path = os.path.join('test', 'helloworld.bin') fcli = FlasherCLI(["flash", "-i", bin_path, "-t", "K64F"]) self.assertEqual(fcli.execute(), 15) self.assertEqual(mock_stdout.getvalue(), "Target_id is missing\n")
def test_wrong_platform(self, mock_stdout): bin_path = os.path.join('test', 'helloworld.bin') fcli = FlasherCLI(["flash", "-i", bin_path, "-t", "K65G"]) self.assertEqual(fcli.execute(), 10) self.assertIn("Not supported platform: K65G", mock_stdout.getvalue())
def test_parser_invalid(self): with self.assertRaises(SystemExit) as context: FlasherCLI() self.assertEqual(context.exception.code, EXIT_CODE_MISUSE_CMD)
def test_file_does_not_exist(self, mock_stdout): fcli = FlasherCLI(["flash", "-i", "None"]) self.assertEqual(fcli.execute(), 5) self.assertEqual(mock_stdout.getvalue(), 'Could not find given file: None\n')
def test_file_not_given(self, mock_stdout): fcli = FlasherCLI(["flash", "-i", None]) self.assertEqual(fcli.execute(), 5) self.assertEqual(mock_stdout.getvalue(), 'File is missing\n')
def test_main_version(self, mock_stdout): fcli = FlasherCLI(["version"]) self.assertEqual(fcli.execute(), 0) self.assertEqual(mock_stdout.getvalue(), FLASHER_VERSION + '\n')
def test_main_verboses(self, mock_stdout): fcli = FlasherCLI(["-v", "version"]) self.assertEqual(fcli.execute(), 0) self.assertIsNot(len("\n".split(mock_stdout.getvalue())), 0)
def test_main_version(self, mock_stdout): fcli = FlasherCLI(["version"]) self.assertEqual(fcli.execute(), EXIT_CODE_SUCCESS) r_match = re.compile(r"^\d+\.\d+\.\d+$") value = mock_stdout.getvalue() self.assertTrue(r_match.match(value))
def test_main(self, mock_stdout): with self.assertRaises(SystemExit) as context: FlasherCLI([]) self.assertEqual(context.exception.code, 2) if mock_stdout: pass
def test_erase_wrong_tid(self, mock_stdout): fcli = FlasherCLI(["erase", "--tid", "555"]) self.assertEqual(fcli.execute(), 20) self.assertEqual(mock_stdout.getvalue(), "Could not find any connected device\n")
def test_erase_tid_missing(self, mock_stdout): fcli = FlasherCLI(["erase"]) self.assertEqual(fcli.execute(), 15) self.assertEqual(mock_stdout.getvalue(), "Target_id is missing\n")
def test_reset_all(self, mock_stdout): fcli = FlasherCLI(["reset", "--tid", "all"]) self.assertEqual(fcli.execute(), 20) self.assertEqual(mock_stdout.getvalue(), "Could not find any connected device\n")
def test_wrong_tid(self, mock_stdout): bin_path = os.path.join('test', 'helloworld.bin') fcli = FlasherCLI(["flash", "-i", bin_path, "--tid", "555", "-t", "K64F"]) self.assertEqual(fcli.execute(), 20) self.assertEqual(mock_stdout.getvalue(), "Could not find any connected device\n")
def test_main(self, mock_stdout): with self.assertRaises(SystemExit) as context: FlasherCLI([]) self.assertEqual(context.exception.code, EXIT_CODE_MISUSE_CMD)