Ejemplo n.º 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")
Ejemplo 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)
Ejemplo n.º 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")
Ejemplo n.º 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')
Ejemplo 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')
Ejemplo 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")
Ejemplo 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')
Ejemplo n.º 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")
Ejemplo n.º 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")
Ejemplo n.º 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")
Ejemplo 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())
Ejemplo n.º 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")
Ejemplo 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")
Ejemplo n.º 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")
Ejemplo n.º 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")
Ejemplo 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())
Ejemplo n.º 17
0
 def test_parser_invalid(self):
     with self.assertRaises(SystemExit) as context:
         FlasherCLI()
     self.assertEqual(context.exception.code, EXIT_CODE_MISUSE_CMD)
Ejemplo n.º 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')
Ejemplo 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')
Ejemplo 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')
Ejemplo 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)
Ejemplo n.º 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))
Ejemplo n.º 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
Ejemplo n.º 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")
Ejemplo 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")
Ejemplo 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")
Ejemplo 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")
Ejemplo 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)