From 5386fdcd91ae49cc0a3fa1d4fe51f7878aa3ac93 Mon Sep 17 00:00:00 2001 From: James Parrott <80779630+JamesParrott@users.noreply.github.com> Date: Mon, 22 Jun 2026 09:41:29 +0100 Subject: [PATCH] Improve property tests / fix test bugs. Don't coerce to float if decimal == 0. Allow whitespace in test alphabet, but mimick .strip() (account for Issue #418 ) https://github.com/GeospatialPython/pyshp/issues/418) --- tests/hypothesis_tests.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/tests/hypothesis_tests.py b/tests/hypothesis_tests.py index 7a7ebe3..c0f89cd 100644 --- a/tests/hypothesis_tests.py +++ b/tests/hypothesis_tests.py @@ -556,7 +556,7 @@ def dbf_field(draw): return {"name": name, "field_type": field_type, "size": size, "decimal": decimal} -ascii_printable = string.ascii_letters + string.digits + string.punctuation #+ " " +ascii_printable = string.ascii_letters + string.digits + string.punctuation + " " def record_value_for_field(name: str, field_type: str, size: int, decimal: int = 0): @@ -590,8 +590,7 @@ def record_value_for_field(name: str, field_type: str, size: int, decimal: int = raise ValueError(f"Unsupported: {field_type=}") -@composite -def dbf_fields_and_records( +def _dbf_fields_and_record_strategy( draw, max_fields=10, # In DbfWriter.__init__, max_num_fields: int = 2046, max_records=20, @@ -601,6 +600,18 @@ def dbf_fields_and_records( record_strategy = tuples(*(record_value_for_field(**field) for field in fields)) + return fields, record_strategy + + +@composite +def dbf_fields_and_records( + draw, + max_fields=10, # In DbfWriter.__init__, max_num_fields: int = 2046, + max_records=20, + ): + + fields, record_strategy = _dbf_fields_and_record_strategy(draw, max_fields, max_records) + records = draw(lists(record_strategy, min_size=0, max_size=max_records)) return fields, records @@ -634,8 +645,8 @@ def test_dbf_reader_writer_roundtrip(fields_and_records)-> None: expected = expected.strftime("%Y%m%d") if isinstance(actual, datetime.date): actual = actual.strftime("%Y%m%d") - elif field_type in ("N", "F"): + elif field_type in ("N", "F") and decimal >= 1: expected = float(format(expected, f".{decimal}f")) - # elif field_type == "C": - # expected = expected.strip() + elif field_type == "C": + expected = expected.strip() assert actual == expected, f"{actual=}, {expected=}, {field_type=}, {type(actual)=}, {type(expected)=}"