def test_get_by_name_raises_target_error_when_target_attr_collection_fails(self, mock_target_attrs): target_name = "Target" targets_json_file_path = "targets.json" mock_target_attrs.side_effect = TargetAttributesError with self.assertRaises(TargetError): get_target_by_name(target_name, targets_json_file_path)
def test_get_by_name_raises_target_error_when_target_json_not_found(self, mock_target_attrs): target_name = "Target" targets_json_file_path = "not-targets.json" mock_target_attrs.side_effect = FileNotFoundError with self.assertRaises(TargetError): get_target_by_name(target_name, targets_json_file_path)
def test_get_by_name(self, mock_target_attrs): target_name = "Target" targets_json_file_path = "targets.json" result = get_target_by_name(target_name, targets_json_file_path) self.assertEqual(result, mock_target_attrs.return_value) mock_target_attrs.assert_called_once_with(targets_json_file_path, target_name)
def test_get_by_name(self, MbedProgram, MockTarget): target_name = "Target" path_to_mbed_program = "my-program" result = get_target_by_name(target_name, path_to_mbed_program) self.assertEqual(result, MockTarget.from_targets_json.return_value) MockTarget.from_targets_json.assert_called_once_with( target_name, MbedProgram.from_existing.return_value.mbed_os.targets_json_file, ) MbedProgram.from_existing.assert_called_once_with( pathlib.Path(path_to_mbed_program))