Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions pyocd/subcommands/pack_cmd.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# pyOCD debugger
# Copyright (c) 2021 Chris Reed
# Copyright (c) 2026 Arm Limited
# Copyright (c) 2026 Giridhar
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -189,6 +190,9 @@ def invoke(self) -> int:
# Look for matching part numbers.
matches = self._get_matches(cache)

if not matches:
return 1

if matches:
# Get the list of installed pack targets.
installed_targets = pack_target.ManagedPacks.get_installed_targets(cache=cache)
Expand Down Expand Up @@ -251,6 +255,9 @@ def invoke(self) -> int:
# Look for matching part numbers.
matches = self._get_matches(cache)

if not matches:
return 1

if matches:
devices = [cache.index[dev] for dev in matches]
packs = cache.packs_for_devices(devices)
Expand Down Expand Up @@ -339,6 +346,9 @@ def invoke(self) -> int:

matches = self._get_matches(cache)

if not matches:
return 1

if self._args.find_devices:
# Get the list of installed pack targets.
installed_targets = pack_target.ManagedPacks.get_installed_targets(cache=cache)
Expand Down
81 changes: 81 additions & 0 deletions test/unit/test_pack_cmd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# pyOCD debugger
# Copyright (c) 2026 Giridhar
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from argparse import Namespace
from types import SimpleNamespace

import pytest

from pyocd.subcommands.pack_cmd import (
PackFindSubcommand,
PackInstallSubcommand,
PackSubcommand,
)


@pytest.fixture
def cache():
return SimpleNamespace(index={"KnownDevice": {}})


def test_pack_find_returns_error_when_no_device_matches(monkeypatch, cache):
command = PackFindSubcommand(Namespace(
patterns=["MissingDevice"],
update=False,
clean=False,
no_header=False,
verbose=0,
quiet=0,
))
monkeypatch.setattr(command, "_get_cache", lambda: cache)

assert command.invoke() == 1


def test_pack_install_returns_error_when_no_device_matches(monkeypatch, cache):
command = PackInstallSubcommand(Namespace(
patterns=["MissingDevice"],
update=False,
clean=False,
no_download=False,
verbose=0,
quiet=0,
))
monkeypatch.setattr(command, "_get_cache", lambda: cache)

assert command.invoke() == 1


@pytest.mark.parametrize(("find_devices", "install_devices"), [
(["MissingDevice"], None),
(None, ["MissingDevice"]),
])
def test_deprecated_pack_options_return_error_when_no_device_matches(
monkeypatch, cache, find_devices, install_devices):
command = PackSubcommand(Namespace(
clean=False,
update=False,
show=False,
find_devices=find_devices,
install_devices=install_devices,
no_download=False,
no_header=False,
verbose=0,
quiet=0,
))
monkeypatch.setattr(command, "_get_cache", lambda: cache)

assert command.invoke() == 1