diff --git a/.github/actions/test/action.yml b/.github/actions/test/action.yml index 622b934..61dfe13 100644 --- a/.github/actions/test/action.yml +++ b/.github/actions/test/action.yml @@ -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: @@ -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: | diff --git a/README.md b/README.md index caf5f33..a8ed822 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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. @@ -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 diff --git a/pytest.ini b/pytest.ini index dbc031b..39fbfae 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,3 +1,4 @@ [pytest] markers = network: marks tests requiring network access + slow: marks other tests that cause bottlenecks diff --git a/shapefile.py b/shapefile.py index 1f8bbf8..4d5ad68 100644 --- a/shapefile.py +++ b/shapefile.py @@ -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() diff --git a/test_shapefile.py b/test_shapefile.py index 5f9b855..04994af 100644 --- a/test_shapefile.py +++ b/test_shapefile.py @@ -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) @@ -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()