5
5
import datetime
6
6
import json
7
7
import os .path
8
- import sys
9
8
10
- if sys . version_info . major == 3 :
9
+ try :
11
10
from pathlib import Path
11
+ except ImportError :
12
+ # pathlib2 is a dependency of pytest >= 3.7
13
+ from pathlib2 import Path
12
14
13
15
# third party imports
14
16
import pytest
15
17
16
- if sys .version_info .major == 2 :
17
- # required by pytest for python <36
18
- from pathlib2 import Path
19
-
20
18
# our imports
21
19
import shapefile
22
20
@@ -208,7 +206,7 @@ def test_empty_shape_geo_interface():
208
206
"""
209
207
shape = shapefile .Shape ()
210
208
with pytest .raises (Exception ):
211
- shape . __geo_interface__
209
+ getattr ( shape , ' __geo_interface__' )
212
210
213
211
@pytest .mark .parametrize ("typ,points,parts,expected" , geo_interface_tests )
214
212
def test_expected_shape_geo_interface (typ , points , parts , expected ):
@@ -257,17 +255,17 @@ def test_reader_url():
257
255
# test with extension
258
256
url = "https://github.com/nvkelso/natural-earth-vector/blob/master/110m_cultural/ne_110m_admin_0_tiny_countries.shp?raw=true"
259
257
with shapefile .Reader (url ) as sf :
260
- for recShape in sf .iterShapeRecords ():
258
+ for __recShape in sf .iterShapeRecords ():
261
259
pass
262
- assert sf .shp .closed == sf .shx .closed == sf .dbf .closed is True
260
+ assert sf .shp .closed is sf .shx .closed is sf .dbf .closed is True
263
261
264
262
# test without extension
265
263
url = "https://github.com/nvkelso/natural-earth-vector/blob/master/110m_cultural/ne_110m_admin_0_tiny_countries?raw=true"
266
264
with shapefile .Reader (url ) as sf :
267
- for recShape in sf .iterShapeRecords ():
265
+ for __recShape in sf .iterShapeRecords ():
268
266
pass
269
267
assert len (sf ) > 0
270
- assert sf .shp .closed == sf .shx .closed == sf .dbf .closed is True
268
+ assert sf .shp .closed is sf .shx .closed is sf .dbf .closed is True
271
269
272
270
# test no files found
273
271
url = "https://raw.githubusercontent.com/nvkelso/natural-earth-vector/master/README.md"
@@ -278,10 +276,10 @@ def test_reader_url():
278
276
# test reading zipfile from url
279
277
url = "https://github.com/JamesParrott/PyShp_test_shapefile/raw/main/gis_osm_natural_a_free_1.zip"
280
278
with shapefile .Reader (url ) as sf :
281
- for recShape in sf .iterShapeRecords ():
279
+ for __recShape in sf .iterShapeRecords ():
282
280
pass
283
281
assert len (sf ) > 0
284
- assert sf .shp .closed == sf .shx .closed == sf .dbf .closed is True
282
+ assert sf .shp .closed is sf .shx .closed is sf .dbf .closed is True
285
283
286
284
287
285
def test_reader_zip ():
@@ -290,10 +288,10 @@ def test_reader_zip():
290
288
"""
291
289
# test reading zipfile only
292
290
with shapefile .Reader ("shapefiles/blockgroups.zip" ) as sf :
293
- for recShape in sf .iterShapeRecords ():
291
+ for __recShape in sf .iterShapeRecords ():
294
292
pass
295
293
assert len (sf ) > 0
296
- assert sf .shp .closed == sf .shx .closed == sf .dbf .closed is True
294
+ assert sf .shp .closed is sf .shx .closed is sf .dbf .closed is True
297
295
298
296
# test require specific path when reading multi-shapefile zipfile
299
297
with pytest .raises (shapefile .ShapefileException ):
@@ -302,17 +300,17 @@ def test_reader_zip():
302
300
303
301
# test specifying the path when reading multi-shapefile zipfile (with extension)
304
302
with shapefile .Reader ("shapefiles/blockgroups_multishapefile.zip/blockgroups2.shp" ) as sf :
305
- for recShape in sf .iterShapeRecords ():
303
+ for __recShape in sf .iterShapeRecords ():
306
304
pass
307
305
assert len (sf ) > 0
308
- assert sf .shp .closed == sf .shx .closed == sf .dbf .closed is True
306
+ assert sf .shp .closed is sf .shx .closed is sf .dbf .closed is True
309
307
310
308
# test specifying the path when reading multi-shapefile zipfile (without extension)
311
309
with shapefile .Reader ("shapefiles/blockgroups_multishapefile.zip/blockgroups2" ) as sf :
312
- for recShape in sf .iterShapeRecords ():
310
+ for __recShape in sf .iterShapeRecords ():
313
311
pass
314
312
assert len (sf ) > 0
315
- assert sf .shp .closed == sf .shx .closed == sf .dbf .closed is True
313
+ assert sf .shp .closed is sf .shx .closed is sf .dbf .closed is True
316
314
317
315
# test raising error when can't find shapefile inside zipfile
318
316
with pytest .raises (shapefile .ShapefileException ):
@@ -783,7 +781,7 @@ def test_reader_offsets():
783
781
# shx offsets should not be read during loading
784
782
assert not sf ._offsets
785
783
# reading a shape index should trigger reading offsets from shx file
786
- shape = sf .shape (3 )
784
+ sf .shape (3 )
787
785
assert len (sf ._offsets ) == len (sf .shapes ())
788
786
789
787
@@ -800,7 +798,7 @@ def test_reader_offsets_no_shx():
800
798
assert not sf ._offsets
801
799
# reading a shape index should iterate to the shape
802
800
# but the list of offsets should remain empty
803
- shape = sf .shape (3 )
801
+ sf .shape (3 )
804
802
assert not sf ._offsets
805
803
# reading all the shapes should build the list of offsets
806
804
shapes = sf .shapes ()
@@ -1180,7 +1178,7 @@ def test_write_shp_shx_only(tmpdir):
1180
1178
assert writer .shp and writer .shx and not writer .dbf
1181
1179
assert writer .shpNum == 1
1182
1180
assert len (writer ) == 1
1183
- assert writer .shp .closed == writer .shx .closed is True
1181
+ assert writer .shp .closed is writer .shx .closed is True
1184
1182
1185
1183
# assert test.shp exists
1186
1184
assert os .path .exists (filename + '.shp' )
@@ -1214,7 +1212,7 @@ def test_write_shp_dbf_only(tmpdir):
1214
1212
assert writer .shp and not writer .shx and writer .dbf
1215
1213
assert writer .shpNum == writer .recNum == 1
1216
1214
assert len (writer ) == 1
1217
- assert writer .shp .closed == writer .dbf .closed is True
1215
+ assert writer .shp .closed is writer .dbf .closed is True
1218
1216
1219
1217
# assert test.shp exists
1220
1218
assert os .path .exists (filename + '.shp' )
0 commit comments