Skip to content

Add optional separate viewer rows for each payload length - #2170

Open
Solarboaters wants to merge 2 commits into
hardbyte:mainfrom
Solarboaters:feat/viewer-separate-dlc
Open

Solarboaters wants to merge 2 commits into
hardbyte:mainfrom
Solarboaters:feat/viewer-separate-dlc

Conversation

@Solarboaters

@Solarboaters Solarboaters commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary of Changes

Add opt-in --separate-dlc rows to the CAN viewer. Frames sharing an identifier with different lengths keep their own payload, count and interval, instead of replacing one another. Standard/extended identifiers remain distinct and sorting remains numeric. Default behaviour is unchanged.

Related Issues / Pull Requests

Fixes #1737, following @kgmuzungu's request and suggestion to make this optional.

Type of Change

  • New feature

Checklist

  • Followed the contribution guide; added regression tests and documentation.
  • Added a towncrier news fragment.
  • All checks and tests pass (tox). Equivalent configured commands were run directly: full Python 3.12 suite, plus Black/Ruff/Pylint, all five mypy targets, Sphinx HTML and doctests on Python 3.14. The full tox interpreter/platform matrix was not run.

Validation

Replayed the reported 0x507 CAN FD sequence with lengths 20/24/32/48/20 through CanViewer, checking both the unchanged default single-row behaviour and the opt-in separate rows. The updated test fails when row splitting is forced on regardless of the option. Redundant internal-layout and redraw assertions were removed, and option parsing is covered in the existing parser test.

Current revision: all 10 viewer tests and two subtests pass; full Python 3.12 suite: 730 passed, 142 skipped, 51 subtests passed. Black, Ruff, Pylint and all five mypy targets pass. The earlier revision also passed Python 3.14 viewer tests and documentation builds; those were not rerun locally for this test-only follow-up. Hosted CI is pending on the updated head.

Tests use generated frames and the existing mocked curses screen; no physical ebike/CAN interface or interactive terminal session was tested.

@zariiii9003

Copy link
Copy Markdown
Collaborator

AI Review: Add optional separate viewer rows for each payload length

The --separate-dlc keying is correct: sorting, standard/extended separation, per-row highlighting, redraw and scrolling all behave with tuple keys, and the CLI wiring works. Two test issues remain.

Findings

  • test/test_viewer.py – default behaviour is unguarded. Replacing if self.separate_dlc: with if True: in CanViewer.draw_can_bus_message leaves every test green, so nothing protects the "default behaviour is unchanged" claim. Fix: run the 20/24/32/48/20 sequence once without the option and assert a single row, e.g.
    for separate_dlc, expected in ((False, {20: 1}), (True, {20: 2, 24: 1, 32: 1, 48: 1})):
        with self.subTest(separate_dlc=separate_dlc):
            self.can_viewer.ids = {}
            self.can_viewer.separate_dlc = separate_dlc
            ...  # draw the sequence
            self.assertEqual({r["msg"].dlc: r["count"] for r in self.can_viewer.ids.values()}, expected)
  • test_separate_dlc_preserves_each_length – remove assertions that pin internals or duplicate coverage. The previous_values[key][0] == dlc loop asserts the internal dict layout (and only holds because data=[length] * length), and the redraw_screen() check repeats test_redraw_preserves_receive_statistics without exercising a mode-specific path. The count/row assertions above are enough.
  • test_separate_dlc_option_reaches_viewer – trim to the wiring check. Building a second CanViewer only tests attribute assignment, and assertFalse(self.can_viewer.separate_dlc) adds nothing. Keep the main() → wrapper.call_args.kwargs == {"separate_dlc": True} assertion; move the parser checks (--separate-dlc → True, absent → False) into the existing test_parse_args.

With these changes, removing the tuple key, ignoring the extended flag, always splitting by length, inverting the flag, or dropping the main() argument each still fails a test.

Verdict

request changes

Signed-off-by: Andrew Jessop <354059055+Solarboaters@users.noreply.github.com>
@Solarboaters

Copy link
Copy Markdown
Contributor Author

Updated in 33e851d: the reported sequence now checks both default and separate-DLC behaviour, redundant assertions are removed, and parser checks sit in test_parse_args. Forcing splitting on makes the regression fail; all 10 viewer tests, the full 730-test suite (142 skipped), lint and all five mypy targets pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

viewer with CAN-FD, print packets with variable DLC but same ID in different lines

2 participants