55import datetime
66import json
77import os .path
8- import sys
98
10- if sys . version_info . major == 3 :
9+ try :
1110 from pathlib import Path
11+ except ImportError :
12+ # pathlib2 is a dependency of pytest >= 3.7
13+ from pathlib2 import Path
1214
1315# third party imports
1416import pytest
1517
16- if sys .version_info .major == 2 :
17- # required by pytest for python <36
18- from pathlib2 import Path
19-
2018# our imports
2119import shapefile
2220
@@ -208,7 +206,7 @@ def test_empty_shape_geo_interface():
208206 """
209207 shape = shapefile .Shape ()
210208 with pytest .raises (Exception ):
211- shape . __geo_interface__
209+ getattr ( shape , ' __geo_interface__' )
212210
213211@pytest .mark .parametrize ("typ,points,parts,expected" , geo_interface_tests )
214212def test_expected_shape_geo_interface (typ , points , parts , expected ):
@@ -257,17 +255,17 @@ def test_reader_url():
257255 # test with extension
258256 url = "https://github.com/nvkelso/natural-earth-vector/blob/master/110m_cultural/ne_110m_admin_0_tiny_countries.shp?raw=true"
259257 with shapefile .Reader (url ) as sf :
260- for recShape in sf .iterShapeRecords ():
258+ for __recShape in sf .iterShapeRecords ():
261259 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
263261
264262 # test without extension
265263 url = "https://github.com/nvkelso/natural-earth-vector/blob/master/110m_cultural/ne_110m_admin_0_tiny_countries?raw=true"
266264 with shapefile .Reader (url ) as sf :
267- for recShape in sf .iterShapeRecords ():
265+ for __recShape in sf .iterShapeRecords ():
268266 pass
269267 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
271269
272270 # test no files found
273271 url = "https://raw.githubusercontent.com/nvkelso/natural-earth-vector/master/README.md"
@@ -278,10 +276,10 @@ def test_reader_url():
278276 # test reading zipfile from url
279277 url = "https://github.com/JamesParrott/PyShp_test_shapefile/raw/main/gis_osm_natural_a_free_1.zip"
280278 with shapefile .Reader (url ) as sf :
281- for recShape in sf .iterShapeRecords ():
279+ for __recShape in sf .iterShapeRecords ():
282280 pass
283281 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
285283
286284
287285def test_reader_zip ():
@@ -290,10 +288,10 @@ def test_reader_zip():
290288 """
291289 # test reading zipfile only
292290 with shapefile .Reader ("shapefiles/blockgroups.zip" ) as sf :
293- for recShape in sf .iterShapeRecords ():
291+ for __recShape in sf .iterShapeRecords ():
294292 pass
295293 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
297295
298296 # test require specific path when reading multi-shapefile zipfile
299297 with pytest .raises (shapefile .ShapefileException ):
@@ -302,17 +300,17 @@ def test_reader_zip():
302300
303301 # test specifying the path when reading multi-shapefile zipfile (with extension)
304302 with shapefile .Reader ("shapefiles/blockgroups_multishapefile.zip/blockgroups2.shp" ) as sf :
305- for recShape in sf .iterShapeRecords ():
303+ for __recShape in sf .iterShapeRecords ():
306304 pass
307305 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
309307
310308 # test specifying the path when reading multi-shapefile zipfile (without extension)
311309 with shapefile .Reader ("shapefiles/blockgroups_multishapefile.zip/blockgroups2" ) as sf :
312- for recShape in sf .iterShapeRecords ():
310+ for __recShape in sf .iterShapeRecords ():
313311 pass
314312 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
316314
317315 # test raising error when can't find shapefile inside zipfile
318316 with pytest .raises (shapefile .ShapefileException ):
@@ -783,7 +781,7 @@ def test_reader_offsets():
783781 # shx offsets should not be read during loading
784782 assert not sf ._offsets
785783 # reading a shape index should trigger reading offsets from shx file
786- shape = sf .shape (3 )
784+ sf .shape (3 )
787785 assert len (sf ._offsets ) == len (sf .shapes ())
788786
789787
@@ -800,7 +798,7 @@ def test_reader_offsets_no_shx():
800798 assert not sf ._offsets
801799 # reading a shape index should iterate to the shape
802800 # but the list of offsets should remain empty
803- shape = sf .shape (3 )
801+ sf .shape (3 )
804802 assert not sf ._offsets
805803 # reading all the shapes should build the list of offsets
806804 shapes = sf .shapes ()
@@ -1180,7 +1178,7 @@ def test_write_shp_shx_only(tmpdir):
11801178 assert writer .shp and writer .shx and not writer .dbf
11811179 assert writer .shpNum == 1
11821180 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
11841182
11851183 # assert test.shp exists
11861184 assert os .path .exists (filename + '.shp' )
@@ -1214,7 +1212,7 @@ def test_write_shp_dbf_only(tmpdir):
12141212 assert writer .shp and not writer .shx and writer .dbf
12151213 assert writer .shpNum == writer .recNum == 1
12161214 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
12181216
12191217 # assert test.shp exists
12201218 assert os .path .exists (filename + '.shp' )
0 commit comments