Skip to content

Commit 7867f78

Browse files
committed
housekeeping (tests, docs)
1 parent d743d3f commit 7867f78

File tree

63 files changed

+333
-186
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+333
-186
lines changed

.github/workflows/main.yml

Lines changed: 12 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ jobs:
124124
pip3 install -r requirements-django.txt
125125
python3 setup.py install
126126
pip3 install --global-option=build_ext --global-option="-I/usr/include/gdal" GDAL==`gdal-config --version`
127-
#pip3 install --upgrade rasterio==1.1.8
128127
- name: setup test data ⚙️
129128
run: |
130129
python3 tests/load_es_data.py tests/data/ne_110m_populated_places_simple.geojson geonameid
@@ -137,49 +136,20 @@ jobs:
137136
mysql -h 127.0.0.1 -P 3306 -u root -p'mysql' test_geo_app < tests/data/mysql_data.sql
138137
docker ps
139138
python3 tests/load_oracle_data.py
140-
- name: run unit tests ⚙️
139+
- name: run API tests ⚙️
140+
run: pytest tests/api --ignore-glob='*_live.py'
141+
- name: run Formatter tests ⚙️
142+
run: pytest tests/formatter
143+
- name: run Provider tests ⚙️
141144
env:
142145
POSTGRESQL_PASSWORD: ${{ secrets.DatabasePassword || 'postgres' }}
143-
run: |
144-
pytest tests/api --ignore=tests/api/test_admin_live.py
145-
pytest tests/test_api_ogr_provider.py
146-
pytest tests/test_base_provider.py
147-
pytest tests/test_config.py
148-
pytest tests/test_csv__formatter.py
149-
pytest tests/test_csv__provider.py
150-
pytest tests/test_django.py
151-
pytest tests/test_elasticsearch__provider.py
152-
pytest tests/test_opensearch__provider.py
153-
pytest tests/test_esri_provider.py
154-
pytest tests/test_filesystem_provider.py
155-
pytest tests/test_geojson_provider.py
156-
pytest tests/test_linked_data.py
157-
pytest tests/test_mongo_provider.py
158-
pytest tests/test_ogr_csv_provider.py
159-
pytest tests/test_ogr_esrijson_provider.py
160-
pytest tests/test_ogr_gpkg_provider.py
161-
pytest tests/test_ogr_shapefile_provider.py
162-
pytest tests/test_ogr_sqlite_provider.py
163-
pytest tests/test_ogr_wfs_provider.py
164-
pytest tests/test_postgresql_manager.py
165-
# pytest tests/test_ogr_wfs_provider_live.py # NOTE: these are skipped in the file but listed here for completeness
166-
pytest tests/test_openapi.py
167-
pytest tests/test_oracle_provider.py
168-
pytest tests/test_parquet_provider.py
169-
pytest tests/test_postgresql_provider.py
170-
pytest tests/test_postgresql_mvt_provider.py
171-
pytest tests/test_mysql_provider.py
172-
pytest tests/test_rasterio_provider.py
173-
pytest tests/test_sensorthings_edr_provider.py
174-
pytest tests/test_sensorthings_provider.py
175-
pytest tests/test_socrata_provider.py
176-
# pytest tests/test_socrata_provider_live.py.py # NOTE: these are skipped in the file but listed here for completeness
177-
pytest tests/test_sqlite_geopackage_provider.py
178-
pytest tests/test_tinydb_catalogue_provider.py
179-
pytest tests/test_tinydb_manager_for_parallel_requests.py
180-
pytest tests/test_util.py
181-
pytest tests/test_xarray_netcdf_provider.py
182-
pytest tests/test_xarray_zarr_provider.py
146+
run: pytest tests/provider --ignore-glob='*_live.py'
147+
- name: run Manager tests ⚙️
148+
env:
149+
POSTGRESQL_PASSWORD: ${{ secrets.DatabasePassword || 'postgres' }}
150+
run: pytest tests/manager
151+
- name: run other tests ⚙️
152+
run: pytest tests/other --ignore-glob='*_live.py'
183153
- name: failed tests 🚩
184154
if: ${{ failure() }}
185155
run: |

docs/source/data-publishing/ogcapi-features.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ Custom SQL Manipulator Plugin
570570
The provider supports a SQL-Manipulator-Plugin class. With this, the SQL statement could be manipulated. This is
571571
useful e.g. for authorization at row level or manipulation of the explain plan with hints.
572572

573-
An example and more information about that feature can be found in the test class in tests/test_oracle_provider.py.
573+
More information and examples about this feature can be found in ``tests/provider/test_oracle_provider.py``.
574574

575575
.. _Parquet:
576576

