Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ part of your geospatial project.
### ShpWriter.shape API Tweak (small breaking change).
- Make ShpWriter.shape return shape length in bytes (the
same as for offset) not in 16 bit words.
### Testing
- Include NullShapes in shp round trip test.


## 3.0.13
Expand Down
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ VERSION 3.0.14.dev
2026-06-20
* API Tweak (small breaking change). Make ShpWriter.shape return shape length in bytes
(the same as for offset) not in 16 bit words.
* Include NullShapes in shp round trip test.

VERSION 3.0.13

Expand Down
44 changes: 11 additions & 33 deletions tests/hypothesis_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
zs = one_of(just(0.0), float_nums)
PointsLengths = integers(min_value=1, max_value=8000) # length of points
oid = one_of(none(), integers(min_value=0))
null_shapes = builds(shp.NullShape, oid=oid)
point_2D = builds(shp.Point, x=xs, y=ys, oid=oid)
pointm = builds(
shp.PointM,
Expand Down Expand Up @@ -419,7 +420,7 @@ def test_MultiPatch_roundtrips(
# a Null shape).

shape_codes_names_and_strategies = [
# (0, "Null Shape"),
(0, "Null Shape", null_shapes),
(1, "Point", point_2D),
(3, "PolyLine", polyline),
(5, "Polygon", polygon),
Expand All @@ -437,8 +438,14 @@ def test_MultiPatch_roundtrips(

def code_and_shape_strat_from_triple(t):
x, _name, shapes = t
return tuples(just(x), lists(shapes, min_size = 0, max_size=MAX_NUM_SHAPES)) # Empty shp files are in the esri spec.

return tuples(
just(x),
lists(
one_of(shapes, null_shapes),
min_size = 0, # Empty shp files are in the ESRI spec.
max_size=MAX_NUM_SHAPES,
),
)
codes_and_shapes_strats = [
code_and_shape_strat_from_triple(t)
for t in shape_codes_names_and_strategies
Expand All @@ -460,7 +467,7 @@ def test_shp_reader_writer_roundtrip(codes_and_shapes)-> None:

for actual, expected in itertools.zip_longest(r.shapes(), expected_shapes):

assert isinstance(actual, shp.SHAPE_CLASS_FROM_SHAPETYPE[code_ex])
assert isinstance(actual, (shp.SHAPE_CLASS_FROM_SHAPETYPE[code_ex], shp.NullShape))
assert actual.points_3D == expected.points_3D
# Don't assert actual.oid == expected.oid it's defined by
# actual.oid indicates the order actual was written in, expected.oid
Expand All @@ -484,35 +491,6 @@ def test_shp_reader_writer_roundtrip(codes_and_shapes)-> None:



# SHX_UB = MAX_FILE_SIZE_16bw - 50


# ## Surprisingly slow. Doesn't add enough value to merit waiting for
# @composite
# def positive_ints_with_bounded_sum(
# draw,
# min_x: int = 6,
# upper_bound: int = SHX_UB,
# max_len: int = MAX_NUM_SHAPES,
# ):
# assert min_x >= 1
# assert upper_bound >= max_len
# length = draw(integers(min_value=0, max_value=max_len))
# if length == 0:
# return []

# max_x = upper_bound - (length - 1)
# result = []

# for i in range(length):
# if max_x < min_x :
# break
# x = draw(integers(min_value=min_x, max_value=max_x))
# result.append(x)
# max_x -= x

# return result


@pytest.mark.hypothesis
@given(codes_and_shapes=codes_and_shapes)
Expand Down
Loading