Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 35ad714

Browse filesBrowse files
authored
Merge pull request #303 from JamesParrott/Synced_with_PyShp
Run Pylint on test_shapefile.py, suppress W0212 for now, and make changes to silence other warnings from it
2 parents ffc7c46 + 31798da commit 35ad714
Copy full SHA for 35ad714

File tree

Expand file treeCollapse file tree

5 files changed

+62
-26
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+62
-26
lines changed

‎.github/workflows/run_tests_and_hooks.yml renamed to ‎.github/workflows/run_tests_hooks_and_tools.yml

Copy file name to clipboardExpand all lines: .github/workflows/run_tests_hooks_and_tools.yml
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,19 @@ jobs:
1717
- uses: actions/setup-python@v5
1818
- uses: pre-commit/action@v3.0.1
1919

20+
pylint:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- uses: actions/checkout@v4
24+
- uses: actions/setup-python@v5
25+
- name: install Pylint and plugin
26+
run: |
27+
python -m pip install --upgrade pip
28+
pip install pytest pylint pylint-per-file-ignores
29+
- name: run Pylint for errors and warnings only, on test_shapefile.py
30+
run: |
31+
pylint --disable=R,C test_shapefile.py
32+
2033
test_on_old_Pythons:
2134
strategy:
2235
fail-fast: false
@@ -60,6 +73,8 @@ jobs:
6073
include:
6174
- os: ubuntu-24.04
6275
python-version: "3.14.0-alpha.0"
76+
- os: ubuntu-22.04
77+
python-version: "3.14.0-alpha.0"
6378

6479
runs-on: ${{ matrix.os }}
6580
steps:

‎README.md

Copy file name to clipboardExpand all lines: README.md
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,8 +1440,9 @@ In the same folder as README.md and shapefile.py, from the command line run
14401440
$ python shapefile.py
14411441
```
14421442

1443-
Linux/Mac and similar platforms will need to run `$ dos2unix README.md` in order
1444-
to correct line endings in README.md.
1443+
Linux/Mac and similar platforms may need to run `$ dos2unix README.md` in order
1444+
to correct line endings in README.md, if Git has not automatically changed them.
1445+
14451446

14461447
# Contributors
14471448

@@ -1459,10 +1460,12 @@ fiveham
14591460
geospatialpython
14601461
Hannes
14611462
Ignacio Martinez Vazquez
1463+
James Parrott
14621464
Jason Moujaes
14631465
Jonty Wareing
14641466
Karim Bahgat
14651467
karanrn
1468+
Kurt Schwehr
14661469
Kyle Kelley
14671470
Louis Tiao
14681471
Marcin Cuprjak

‎pyproject.toml

Copy file name to clipboard
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
11
[build-system]
22
requires = ["setuptools"]
33
build-backend = "setuptools.build_meta"
4+
5+
[tool.pylint.MASTER]
6+
load-plugins=[
7+
"pylint_per_file_ignores",
8+
]
9+
10+
[tool.pylint.'MESSAGES CONTROL']
11+
# Silence warning: shapefile.py:2076:20: W0212: Access to a protected
12+
# member _from_geojson of a client class (protected-access)
13+
#
14+
# Silence warnings: test_shapefile.py:{783,786,799,803,06,1195}:19:
15+
# W0212: Access to a protected member _offsets of a
16+
# client class (protected-access)
17+
#
18+
# Toml multi-line string used instead of array due to:
19+
# https://github.com/christopherpickering/pylint-per-file-ignores/issues/160
20+
per-file-ignores = """
21+
shapefile.py:W0212
22+
test_shapefile.py:W0212
23+
"""

‎requirements.test.txt

Copy file name to clipboard
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
pytest
1+
pytest >= 3.7
22
setuptools

‎test_shapefile.py

Copy file name to clipboardExpand all lines: test_shapefile.py
+21-23Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,16 @@
55
import datetime
66
import json
77
import 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
1416
import 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
2119
import 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)
214212
def 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

287285
def 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

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.