Skip to content

Commit 0045cc8

Browse files
committed
Describe strategy for network tests.
1 parent acd1fe9 commit 0045cc8

File tree

2 files changed

+47
-8
lines changed

2 files changed

+47
-8
lines changed

.github/actions/test/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ runs:
9595
env:
9696
REPLACE_REMOTE_URLS_WITH_LOCALHOST: ${{ inputs.replace_remote_urls_with_localhost }}
9797
run: |
98-
pytest -rA --tb=short ${{ inputs.extra_args }}
98+
pytest -rA --tb=short ${{ inputs.extra_args }}
9999
100100
- name: Show versions for logs.
101101
shell: bash

README.md

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ part of your geospatial project.
102102
- Equality comparisons between Records now also require the fields to be the same (and in the same order).
103103

104104
### Development:
105-
- Code quality tools run on PyShp
105+
- Code quality tools (Ruff format) run on PyShp
106+
- Network, non-network, or all doctests selectable via command line args
107+
- Network tests made runnable on localhost.
106108

107109
## 2.3.1
108110

@@ -1434,24 +1436,61 @@ ESRI White Paper](http://downloads.esri.com/support/whitepapers/ao_/J9749_MultiP
14341436

14351437
The testing framework is pytest, and the tests are located in test_shapefile.py.
14361438
This includes an extensive set of unit tests of the various pyshp features,
1437-
and tests against various input data. Some of the tests that require
1438-
internet connectivity will be skipped in offline testing environments.
1439+
and tests against various input data.
14391440
In the same folder as README.md and shapefile.py, from the command line run
1440-
```
1441-
$ python -m pytest
1441+
1442+
```shell
1443+
python -m pytest
14421444
```
14431445

14441446
Additionally, all the code and examples located in this file, README.md,
14451447
is tested and verified with the builtin doctest framework.
14461448
A special routine for invoking the doctest is run when calling directly on shapefile.py.
14471449
In the same folder as README.md and shapefile.py, from the command line run
1448-
```
1449-
$ python shapefile.py
1450+
1451+
```shell
1452+
python shapefile.py
14501453
```
14511454

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

1458+
## Network tests
1459+
1460+
Some of the tests and doctests, are intended to test reading shapefiles from
1461+
remote servers, which requires internet connectivity. The pytest tests are marked "network".
1462+
For rapid iteration, in CI, or when developing in offline testing environments, these
1463+
tests can be dealt with in two ways:
1464+
i) by skipping the network tests via :
1465+
```shell
1466+
pytest -m "not network"
1467+
```
1468+
or the doctests via:
1469+
```shell
1470+
python shapefile.py -m "not network"
1471+
```
1472+
or ii) by cloning a repo of the files they download, serving these on localhost in a separate process,
1473+
and running the network tests with the environment variable REPLACE_REMOTE_URLS_WITH_LOCALHOST to `yes`:
1474+
Setup a local file server (*):
1475+
```
1476+
git clone http://github.com/JamesParrott/PyShp_test_shapefile
1477+
cd PyShp_test_shapefile
1478+
python -m http.server 8000
1479+
```
1480+
and then:
1481+
```bash
1482+
REPLACE_REMOTE_URLS_WITH_LOCALHOST=yes && pytest
1483+
```
1484+
or the doctests via:
1485+
```bash
1486+
REPLACE_REMOTE_URLS_WITH_LOCALHOST=yes && python shapefile.py
1487+
```
1488+
The network tests alone can also be run (without also running all the tests that don't
1489+
make network requests) using: `pytest -m network` (or the doctests using: `python shapefile.py -m network`).
1490+
1491+
(*) The steps to host the files using Caddy for PYthon 2 are in ./actions/test/action.yml. For reasons as
1492+
yet unknown, shapefile.py's Reader class in Python 2 Pytest, can't connect to a Python 2 SimpleHTTPServer.
1493+
14551494

14561495
# Contributors
14571496

0 commit comments

Comments
 (0)