Polish, CI gates, and CLI smoke tests (P1-P8 + C1/C2 + T1/T4)#1
Merged
Conversation
Polish (P1-P8): - P1: extracted _validate_int16 in client.py; write() and write_value() now share the int16/uint16 range-check logic. - P2: time.sleep(0.05) promoted to a named _RETRY_DELAY_SEC constant. - P3: dropped redundant bits[:count] slice in read_coils/read_discretes (_extract_result already trims pymodbus's whole-byte padding). - P4: removed redundant lazy UnsupportedRegisterError import inside Register.from_name. - P5: dropped unreachable try/except around bytes.decode(..., errors="replace"). - P6: built module-level _NAME_INDEX dict for O(1) Register.from_name; preserves historical "first match wins" on ambiguous suffixes and raises at import on canonical/legacy collisions. - P7: documented retry behaviour on every ModbusCommError subclass (which are retried vs deterministic). - P8: exported interpret_raw via __init__.py __all__; CLI imports from the public path now. CI + packaging (C1, C2, T4): - pyproject.toml: dev/test extras (pytest-cov, ruff, mypy); [tool.ruff] (E/F/W/I/UP/B/SIM rule set, py310 target, line-length 100, E501 ignored, B011 ignored in tests); [tool.mypy] gradual-typing config with check_untyped_defs + warn_unreachable + pymodbus override. - .github/workflows/ci.yml: Python 3.10/3.11/3.12 matrix with pip cache, py_compile example.py, ruff lint, mypy type-check, and pytest with --cov term-missing. CLI smoke tests (T1): - tests/test_cli.py: 27 new tests covering _parse_raw_value, _parse_interpreted_value, _format_raw, _format_interpreted (incl. the B5 regression that --interpret no longer emits a misleading hex twin), _resolve_model_arg + --branch DeprecationWarning, and end-to-end main(argv) for list-models, list-registers, and the port/slave guard. Ruff autofixes also normalised imports across the package and rewrote typing.Iterable -> collections.abc.Iterable plus dropped quoted-string forward references under `from __future__ import annotations`. Verification: pytest 179 passed (152 + 27 new), 88% line coverage, ruff clean, mypy clean, python -m py_compile example.py clean. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
Register.from_namescan with an O(1) module-level index, documented retry behaviour on eachModbusCommErrorsubclass, and promotedinterpret_rawto the public surface.dev/testextras +[tool.ruff]+[tool.mypy]config; GitHub Actions matrix now runs Python 3.10/3.11/3.12 with pip cache,py_compile example.py, ruff lint, mypy type-check, and pytest with coverage.tests/test_cli.pywith 27 tests covering parsers, formatters (incl. the B5 hex-twin regression),--branchdeprecation, andmain(argv)forlist-models/list-registers/ port-guard.Ruff autofixes also normalised imports across the package, rewrote
typing.Iterable→collections.abc.Iterable, and removed redundant quoted-string forward references underfrom __future__ import annotations.Test plan
testsworkflow passes on Python 3.10, 3.11, and 3.12ruff check .reports cleanmypy smartpower_modbusreports cleanpython -m py_compile example.pysucceedspytest --cov=smartpower_modbusreports 179 passing and ≥88% line coveragepython -m smartpower_modbus.cli list-modelslists all four SmartPower modelspython -m smartpower_modbus.cli --model SmartPowerGen_2.0 list-registersprints the GEN_2_0 register tableexample.py --port <PORT> --slave <ID>still connects, auto-identifies, and reads telemetryLocal verification (already run)
pytest -q --cov: 179 passed (152 pre-existing + 27 new), 88% line coverageruff check .: cleanmypy smartpower_modbus: cleanpython -m py_compile example.py: clean🤖 Generated with Claude Code