Skip to content

Commit cc82ec8

Browse files
committed
Add test for iterRecords new start and stop args; ensure same Records returned as from Reader.record
1 parent 74cf6dd commit cc82ec8

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

test_shapefile.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44

55
import datetime
6+
import itertools
67
import json
78
import os.path
89

@@ -968,10 +969,33 @@ def test_record_oid():
968969
for i, record in enumerate(sf.iterRecords()):
969970
assert record.oid == i
970971

972+
971973
for i, shaperec in enumerate(sf.iterShapeRecords()):
972974
assert shaperec.record.oid == i
973975

974976

977+
def test_iterRecords_start_stop():
978+
"""
979+
Assert that Reader.iterRecords(start, stop)
980+
returns the correct records, as if searched for
981+
by Reader..
982+
"""
983+
984+
985+
with shapefile.Reader("shapefiles/blockgroups") as sf:
986+
987+
N = len(sf)
988+
989+
# Arbitrary selection of start values
990+
for start in [0, 1, 2, 3, 5, 11, 17, 33, 51, 103, 170, 234, 435, 543, N-3, N-2, N-1]:
991+
for stop in range(start, len(sf)):
992+
# test negative indexing from end, as well as
993+
# positive values of stop, and its default
994+
for stop_arg in (stop, stop - len(sf), None):
995+
for record in sf.iterRecords(start = start, stop = stop):
996+
assert record == sf.record(record.oid)
997+
998+
975999
def test_shape_oid():
9761000
"""
9771001
Assert that the shape's oid attribute returns

0 commit comments

Comments
 (0)