From 8febed75f2ae88661b15e71afd88fb292920e553 Mon Sep 17 00:00:00 2001 From: Trim21 Date: Thu, 13 Feb 2025 13:09:05 +0800 Subject: [PATCH] run tests on windows --- .github/workflows/ci-tests.yml | 18 ++++++++++++++++++ cf_units/tests/test_coding_standards.py | 2 +- tox.ini | 5 ++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-tests.yml b/.github/workflows/ci-tests.yml index a062dd35..7cfb0eb9 100644 --- a/.github/workflows/ci-tests.yml +++ b/.github/workflows/ci-tests.yml @@ -45,6 +45,9 @@ jobs: # On macos, the up-to-date git may not be first on the path # N.B. setting includes a final ":", to simplify the path setting command gitpath-prepend: "/opt/homebrew/bin:" + - os: windows-latest + version: py313 + platform: win steps: - name: "Checkout" uses: actions/checkout@v4 @@ -105,6 +108,21 @@ jobs: path: ${{ github.workspace }}/.tox key: ${{ runner.os }}-tox-${{ env.ENV_NAME }}-${{ matrix.version }}-p${{ env.CACHE_PERIOD }}-b${{ env.CACHE_BUILD }}-${{ hashFiles(env.TOX_INI) }} + # setuptools can't find shared library installed by conda on windows + # so we need to prepare environment variables for it + - name: Export environment variables for UDUNITS2 lookup + if: runner.os == 'Windows' + uses: actions/github-script@v7 + with: + script: | + const path = require('path') + + const base = path.join('.tox/${{ matrix.version }}-${{ matrix.platform }}-test') + + core.exportVariable('UDUNITS2_INCDIR', path.join(base, 'Library/include/')); + core.exportVariable('UDUNITS2_LIBDIR', path.join(base, 'Library/lib/')); + core.exportVariable('UDUNITS2_XML_PATH', path.join(base, 'Library/share/udunits/udunits2.xml')); + - name: "Run ${{ matrix.os }} on ${{ matrix.version}} tests" run: | export PATH=${{ matrix.gitpath-prepend }}$PATH diff --git a/cf_units/tests/test_coding_standards.py b/cf_units/tests/test_coding_standards.py index bde08a77..fdf188dd 100644 --- a/cf_units/tests/test_coding_standards.py +++ b/cf_units/tests/test_coding_standards.py @@ -99,7 +99,7 @@ def test_license_headers(self): and full_fname.is_file() and not any(fnmatch(fname, pat) for pat in exclude_patterns) ): - with open(full_fname) as fh: + with open(full_fname, encoding="utf-8") as fh: content = fh.read() if not content.startswith(LICENSE_TEMPLATE): print( diff --git a/tox.ini b/tox.ini index 6179bde0..12e39dae 100644 --- a/tox.ini +++ b/tox.ini @@ -19,7 +19,7 @@ conda_deps = description = Create explicit environment specification conda lock files for cf-units dependencies. platform = - linux|darwin + linux|darwin|win32 setenv = LOCKDIR = {toxinidir}{/}requirements{/}locks TMPFILE = {envtmpdir}{/}cf-units.yml @@ -50,6 +50,9 @@ description = Perform cf-units unit/integration tests. passenv = CYTHON_COVERAGE + UDUNITS2_INCDIR + UDUNITS2_LIBDIR + UDUNITS2_XML_PATH usedevelop = true commands =