diff --git a/pyocd/core/helpers.py b/pyocd/core/helpers.py index e973e0d20..068c61e3e 100644 --- a/pyocd/core/helpers.py +++ b/pyocd/core/helpers.py @@ -282,8 +282,8 @@ def _print_probe_list(probes: Sequence["DebugProbe"]) -> None: pt.align = 'l' pt.header = True pt.border = True - pt.hrules = prettytable.HEADER - pt.vrules = prettytable.NONE + pt.hrules = getattr(prettytable, "HRuleStyle", prettytable).HEADER + pt.vrules = getattr(prettytable, "VRuleStyle", prettytable).NONE for index, probe in enumerate(probes): try: diff --git a/pyocd/subcommands/base.py b/pyocd/subcommands/base.py index 03ab43d15..ae204281f 100644 --- a/pyocd/subcommands/base.py +++ b/pyocd/subcommands/base.py @@ -168,8 +168,8 @@ def _get_pretty_table(self, fields: List[str], header: bool = None) -> prettytab else: pt.header = True pt.border = True - pt.hrules = prettytable.HEADER - pt.vrules = prettytable.NONE + pt.hrules = getattr(prettytable, "HRuleStyle", prettytable).HEADER + pt.vrules = getattr(prettytable, "VRuleStyle", prettytable).NONE return pt def _modified_option_defaults(self) -> Dict[str, Any]: diff --git a/test/unit/test_table_rendering.py b/test/unit/test_table_rendering.py new file mode 100644 index 000000000..e1253f32d --- /dev/null +++ b/test/unit/test_table_rendering.py @@ -0,0 +1,46 @@ +# pyOCD debugger +# Copyright (c) 2026 Solarboaters +# 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. + +import argparse +from types import SimpleNamespace + +import pytest + +from pyocd.core.helpers import ConnectHelper +from pyocd.subcommands.base import SubcommandBase + + +@pytest.mark.parametrize("header", [True, False]) +def test_subcommand_table_rendering(header): + command = SubcommandBase(argparse.Namespace(no_header=not header)) + table = command._get_pretty_table(["Name", "Value"]) + table.add_row(["sample", "42"]) + rendered = table.get_string() + assert "sample" in rendered + assert "42" in rendered + assert ("Name" in rendered) == header + assert "|" not in rendered + + +def test_probe_selection_table_rendering(capsys): + probe = SimpleNamespace(associated_board_info=None, + description="Example probe", unique_id="example-123") + ConnectHelper._print_probe_list([probe]) + rendered = capsys.readouterr().out + assert "Example probe" in rendered + assert "example-123" in rendered + assert "Probe/Board" in rendered + assert "|" not in rendered