Skip to content

Fix newline handling in BYTES directive#225

Merged
MatthieuDartiailh merged 3 commits into
pyvisa:mainfrom
BT8298:bytes
Jun 22, 2026
Merged

Fix newline handling in BYTES directive#225
MatthieuDartiailh merged 3 commits into
pyvisa:mainfrom
BT8298:bytes

Conversation

@BT8298

@BT8298 BT8298 commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Fixes the BYTES directive introduced in #220 not handling newline characters properly.

@codecov

codecov Bot commented Jun 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.78%. Comparing base (91f0897) to head (da572f8).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #225   +/-   ##
=======================================
  Coverage   86.78%   86.78%           
=======================================
  Files          19       19           
  Lines        1052     1052           
  Branches      114      114           
=======================================
  Hits          913      913           
  Misses        104      104           
  Partials       35       35           
Flag Coverage Δ
unittests 86.78% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

("BYTES(\xaa\x55\x00\x02\x08\x01\xf4)", b"\xaa\x55\x00\x02\x08\x01\xf4"),
# "\x0a" == "\n"
(
"BYTES(\xaa\x55\x00\x03\x08\x0a\xb0\x3a)",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could one directly use \n ?

@BT8298 BT8298 Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it works when replacing \x0a with \n in the test case. I just committed that new test case. However, since to_bytes is evaluated on internal python objects after the yaml is parsed and loaded (at least by my understanding), the yaml loader could potentially mangle \n escapes as it reads the file. To be absolutely sure, passing in a yaml device definition file as part of the test would be required. Is it worth doing that, or just "trust" the yaml loader to not have unexpected behavior?

BT8298 and others added 2 commits June 22, 2026 13:23
The directive parser would not match any BYTES directive with a newline
character in it due to regex dot pattern not matching newline by
default.
@MatthieuDartiailh MatthieuDartiailh merged commit 4f3ff24 into pyvisa:main Jun 22, 2026
17 checks passed
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.

2 participants