From 39fe024874f99d43b18ca8073497e2e69e35bde7 Mon Sep 17 00:00:00 2001 From: Alan Date: Thu, 1 Oct 2026 08:18:23 +0800 Subject: [PATCH] Handle missing optional Tags in OpenSearch descriptions --- owslib/opensearch.py | 2 +- tests/test_opensearch.py | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 tests/test_opensearch.py diff --git a/owslib/opensearch.py b/owslib/opensearch.py index 616122cd..65b660de 100644 --- a/owslib/opensearch.py +++ b/owslib/opensearch.py @@ -167,7 +167,7 @@ def __init__(self, md): self.outputencoding = testXMLValue(val) val = md.find(nspath_eval('os:Tags', namespaces)) - self.tags = testXMLValue(val).split() + self.tags = (testXMLValue(val) or '').split() val = md.find(nspath_eval('os:Contact', namespaces)) self.contact = testXMLValue(val) diff --git a/tests/test_opensearch.py b/tests/test_opensearch.py new file mode 100644 index 00000000..0336768e --- /dev/null +++ b/tests/test_opensearch.py @@ -0,0 +1,27 @@ +import pytest + +from owslib.opensearch import OpenSearch + + +@pytest.mark.parametrize('tags_xml, expected_tags', [ + ('', []), + ('', []), + (' ', []), + ('earth observation', ['earth', 'observation']), +]) +def test_opensearch_description_optional_tags(tags_xml, expected_tags): + xml = f''' + Example search + Search public observations + + {tags_xml} + ''' + + client = OpenSearch('https://example.com/opensearch', xml=xml) + + assert client.description.tags == expected_tags + assert client.description.shortname == 'Example search' + assert client.description.urls['application/atom+xml']['template'] == ( + 'https://example.com/search?q={searchTerms}' + )