@@ -556,7 +556,7 @@ def dbf_field(draw):
556556
557557 return {"name" : name , "field_type" : field_type , "size" : size , "decimal" : decimal }
558558
559- ascii_printable = string .ascii_letters + string .digits + string .punctuation # + " "
559+ ascii_printable = string .ascii_letters + string .digits + string .punctuation + " "
560560
561561def record_value_for_field (name : str , field_type : str , size : int , decimal : int = 0 ):
562562
@@ -590,8 +590,7 @@ def record_value_for_field(name: str, field_type: str, size: int, decimal: int =
590590 raise ValueError (f"Unsupported: { field_type = } " )
591591
592592
593- @composite
594- def dbf_fields_and_records (
593+ def _dbf_fields_and_record_strategy (
595594 draw ,
596595 max_fields = 10 , # In DbfWriter.__init__, max_num_fields: int = 2046,
597596 max_records = 20 ,
@@ -601,6 +600,18 @@ def dbf_fields_and_records(
601600
602601 record_strategy = tuples (* (record_value_for_field (** field ) for field in fields ))
603602
603+ return fields , record_strategy
604+
605+
606+ @composite
607+ def dbf_fields_and_records (
608+ draw ,
609+ max_fields = 10 , # In DbfWriter.__init__, max_num_fields: int = 2046,
610+ max_records = 20 ,
611+ ):
612+
613+ fields , record_strategy = _dbf_fields_and_record_strategy (draw , max_fields , max_records )
614+
604615 records = draw (lists (record_strategy , min_size = 0 , max_size = max_records ))
605616
606617 return fields , records
@@ -634,8 +645,8 @@ def test_dbf_reader_writer_roundtrip(fields_and_records)-> None:
634645 expected = expected .strftime ("%Y%m%d" )
635646 if isinstance (actual , datetime .date ):
636647 actual = actual .strftime ("%Y%m%d" )
637- elif field_type in ("N" , "F" ):
648+ elif field_type in ("N" , "F" ) and decimal >= 1 :
638649 expected = float (format (expected , f".{ decimal } f" ))
639- # elif field_type == "C":
640- # expected = expected.strip()
650+ elif field_type == "C" :
651+ expected = expected .strip ()
641652 assert actual == expected , f"{ actual = } , { expected = } , { field_type = } , { type (actual )= } , { type (expected )= } "
0 commit comments