Add property-based testing with Hypothesis#636
Open
gijzelaerr wants to merge 3 commits intomasterfrom
Open
Conversation
Add 48 property-based tests using Hypothesis covering: - Roundtrip tests for all getter/setter pairs (integers, floats, strings, dates) - Roundtrip tests for S7 data type encode/decode - TPKT/COTP frame structure validation - S7 PDU structure validation - Fuzz tests for robustness against malformed input Bugs found and fixed: - set_date: used signed int16 (>h) for days offset, overflows for dates after ~2079. Fixed to unsigned int16 (>H). - set_tod: used float arithmetic (total_seconds() * 1000) causing precision loss. Fixed to use integer arithmetic on timedelta components. Known issue documented (not fixed): - wstring get/set uses character count but UTF-16-BE surrogate pairs for supplementary characters (codepoint > 0xFFFF) need 4 bytes per character. Closes #629 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
PLCs only support BMP characters (U+0000–U+FFFF) in WSTRING. Characters above U+FFFF require UTF-16 surrogate pairs (4 bytes) but the WSTRING length field counts 2-byte code units, causing data corruption. Validate input and raise ValueError for non-BMP characters, matching the reference PLC implementation behavior. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
get_dtl was reading only byte 8 as a raw integer for microseconds, but the DTL format stores nanoseconds as a 4-byte big-endian uint32 in bytes 8-11. This fix reads the full field and converts ns to us. Also removes unnecessary KeyError catch from PDU fuzz test. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
49cdc4e to
5f3eba2
Compare
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
set_dateoverflow: used signed>hfor days offset from 1990-01-01, which overflows for dates after ~2079. Fixed to unsigned>H.set_todprecision loss: usedint(total_seconds() * 1000)which loses precision due to float arithmetic. Fixed to integer arithmetic ontimedeltacomponents.set_wstring/get_wstringuse character count, not UTF-16 code unit count.Test coverage
Run with:
pytest -m hypothesisTest plan
pytest -m hypothesismarker worksCloses #629
🤖 Generated with Claude Code