@@ -276,6 +276,93 @@ def test_reader_fields():
276276 assert isinstance (field [3 ], int ) # decimal length
277277
278278
279+ def test_reader_shapefile_extension_ignored ():
280+ """
281+ Assert that the filename's extension is
282+ ignored when reading a shapefile.
283+ """
284+ base = "shapefiles/blockgroups"
285+ ext = ".abc"
286+ filename = base + ext
287+ with shapefile .Reader (filename ) as sf :
288+ assert len (sf ) == 663
289+
290+ # assert test.abc does not exist
291+ assert not os .path .exists (filename )
292+
293+
294+ def test_reader_dbf_only ():
295+ """
296+ Assert that specifying just the
297+ dbf argument to the shapefile reader
298+ reads just the dbf file.
299+ """
300+ with shapefile .Reader (dbf = "shapefiles/blockgroups.dbf" ) as sf :
301+ assert len (sf ) == 663
302+ record = sf .record (3 )
303+ assert record [1 :3 ] == ['060750601001' , 4715 ]
304+
305+
306+ def test_reader_shp_shx_only ():
307+ """
308+ Assert that specifying just the
309+ shp and shx argument to the shapefile reader
310+ reads just the shp and shx file.
311+ """
312+ with shapefile .Reader (shp = "shapefiles/blockgroups.shp" , shx = "shapefiles/blockgroups.shx" ) as sf :
313+ assert len (sf ) == 663
314+ shape = sf .shape (3 )
315+ assert len (shape .points ) is 173
316+
317+
318+ def test_reader_shx_optional ():
319+ """
320+ Assert that specifying just the
321+ shp argument to the shapefile reader
322+ reads just the shp file (shx optional).
323+ """
324+ with shapefile .Reader (shp = "shapefiles/blockgroups.shp" ) as sf :
325+ assert len (sf ) == 663
326+ shape = sf .shape (3 )
327+ assert len (shape .points ) is 173
328+
329+
330+ def test_reader_filelike_dbf_only ():
331+ """
332+ Assert that specifying just the
333+ dbf argument to the shapefile reader
334+ reads just the dbf file.
335+ """
336+ with shapefile .Reader (dbf = open ("shapefiles/blockgroups.dbf" , "rb" )) as sf :
337+ assert len (sf ) == 663
338+ record = sf .record (3 )
339+ assert record [1 :3 ] == ['060750601001' , 4715 ]
340+
341+
342+ def test_reader_filelike_shp_shx_only ():
343+ """
344+ Assert that specifying just the
345+ shp and shx argument to the shapefile reader
346+ reads just the shp and shx file.
347+ """
348+ with shapefile .Reader (shp = open ("shapefiles/blockgroups.shp" , "rb" ), shx = open ("shapefiles/blockgroups.shx" , "rb" )) as sf :
349+ assert len (sf ) == 663
350+ shape = sf .shape (3 )
351+ assert len (shape .points ) is 173
352+
353+
354+ def test_reader_filelike_shx_optional ():
355+ """
356+ Assert that specifying just the
357+ shp argument to the shapefile reader
358+ reads just the shp file (shx optional).
359+ """
360+ with shapefile .Reader (shp = open ("shapefiles/blockgroups.shp" , "rb" )) as sf :
361+ assert len (sf ) == 663
362+ shape = sf .shape (3 )
363+ assert len (shape .points ) is 173
364+
365+
279366def test_records_match_shapes ():
280367 """
281368 Assert that the number of records matches
@@ -498,7 +585,7 @@ def test_write_geojson(tmpdir):
498585@pytest .mark .parametrize ("shape_type" , shape_types )
499586def test_write_empty_shapefile (tmpdir , shape_type ):
500587 """
501- Assert that can write an empty shapefile
588+ Assert that can write an empty shapefile, for all different shape types.
502589 """
503590 filename = tmpdir .join ("test" ).strpath
504591 with shapefile .Writer (filename , shapeType = shape_type ) as w :
0 commit comments