Add shared buffered Serial test helper - #1265
Open
VivienP wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Three driver test modules duplicate Serial buffering, lifecycle stubs and write recording. This adds
pylabrobot.io.testing.fake_serial()and replaces those fixtures in the generic barcode scanner, KBiosystems sealer and Azenta IntelliXcap96 tests.Related to #1235; this is a Serial-first increment.
The helper returns
create_autospec(Serial, instance=True, spec_set=True)without constructing or opening a transport. It provides an instance-local receive buffer, responses appended by a synchronouson_writecallback when writes are awaited, input-buffer reset, async lifecycle no-ops and synchronous timeout access with exception-safe restoration. Reads return immediately; non-positive sizes leave the buffer unchanged, matching pyserial's Windows/POSIX behavior.Sealer command echoes and IntelliXcap STX/ETX framing remain in their test-local callbacks. Command assertions compare complete native
write.await_args_listvalues against literal bytes, including terminators, and checkcall_count == await_count. Existing behavioral tests are retained.Public methods outside the supported profile raise named
NotImplementedErrorexceptions until explicitly configured through the native mock API. The profile includes unsupported file methods inherited from the standard-libraryio.IOBase; the Serial/FTDI inheritance change remains separate. Transport implementation tests retain their existing boundaries. There is no timing simulation, device emulator, assertion DSL or additional transport helper.Validation on Windows with Python 3.12:
python -m pytest: 3212 passed, 0 failed, 1 skipped, 63 warnings in 1047.96 seconds. The skipped module isthe_ghost_touch_tests.py, because optional Pillow (PIL) is absent. Warnings are outside the changed files, including existing deprecations and two unawaited-coroutine warnings in Spark tests.pylabrobot/iosuite: 134 passed, with no skips.python -m ruff check pylabrobot: passed.python -m ruff format --check pylabrobot: all 812 files formatted.python -m mypy pylabrobot: one error in unchangedpylabrobot/thermo_fisher/btx/gemini/X2/the_ghost_touch.py:28, due to missingPIL. Mypy over the five changed files with--follow-imports=silentpasses.Helper tests cover buffer slicing and isolation, callback responses and exceptions, reset behavior, timeout restoration, sync/async method shapes, unsupported methods and native overrides, exact write assertions, and unawaited writes. Negative controls cover wrong command bytes, wrong terminators, extra writes and missing writes. Validation used mocked transports and local test servers; no hardware validation is claimed.