From dddc6d3995ff21badb7b5b0d21832cc4cf896af6 Mon Sep 17 00:00:00 2001 From: Francesco Bartoli Date: Tue, 10 Feb 2026 12:04:46 +0100 Subject: [PATCH 1/3] Fix to not mutating conformance class list --- pygeoapi/api/__init__.py | 2 +- tests/api/test_api.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/pygeoapi/api/__init__.py b/pygeoapi/api/__init__.py index 99818996e..96fbfd8a4 100644 --- a/pygeoapi/api/__init__.py +++ b/pygeoapi/api/__init__.py @@ -886,7 +886,7 @@ def conformance(api: API, request: APIRequest) -> Tuple[dict, int, str]: apis_dict = all_apis() - conformance_list = CONFORMANCE_CLASSES + conformance_list = list(CONFORMANCE_CLASSES) for key, value in api.config['resources'].items(): if value['type'] == 'process': diff --git a/tests/api/test_api.py b/tests/api/test_api.py index 0f8e785c1..5826d6078 100644 --- a/tests/api/test_api.py +++ b/tests/api/test_api.py @@ -567,6 +567,38 @@ def test_conformance(config, api_): assert rsp_headers['Content-Language'] == 'en-US' +def test_conformance_does_not_mutate_global_list(config, api_): + """Test the conformance function does not mutate the global CONFORMANCE_CLASSES. + + This test verifies that the global CONFORMANCE_CLASSES list is not mutated + by calls to the conformance function. The base conformance classes should + remain unchanged after multiple calls. + """ + from pygeoapi.api import CONFORMANCE_CLASSES + + # Store the original length and content of the global list + original_length = len(CONFORMANCE_CLASSES) + original_classes = list(CONFORMANCE_CLASSES) + + req = mock_api_request() + + # Make multiple calls to conformance + for _ in range(3): + conformance(api_, req) + + # The global list should NOT have been mutated + assert len(CONFORMANCE_CLASSES) == original_length, ( + f'Global CONFORMANCE_CLASSES was mutated! ' + f'Original length: {original_length}, ' + f'Current length: {len(CONFORMANCE_CLASSES)}. ' + f'The conformance() function should create a copy of the list ' + f'before extending it.' + ) + assert CONFORMANCE_CLASSES == original_classes, ( + 'Global CONFORMANCE_CLASSES content was modified' + ) + + def test_describe_collections(config, api_): req = mock_api_request({"f": "html"}) rsp_headers, code, response = describe_collections(api_, req) From 18c9f7e059309feb0cd099c4efe32b549240b334 Mon Sep 17 00:00:00 2001 From: Francesco Bartoli Date: Tue, 10 Feb 2026 13:46:09 +0100 Subject: [PATCH 2/3] Fix flake8 --- tests/api/test_api.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/api/test_api.py b/tests/api/test_api.py index 5826d6078..f7768f9c2 100644 --- a/tests/api/test_api.py +++ b/tests/api/test_api.py @@ -568,11 +568,11 @@ def test_conformance(config, api_): def test_conformance_does_not_mutate_global_list(config, api_): - """Test the conformance function does not mutate the global CONFORMANCE_CLASSES. + """Test conformance method does not mutate CONFORMANCE_CLASSES. - This test verifies that the global CONFORMANCE_CLASSES list is not mutated - by calls to the conformance function. The base conformance classes should - remain unchanged after multiple calls. + This test verifies that the global CONFORMANCE_CLASSES list is not + mutated by calls to the conformance function. The base conformance + classes should remain unchanged after multiple calls. """ from pygeoapi.api import CONFORMANCE_CLASSES From 2be289e78cdd912142d2622657c254b883070f31 Mon Sep 17 00:00:00 2001 From: Francesco Bartoli Date: Tue, 10 Feb 2026 14:11:32 +0100 Subject: [PATCH 3/3] Move import and update copyright --- pygeoapi/api/__init__.py | 2 +- tests/api/test_api.py | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/pygeoapi/api/__init__.py b/pygeoapi/api/__init__.py index 96fbfd8a4..9116737a4 100644 --- a/pygeoapi/api/__init__.py +++ b/pygeoapi/api/__init__.py @@ -8,7 +8,7 @@ # Ricardo Garcia Silva # # Copyright (c) 2026 Tom Kralidis -# Copyright (c) 2025 Francesco Bartoli +# Copyright (c) 2026 Francesco Bartoli # Copyright (c) 2022 John A Stevenson and Colin Blackburn # Copyright (c) 2023 Ricardo Garcia Silva # diff --git a/tests/api/test_api.py b/tests/api/test_api.py index f7768f9c2..816fe8178 100644 --- a/tests/api/test_api.py +++ b/tests/api/test_api.py @@ -4,9 +4,11 @@ # John A Stevenson # Colin Blackburn # Bernhard Mallinger +# Francesco Bartoli # # Copyright (c) 2024 Tom Kralidis # Copyright (c) 2022 John A Stevenson and Colin Blackburn +# Copyright (c) 2026 Francesco Bartoli # # Permission is hereby granted, free of charge, to any person # obtaining a copy of this software and associated documentation @@ -39,10 +41,10 @@ import pytest from pygeoapi.api import ( - API, APIRequest, FORMAT_TYPES, F_HTML, F_JSON, F_JSONLD, F_GZIP, - __version__, validate_bbox, validate_datetime, evaluate_limit, - validate_subset, landing_page, openapi_, conformance, describe_collections, - get_collection_schema, + API, APIRequest, CONFORMANCE_CLASSES, FORMAT_TYPES, F_HTML, F_JSON, + F_JSONLD, F_GZIP, __version__, validate_bbox, validate_datetime, + evaluate_limit, validate_subset, landing_page, openapi_, conformance, + describe_collections, get_collection_schema, ) from pygeoapi.util import yaml_load, get_api_rules, get_base_url @@ -574,7 +576,6 @@ def test_conformance_does_not_mutate_global_list(config, api_): mutated by calls to the conformance function. The base conformance classes should remain unchanged after multiple calls. """ - from pygeoapi.api import CONFORMANCE_CLASSES # Store the original length and content of the global list original_length = len(CONFORMANCE_CLASSES)