From d3a06d36c90ec7e64088c410fbd9b082247e7479 Mon Sep 17 00:00:00 2001 From: Seth G Date: Thu, 24 Oct 2024 15:21:03 +0200 Subject: [PATCH] Add Windows Build Action with Tests (#950) * Ensure any starting slash on Windows is removed * Open as utf-8 or tests fail on Windows * Add Windows workflow * No need for docs requirements --- .github/workflows/windows.yml | 25 +++++++++++++++++++++++++ owslib/wps.py | 7 ++++++- tests/test_iso3_parsing.py | 8 ++++---- 3 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/windows.yml diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml new file mode 100644 index 00000000..e6180ef2 --- /dev/null +++ b/.github/workflows/windows.yml @@ -0,0 +1,25 @@ +name: build on Windows ⚙️ + +on: [ push, pull_request ] + +jobs: + main: + runs-on: windows-latest + strategy: + matrix: + python-version: ["3.11"] + steps: + - uses: actions/checkout@master + - uses: actions/setup-python@v5 + name: Setup Python ${{ matrix.python-version }} + with: + python-version: ${{ matrix.python-version }} + + - name: Install requirements 📦 + run: | + pip install -e . + pip install -r requirements.txt + pip install -r requirements-dev.txt + + - name: run tests ⚙️ + run: python -m pytest diff --git a/owslib/wps.py b/owslib/wps.py index 950ebad1..cd250285 100644 --- a/owslib/wps.py +++ b/owslib/wps.py @@ -118,6 +118,7 @@ from owslib.namespaces import Namespaces from urllib.parse import urlparse import warnings +import os # namespace definition n = Namespaces() @@ -1446,7 +1447,11 @@ def retrieveData(self, username=None, password=None, headers=None, verify=True, # The link is a local file. # Useful when running local tests during development. if url.startswith("file://"): - with open(url[7:]) as f: + fn = url[7:] + # If on Windows and path starts with a '/', remove it + if os.name == 'nt' and fn.startswith('/'): + fn = fn[1:] + with open(fn) as f: return f.read() if '?' in url: diff --git a/tests/test_iso3_parsing.py b/tests/test_iso3_parsing.py index a1525281..7e121578 100644 --- a/tests/test_iso3_parsing.py +++ b/tests/test_iso3_parsing.py @@ -302,7 +302,7 @@ def bmd(): Source: https://metawal.wallonie.be/geonetwork """ belgian_sample = str(Path(__file__).parent.parent / "tests" / "resources" / "iso3_examples" / "metawal.wallonie.be-catchments.xml") - with open(belgian_sample, "r") as f_d: + with open(belgian_sample, "r", encoding="utf-8") as f_d: xml_list = f_d.readlines() xml_str = ''.join(xml_list) xml_bytes = bytes(xml_str, encoding='utf-8') @@ -462,7 +462,7 @@ def amd(): Source: https://portal.auscope.org.au/geonetwork """ aust_sample = str(Path(__file__).parent.parent / "tests" / "resources" / "iso3_examples" / "auscope-3d-model.xml") - with open(aust_sample, "r") as f_d: + with open(aust_sample, "r", encoding="utf-8") as f_d: xml_list = f_d.readlines() xml_str = ''.join(xml_list) xml_bytes = bytes(xml_str, encoding='utf-8') @@ -518,7 +518,7 @@ def smd(): Source: https://metawal.wallonie.be/geonetwork """ belgian_srv_sample = str(Path(__file__).parent.parent / "tests" / "resources" / "iso3_examples" / "metawal.wallonie.be-srv.xml") - with open(belgian_srv_sample, "r") as f_d: + with open(belgian_srv_sample, "r", encoding="utf-8") as f_d: xml_list = f_d.readlines() xml_str = ''.join(xml_list) xml_bytes = bytes(xml_str, encoding='utf-8') @@ -554,7 +554,7 @@ def emd(): Source: https://github.com/Esri/arcgis-pro-metadata-toolkit """ arcgis_sample = str(Path(__file__).parent.parent / "tests" / "resources" / "iso3_examples" / "arcgis-sample.xml") - with open(arcgis_sample, "r") as f_d: + with open(arcgis_sample, "r", encoding="utf-8") as f_d: xml_list = f_d.readlines() xml_str = ''.join(xml_list) xml_bytes = bytes(xml_str, encoding='utf-8')