Пример #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)