예제 #1
0
    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")
예제 #2
0
    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)
예제 #3
0
    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")
예제 #4
0
    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')
예제 #5
0
    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')
예제 #6
0
    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")
예제 #7
0
    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')
예제 #8
0
 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")
예제 #9
0
    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")
예제 #10
0
    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")
예제 #11
0
    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())
예제 #12
0
    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")
예제 #13
0
    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")
예제 #14
0
    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")
예제 #15
0
 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")
예제 #16
0
 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())
예제 #17
0
 def test_parser_invalid(self):
     with self.assertRaises(SystemExit) as context:
         FlasherCLI()
     self.assertEqual(context.exception.code, EXIT_CODE_MISUSE_CMD)
예제 #18
0
 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')
예제 #19
0
 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')
예제 #20
0
 def test_main_version(self, mock_stdout):
     fcli = FlasherCLI(["version"])
     self.assertEqual(fcli.execute(), 0)
     self.assertEqual(mock_stdout.getvalue(), FLASHER_VERSION + '\n')
예제 #21
0
 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)
예제 #22
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))
예제 #23
0
 def test_main(self, mock_stdout):
     with self.assertRaises(SystemExit) as context:
         FlasherCLI([])
     self.assertEqual(context.exception.code, 2)
     if mock_stdout:
         pass
예제 #24
0
 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")
예제 #25
0
 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")
예제 #26
0
 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")
예제 #27
0
 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")
예제 #28
0
    def test_main(self, mock_stdout):
        with self.assertRaises(SystemExit) as context:
            FlasherCLI([])

        self.assertEqual(context.exception.code, EXIT_CODE_MISUSE_CMD)