Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions .github/actions/test/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,6 @@ runs:
echo "HTTP_SERVER_PID=$!" >> $GITHUB_ENV
sleep 4 # give server time to start

- name: Doctests
shell: bash
working-directory: ${{ inputs.pyshp_repo_directory }}
env:
REPLACE_REMOTE_URLS_WITH_LOCALHOST: ${{ inputs.replace_remote_urls_with_localhost }}
run: python shapefile.py ${{ inputs.extra_args }}


- name: Download wheel and sdist (built in previous jobs)
uses: actions/download-artifact@v4
with:
Expand All @@ -87,6 +79,13 @@ runs:
WHEEL_NAME=$(ls pyshp-*py3-none-any.whl)
python -m pip install $WHEEL_NAME[test]

- name: Doctests
shell: bash
working-directory: ${{ inputs.pyshp_repo_directory }}
env:
REPLACE_REMOTE_URLS_WITH_LOCALHOST: ${{ inputs.replace_remote_urls_with_localhost }}
run: python test_shapefile.py ${{ inputs.extra_args }}

- name: Show Python and Pytest versions for logs.
shell: bash
run: |
Expand Down
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1446,7 +1446,7 @@ ESRI White Paper](http://downloads.esri.com/support/whitepapers/ao_/J9749_MultiP
The testing framework is pytest, and the tests are located in test_shapefile.py.
This includes an extensive set of unit tests of the various pyshp features,
and tests against various input data.
In the same folder as README.md and shapefile.py, from the command line run
In the same folder as README.md and shapefile.py, from the command line run:

```shell
python -m pytest
Expand All @@ -1455,12 +1455,21 @@ python -m pytest
Additionally, all the code and examples located in this file, README.md,
is tested and verified with the builtin doctest framework.
A special routine for invoking the doctest is run when calling directly on shapefile.py.
In the same folder as README.md and shapefile.py, from the command line run
In the same folder as README.md and shapefile.py, from the command line run:

```shell
python shapefile.py
```

This tests the code inside shapefile.py itself. To test an installed PyShp wheel against
the doctests, the same special routine can be invoked (in an env with the wheel and pytest
installed) from the test file:


```shell
python test_shapefile.py
```

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.

Expand Down Expand Up @@ -1497,8 +1506,6 @@ REPLACE_REMOTE_URLS_WITH_LOCALHOST=yes && python shapefile.py
The network tests alone can also be run (without also running all the tests that don't
make network requests) using: `pytest -m network` (or the doctests using: `python shapefile.py -m network`).

(*) The steps to host the files using Caddy for PYthon 2 are in ./actions/test/action.yml. For reasons as
yet unknown, shapefile.py's Reader class in Python 2 Pytest, can't connect to a Python 2 SimpleHTTPServer.


# Contributors
Expand Down
1 change: 1 addition & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[pytest]
markers =
network: marks tests requiring network access
slow: marks other tests that cause bottlenecks
6 changes: 5 additions & 1 deletion shapefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2979,10 +2979,14 @@ def summarize(self):
return failure_count


if __name__ == "__main__":
def main():
"""
Doctests are contained in the file 'README.md', and are tested using the built-in
testing libraries.
"""
failure_count = _test()
sys.exit(failure_count)


if __name__ == "__main__":
main()
7 changes: 7 additions & 0 deletions test_shapefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,7 @@ def test_record_oid():
assert shaperec.record.oid == i


@pytest.mark.slow
def test_iterRecords_start_stop():
"""
Assert that Reader.iterRecords(start, stop)
Expand Down Expand Up @@ -1850,3 +1851,9 @@ def test_write_empty_shapefile(tmpdir, shape_type):
assert len(r.records()) == 0
# test shapes are empty
assert len(r.shapes()) == 0


# This allows a PyShp wheel installed in the env to be tested
# against the doctests.
if __name__ == "__main__":
shapefile.main()
Loading