Skip to content

Commit 7c269d7

Browse files
authored
Merge pull request #415 from JamesParrott/Synced_with_PyShp
Include NullShapes in shp round trip test
2 parents 1131113 + cdf2060 commit 7c269d7

3 files changed

Lines changed: 14 additions & 33 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ part of your geospatial project.
9797
### ShpWriter.shape API Tweak (small breaking change).
9898
- Make ShpWriter.shape return shape length in bytes (the
9999
same as for offset) not in 16 bit words.
100+
### Testing
101+
- Include NullShapes in shp round trip test.
100102

101103

102104
## 3.0.13

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ VERSION 3.0.14.dev
33
2026-06-20
44
* API Tweak (small breaking change). Make ShpWriter.shape return shape length in bytes
55
(the same as for offset) not in 16 bit words.
6+
* Include NullShapes in shp round trip test.
67

78
VERSION 3.0.13
89

tests/hypothesis_tests.py

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
zs = one_of(just(0.0), float_nums)
2828
PointsLengths = integers(min_value=1, max_value=8000) # length of points
2929
oid = one_of(none(), integers(min_value=0))
30+
null_shapes = builds(shp.NullShape, oid=oid)
3031
point_2D = builds(shp.Point, x=xs, y=ys, oid=oid)
3132
pointm = builds(
3233
shp.PointM,
@@ -419,7 +420,7 @@ def test_MultiPatch_roundtrips(
419420
# a Null shape).
420421

421422
shape_codes_names_and_strategies = [
422-
# (0, "Null Shape"),
423+
(0, "Null Shape", null_shapes),
423424
(1, "Point", point_2D),
424425
(3, "PolyLine", polyline),
425426
(5, "Polygon", polygon),
@@ -437,8 +438,14 @@ def test_MultiPatch_roundtrips(
437438

438439
def code_and_shape_strat_from_triple(t):
439440
x, _name, shapes = t
440-
return tuples(just(x), lists(shapes, min_size = 0, max_size=MAX_NUM_SHAPES)) # Empty shp files are in the esri spec.
441-
441+
return tuples(
442+
just(x),
443+
lists(
444+
one_of(shapes, null_shapes),
445+
min_size = 0, # Empty shp files are in the ESRI spec.
446+
max_size=MAX_NUM_SHAPES,
447+
),
448+
)
442449
codes_and_shapes_strats = [
443450
code_and_shape_strat_from_triple(t)
444451
for t in shape_codes_names_and_strategies
@@ -460,7 +467,7 @@ def test_shp_reader_writer_roundtrip(codes_and_shapes)-> None:
460467

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

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

485492

486493

487-
# SHX_UB = MAX_FILE_SIZE_16bw - 50
488-
489-
490-
# ## Surprisingly slow. Doesn't add enough value to merit waiting for
491-
# @composite
492-
# def positive_ints_with_bounded_sum(
493-
# draw,
494-
# min_x: int = 6,
495-
# upper_bound: int = SHX_UB,
496-
# max_len: int = MAX_NUM_SHAPES,
497-
# ):
498-
# assert min_x >= 1
499-
# assert upper_bound >= max_len
500-
# length = draw(integers(min_value=0, max_value=max_len))
501-
# if length == 0:
502-
# return []
503-
504-
# max_x = upper_bound - (length - 1)
505-
# result = []
506-
507-
# for i in range(length):
508-
# if max_x < min_x :
509-
# break
510-
# x = draw(integers(min_value=min_x, max_value=max_x))
511-
# result.append(x)
512-
# max_x -= x
513-
514-
# return result
515-
516494

517495
@pytest.mark.hypothesis
518496
@given(codes_and_shapes=codes_and_shapes)

0 commit comments

Comments
 (0)