Skip to content

Commit

Permalink
Merge pull request #303 from JamesParrott/Synced_with_PyShp
Browse files Browse the repository at this point in the history
Run Pylint on test_shapefile.py, suppress W0212 for now, and make changes to silence other warnings from it
  • Loading branch information
JamesParrott authored Sep 19, 2024
2 parents ffc7c46 + 31798da commit 35ad714
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ jobs:
- uses: actions/setup-python@v5
- uses: pre-commit/action@v3.0.1

pylint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- name: install Pylint and plugin
run: |
python -m pip install --upgrade pip
pip install pytest pylint pylint-per-file-ignores
- name: run Pylint for errors and warnings only, on test_shapefile.py
run: |
pylint --disable=R,C test_shapefile.py
test_on_old_Pythons:
strategy:
fail-fast: false
Expand Down Expand Up @@ -60,6 +73,8 @@ jobs:
include:
- os: ubuntu-24.04
python-version: "3.14.0-alpha.0"
- os: ubuntu-22.04
python-version: "3.14.0-alpha.0"

runs-on: ${{ matrix.os }}
steps:
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1440,8 +1440,9 @@ In the same folder as README.md and shapefile.py, from the command line run
$ python shapefile.py
```

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


# Contributors

Expand All @@ -1459,10 +1460,12 @@ fiveham
geospatialpython
Hannes
Ignacio Martinez Vazquez
James Parrott
Jason Moujaes
Jonty Wareing
Karim Bahgat
karanrn
Kurt Schwehr
Kyle Kelley
Louis Tiao
Marcin Cuprjak
Expand Down
20 changes: 20 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[tool.pylint.MASTER]
load-plugins=[
"pylint_per_file_ignores",
]

[tool.pylint.'MESSAGES CONTROL']
# Silence warning: shapefile.py:2076:20: W0212: Access to a protected
# member _from_geojson of a client class (protected-access)
#
# Silence warnings: test_shapefile.py:{783,786,799,803,06,1195}:19:
# W0212: Access to a protected member _offsets of a
# client class (protected-access)
#
# Toml multi-line string used instead of array due to:
# https://github.com/christopherpickering/pylint-per-file-ignores/issues/160
per-file-ignores = """
shapefile.py:W0212
test_shapefile.py:W0212
"""
2 changes: 1 addition & 1 deletion requirements.test.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pytest
pytest >= 3.7
setuptools
44 changes: 21 additions & 23 deletions test_shapefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@
import datetime
import json
import os.path
import sys

if sys.version_info.major == 3:
try:
from pathlib import Path
except ImportError:
# pathlib2 is a dependency of pytest >= 3.7
from pathlib2 import Path

# third party imports
import pytest

if sys.version_info.major == 2:
# required by pytest for python <36
from pathlib2 import Path

# our imports
import shapefile

Expand Down Expand Up @@ -208,7 +206,7 @@ def test_empty_shape_geo_interface():
"""
shape = shapefile.Shape()
with pytest.raises(Exception):
shape.__geo_interface__
getattr(shape, '__geo_interface__')

@pytest.mark.parametrize("typ,points,parts,expected", geo_interface_tests)
def test_expected_shape_geo_interface(typ, points, parts, expected):
Expand Down Expand Up @@ -257,17 +255,17 @@ def test_reader_url():
# test with extension
url = "https://github.com/nvkelso/natural-earth-vector/blob/master/110m_cultural/ne_110m_admin_0_tiny_countries.shp?raw=true"
with shapefile.Reader(url) as sf:
for recShape in sf.iterShapeRecords():
for __recShape in sf.iterShapeRecords():
pass
assert sf.shp.closed == sf.shx.closed == sf.dbf.closed is True
assert sf.shp.closed is sf.shx.closed is sf.dbf.closed is True

# test without extension
url = "https://github.com/nvkelso/natural-earth-vector/blob/master/110m_cultural/ne_110m_admin_0_tiny_countries?raw=true"
with shapefile.Reader(url) as sf:
for recShape in sf.iterShapeRecords():
for __recShape in sf.iterShapeRecords():
pass
assert len(sf) > 0
assert sf.shp.closed == sf.shx.closed == sf.dbf.closed is True
assert sf.shp.closed is sf.shx.closed is sf.dbf.closed is True

# test no files found
url = "https://raw.githubusercontent.com/nvkelso/natural-earth-vector/master/README.md"
Expand All @@ -278,10 +276,10 @@ def test_reader_url():
# test reading zipfile from url
url = "https://github.com/JamesParrott/PyShp_test_shapefile/raw/main/gis_osm_natural_a_free_1.zip"
with shapefile.Reader(url) as sf:
for recShape in sf.iterShapeRecords():
for __recShape in sf.iterShapeRecords():
pass
assert len(sf) > 0
assert sf.shp.closed == sf.shx.closed == sf.dbf.closed is True
assert sf.shp.closed is sf.shx.closed is sf.dbf.closed is True


def test_reader_zip():
Expand All @@ -290,10 +288,10 @@ def test_reader_zip():
"""
# test reading zipfile only
with shapefile.Reader("shapefiles/blockgroups.zip") as sf:
for recShape in sf.iterShapeRecords():
for __recShape in sf.iterShapeRecords():
pass
assert len(sf) > 0
assert sf.shp.closed == sf.shx.closed == sf.dbf.closed is True
assert sf.shp.closed is sf.shx.closed is sf.dbf.closed is True

# test require specific path when reading multi-shapefile zipfile
with pytest.raises(shapefile.ShapefileException):
Expand All @@ -302,17 +300,17 @@ def test_reader_zip():

# test specifying the path when reading multi-shapefile zipfile (with extension)
with shapefile.Reader("shapefiles/blockgroups_multishapefile.zip/blockgroups2.shp") as sf:
for recShape in sf.iterShapeRecords():
for __recShape in sf.iterShapeRecords():
pass
assert len(sf) > 0
assert sf.shp.closed == sf.shx.closed == sf.dbf.closed is True
assert sf.shp.closed is sf.shx.closed is sf.dbf.closed is True

# test specifying the path when reading multi-shapefile zipfile (without extension)
with shapefile.Reader("shapefiles/blockgroups_multishapefile.zip/blockgroups2") as sf:
for recShape in sf.iterShapeRecords():
for __recShape in sf.iterShapeRecords():
pass
assert len(sf) > 0
assert sf.shp.closed == sf.shx.closed == sf.dbf.closed is True
assert sf.shp.closed is sf.shx.closed is sf.dbf.closed is True

# test raising error when can't find shapefile inside zipfile
with pytest.raises(shapefile.ShapefileException):
Expand Down Expand Up @@ -783,7 +781,7 @@ def test_reader_offsets():
# shx offsets should not be read during loading
assert not sf._offsets
# reading a shape index should trigger reading offsets from shx file
shape = sf.shape(3)
sf.shape(3)
assert len(sf._offsets) == len(sf.shapes())


Expand All @@ -800,7 +798,7 @@ def test_reader_offsets_no_shx():
assert not sf._offsets
# reading a shape index should iterate to the shape
# but the list of offsets should remain empty
shape = sf.shape(3)
sf.shape(3)
assert not sf._offsets
# reading all the shapes should build the list of offsets
shapes = sf.shapes()
Expand Down Expand Up @@ -1180,7 +1178,7 @@ def test_write_shp_shx_only(tmpdir):
assert writer.shp and writer.shx and not writer.dbf
assert writer.shpNum == 1
assert len(writer) == 1
assert writer.shp.closed == writer.shx.closed is True
assert writer.shp.closed is writer.shx.closed is True

# assert test.shp exists
assert os.path.exists(filename+'.shp')
Expand Down Expand Up @@ -1214,7 +1212,7 @@ def test_write_shp_dbf_only(tmpdir):
assert writer.shp and not writer.shx and writer.dbf
assert writer.shpNum == writer.recNum == 1
assert len(writer) == 1
assert writer.shp.closed == writer.dbf.closed is True
assert writer.shp.closed is writer.dbf.closed is True

# assert test.shp exists
assert os.path.exists(filename+'.shp')
Expand Down

0 comments on commit 35ad714

Please sign in to comment.