docs/source/data-publishing/ogcapi-tiles.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,16 @@ This code block shows how to configure pygeoapi to read map tiles from a WMTS.
201201
min: 0
202202
max: 20
203203
204+
205+
Providing custom Tile Matrix Set definitions
206+
--------------------------------------------
207+
208+
By default, pygeoapi provides the ``WorldCRS84Quad`` and ``WebMercatorQuad`` TMS
209+
definitions, for tile providers to use accordingly. Additional TMS definitions
210+
may be added in pygeoapi's ``resources/definitions/tiles`` (for example, by adding
211+
TMS definition files directly, volume mapping / Docker ``COPY``, Docker Compose ``volumes``, etc.).
212+
213+
204214
Data access examples
205215
--------------------
206216

docs/source/development.rst

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ The pygeoapi codebase exists at https://github.com/geopython/pygeoapi.
1111
Pull Requests and GitHub Actions
1212
--------------------------------
1313

14-
A given GitHub Pull Request is evaluated against the following GitHub actions:
14+
A given GitHub Pull Request is evaluated against the following GitHub Actions:
1515

16-
- main: mainline testing harness (as defined in ``tests``)
17-
- flake8: code linting
18-
- docs: documentation updates (for files updated in ``docs/**.rst``)
19-
- vulnerabilities: Trivy vulnerability scanning
16+
- ``main``: mainline testing harness (as defined in ``tests``)
17+
- ``flake8``: code linting
18+
- ``docs``: documentation updates (for files updated in ``docs/**.rst``)
19+
- ``vulnerabilities``: Trivy vulnerability scanning
2020

2121
Testing
2222
-------
@@ -25,6 +25,11 @@ pygeoapi uses `pytest <https://docs.pytest.org>`_ for managing its automated tes
2525
exist in ``/tests`` and are developed for providers, formatters, processes, as well as the
2626
overall API.
2727

28+
- API specific tests can be found in ``/tests/api``
29+
- Provider specific tests can be found in ``/tests/provider``
30+
- Manager specific tests can be found in ``/tests/manager``
31+
- Additional/other tests can be found in ``/tests/other``
32+
2833
Tests can be run locally as part of development workflow. They are also run on pygeoapi’s
2934
`GitHub Actions setup`_ against all commits and pull requests to the code repository.
3035

@@ -57,24 +62,23 @@ Using pre-commit
5762
^^^^^^^^^^^^^^^^
5863

5964
You may optionally use `pre-commit`_ in order to check for linting and other static issues
60-
before committing changes. Pygeoapi's repo includes a ``.pre-commit.yml``
65+
before committing changes. pygeoapi's repo includes a ``.pre-commit.yml``
6166
file, check the pre-commit docs on how to set it up - in a nutshell:
6267

63-
- pre-commit is mentioned in pygeoapi's ``requirements-dev.txt`` file, so it will be included
64-
when you pip install those
65-
- run ``pre-commit install`` once in order to install its git commit hooks.
66-
- optionally, run ``pre-commit run --all-files``, which will run all pre-commit hooks for all files in the repo.
67-
This also prepares the pre-commit environment.
68-
- from now on, whenever you do a ``git commit``, the pre-commit hooks will run and the commit
69-
will only be done if all checks pass
68+
- pre-commit is part of ``requirements-dev.txt`` file, so it will be included when installing same
69+
- run ``pre-commit install`` once in order to install its git commit hooks
70+
- optionally, run ``pre-commit run --all-files``, which will run all pre-commit hooks for all files
71+
in the repository. Note that this also prepares the pre-commit environment
72+
- When subsequent ``git commit`` commands are run, the pre-commit hooks will run and commit
73+
on passing checks
7074

7175
Building the documentation
7276
--------------------------
7377

74-
To build the documentation in pygeoapi we use `Sphinx`_. The documentation is located in the docs folder.
78+
Documentation is managed using `Sphinx`_ and located in the ``docs`` directory.
7579

7680
.. note::
77-
For the following instructions to work, you must be located in the root folder of pygeoapi.
81+
The following commands should be run from the root folder of the repository.
7882

7983
Install the dependencies necessary for building the documentation using the following command:
8084

@@ -93,12 +97,17 @@ Or using the following ``make`` command:
9397

9498
.. code-block:: bash
9599
96-
make -C docs html
100+
make -C docs/ html
101+
102+
After building the documentation, the ``docs/build`` directory will contain the generated documentation.
103+
104+
To view the generated documentation locally, use one of the following options:
97105

98-
After building the documentation, the folder ``docs/build`` will contain the website generated with the documentation.
99-
Add the folder to a web server or open the file ``docs/build/html/index.html`` file in a web browser to see the contents of the documentation.
106+
- run ``python3 -m http.server`` and navigate to ``http://localhost:8000`` in a web browser. To use a different port, use ``python3 -m http.server 8001``, for example, and navigate to ``http://localhost:8001``
107+
- add the directory to a web server
108+
- open the file ``docs/build/html/index.html`` file in a web browser
100109

101-
The documentation is hosted on `Read the Docs`_. It is automatically generated from the contents of the ``master`` branch on GitHub.
110+
The documentation is hosted on `Read the Docs`_ and automatically generated from the contents of the ``master`` branch on GitHub.
102111

103112
The file ``.readthedocs.yaml`` contains the configuration of the Read the Docs build. Refer to the `Read the Docs configuration file`_ documentation for more information.
104113

docs/source/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ reference documentation on all aspects of the project.
2121

2222
.. note::
2323

24-
Did you know about the `pygeoapi workshop`_? Ready to get your hands dirty? Dive in!
24+
Did you know about the `Diving into pygeoapi workshop`_? Ready to get your hands dirty? Dive in!
2525

2626
.. toctree::
2727
:maxdepth: 4

docs/source/ogc-compliance.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ Setting up your own CITE testing instance
1616
-----------------------------------------
1717

1818
Please see the pygeoapi `OGC Compliance <https://github.com/geopython/pygeoapi/wiki/OGCCompliance>`_
19-
for up to date information as well as technical details on setting up your own CITE instance.
19+
wiki page for up to date information as well as technical details on setting up your own CITE instance.

pygeoapi/api/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
ProviderConnectionError, ProviderGenericError, ProviderTypeError)
6464

6565
from pygeoapi.util import (
66-
CrsTransformSpec, TEMPLATES, UrlPrefetcher, dategetter,
66+
CrsTransformSpec, TEMPLATESDIR, UrlPrefetcher, dategetter,
6767
filter_dict_by_key_value, filter_providers_by_type, get_api_rules,
6868
get_base_url, get_provider_by_type, get_provider_default, get_typed_value,
6969
get_crs_from_uri, get_supported_crs_list, render_j2_template, to_json,
@@ -555,7 +555,7 @@ def __init__(self, config, openapi):
555555
self.default_locale = self.locales[0]
556556

557557
if 'templates' not in self.config['server']:
558-
self.config['server']['templates'] = {'path': TEMPLATES}
558+
self.config['server']['templates'] = {'path': TEMPLATESDIR}
559559

560560
if 'pretty_print' not in self.config['server']:
561561
self.config['server']['pretty_print'] = False

pygeoapi/config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Authors: Tom Kralidis <[email protected]>
44
# Francesco Bartoli <[email protected]>
55
#
6-
# Copyright (c) 2022 Tom Kralidis
6+
# Copyright (c) 2025 Tom Kralidis
77
# Copyright (c) 2025 Francesco Bartoli
88
#
99
# Permission is hereby granted, free of charge, to any person
@@ -36,7 +36,7 @@
3636
import os
3737
import yaml
3838

39-
from pygeoapi.util import to_json, yaml_load, THISDIR
39+
from pygeoapi.util import SCHEMASDIR, to_json, yaml_load
4040

4141
LOGGER = logging.getLogger(__name__)
4242

@@ -65,7 +65,7 @@ def get_config(raw: bool = False) -> dict:
6565
def load_schema() -> dict:
6666
""" Reads the JSON schema YAML file. """
6767

68-
schema_file = THISDIR / 'schemas' / 'config' / 'pygeoapi-config-0.x.yml'
68+
schema_file = SCHEMASDIR / 'config' / 'pygeoapi-config-0.x.yml'
6969

7070
with schema_file.open() as fh2:
7171
return yaml_load(fh2)

pygeoapi/models/provider/base.py

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# ****************************** -*-
2-
# flake8: noqa
31
# =================================================================
42
#
53
# Authors: Antonio Cerciello <[email protected]>
64
# Francesco Bartoli <[email protected]>
5+
# Tom Kralidis <[email protected]>
76
#
87
# Copyright (c) 2022 Antonio Cerciello
98
# Copyright (c) 2025 Francesco Bartoli
9+
# Copyright (c) 2025 Tom Kralidis
1010
#
1111
# Permission is hereby granted, free of charge, to any person
1212
# obtaining a copy of this software and associated documentation
@@ -40,10 +40,9 @@
4040
import pydantic
4141
from pydantic import BaseModel
4242

43-
from pygeoapi.util import THISDIR
43+
from pygeoapi.util import DEFINITIONSDIR
4444

45-
46-
TMS_DIR = THISDIR / 'resources' / 'tilematrixsets'
45+
TMS_DIR = DEFINITIONSDIR / 'tiles'
4746

4847

4948
class TilesMetadataFormat(str, Enum):
@@ -93,10 +92,19 @@ def __init__(self, directory: Path):
9392
self.directory = directory
9493

9594
def load_from_file(self, filename: str) -> TileMatrixSetEnumType:
96-
"""Load a single TMS JSON file."""
95+
"""
96+
Load a single TMS JSON file.
97+
98+
:param filename: filename of TMS
99+
100+
:returns: `TileMatrixSetEnumType` of TMS
101+
"""
102+
97103
filepath = self.directory / filename
104+
98105
with filepath.open(encoding='utf-8') as fh:
99106
data = json.load(fh)
107+
100108
return TileMatrixSetEnumType(
101109
tileMatrixSet=data["id"],
102110
tileMatrixSetURI=data["uri"],
@@ -108,12 +116,18 @@ def load_from_file(self, filename: str) -> TileMatrixSetEnumType:
108116
)
109117

110118
def create_enum(self) -> Enum:
111-
"""Create an Enum with all TileMatrixSets in the directory."""
119+
"""
120+
Create an Enum with all TileMatrixSets in the directory.
121+
122+
:returns: `Enum` of `TileMatrixSetEnum`
123+
"""
124+
112125
members = {}
113-
for file_path in self.directory.glob("*.json"):
114-
tms = self.load_from_file(file_path.name)
115-
enum_name = tms.tileMatrixSet.upper().replace("-", "").replace(" ", "")
126+
for filepath in self.directory.glob("*.json"):
127+
tms = self.load_from_file(filepath.name)
128+
enum_name = tms.tileMatrixSet.upper().replace("-", "").replace(" ", "") # noqa
116129
members[enum_name] = tms
130+
117131
return Enum("TileMatrixSetEnum", members)
118132

119133

@@ -199,7 +213,7 @@ class TileSetMetadata(BaseModel):
199213
license_: Optional[str] = None
200214
# Restrictions on the availability of the Tile Set that the user needs to
201215
# be aware of before using or redistributing the Tile Set
202-
accessConstraints: Optional[AccessConstraintsEnum] = AccessConstraintsEnum.UNCLASSIFIED
216+
accessConstraints: Optional[AccessConstraintsEnum] = AccessConstraintsEnum.UNCLASSIFIED # noqa
203217
# Media types available for the tiles
204218
mediaTypes: Optional[List[str]] = None
205219
# Type of data represented in the tileset

pygeoapi/openapi.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Authors: Francesco Bartoli <[email protected]>
55
# Authors: Ricardo Garcia Silva <[email protected]>
66
#
7-
# Copyright (c) 2024 Tom Kralidis
7+
# Copyright (c) 2025 Tom Kralidis
88
# Copyright (c) 2025 Francesco Bartoli
99
# Copyright (c) 2023 Ricardo Garcia Silva
1010
#
@@ -47,7 +47,7 @@
4747
from pygeoapi.api import all_apis
4848
from pygeoapi.models.openapi import OAPIFormat
4949
from pygeoapi.util import (filter_dict_by_key_value, to_json, yaml_load,
50-
get_api_rules, get_base_url)
50+
get_api_rules, get_base_url, SCHEMASDIR)
5151

5252
LOGGER = logging.getLogger(__name__)
5353

@@ -62,8 +62,6 @@
6262
'pygeoapi': 'https://raw.githubusercontent.com/geopython/pygeoapi/master/pygeoapi/schemas/config/pygeoapi-config-0.x.yml' # noqa
6363
}
6464

65-
THISDIR = os.path.dirname(os.path.realpath(__file__))
66-
6765

6866
def get_ogc_schemas_location(server_config: dict) -> str:
6967
"""
@@ -706,10 +704,9 @@ def get_visible_collections(cfg: dict) -> dict:
706704

707705

708706
def get_config_schema():
709-
schema_file = os.path.join(THISDIR, 'schemas', 'config',
710-
'pygeoapi-config-0.x.yml')
707+
schema_file = SCHEMASDIR / 'config' / 'pygeoapi-config-0.x.yml'
711708

712-
with open(schema_file) as fh2:
709+
with schema_file.open() as fh2:
713710
return yaml_load(fh2)
714711

715712

@@ -957,10 +954,9 @@ def validate_openapi_document(instance_dict: dict) -> bool:
957954
:returns: `bool` of validation
958955
"""
959956

960-
schema_file = os.path.join(THISDIR, 'schemas', 'openapi',
961-
'openapi-3.0.x.json')
957+
schema_file = SCHEMASDIR / 'openapi' / 'openapi-3.0.x.json'
962958

963-
with open(schema_file) as fh2:
959+
with schema_file.open() as fh2:
964960
schema_dict = json.load(fh2)
965961
jsonschema_validate(instance_dict, schema_dict)
966962

0 commit comments

Comments
 (0)