Skip to content

Commit

Permalink
Fixup pytest tmp dir and re-locate nce. (#90)
Browse files Browse the repository at this point in the history
This should avoid Windows long path issues and comports with our self
hosted runner TMP dir setup.
  • Loading branch information
jsirois authored Sep 7, 2024
1 parent 351ff9d commit ca486c4
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ jobs:
- name: Configure Windows pytest short tmp dir path
if: matrix.os == 'windows-2022' || matrix.os == 'windows-arm64'
run: |
echo PYTEST_ADDOPTS="--basetemp C:\\tmp\\pytest" >> ${GITHUB_ENV}
mkdir -p C:/tmp/gha
echo PYTEST_ADDOPTS="--basetemp C:/tmp/gha/pytest" >> ${GITHUB_ENV}
echo SCIE_BASE=C:/tmp/gha/nce >> ${GITHUB_ENV}
- name: Unit Tests
run: nox -e test -- -vvs
- name: Build & Package
Expand Down
6 changes: 5 additions & 1 deletion tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,15 @@ def test_scie_base(tmp_path: Path, science_pyz: Path) -> None:
)
assert expected_base == data["scie"]["lift"]["base"]
expanded_base = os.path.expanduser(expected_base)

# Ensure our configured scie base is not over-ridden.
env = os.environ.copy()
env.pop("SCIE_BASE", None)
try:
assert (
f"Hello from {expanded_base}!"
== subprocess.run(
args=[exe_path], stdout=subprocess.PIPE, text=True, check=True
args=[exe_path], env=env, stdout=subprocess.PIPE, text=True, check=True
).stdout.strip()
)
finally:
Expand Down
11 changes: 9 additions & 2 deletions tests/test_exe.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from dataclasses import dataclass
from pathlib import Path
from shutil import which
from subprocess import CalledProcessError
from textwrap import dedent
from typing import Any, Iterable

Expand Down Expand Up @@ -92,10 +93,16 @@ def test_use_platform_suffix(

@pytest.fixture(scope="module")
def shasum() -> str | None:
shasum = which("shasum")
if not (shasum := which("shasum")):
return None

# N.B.: We check to see if shasum actually works since GH Actions Windows 2022 boxes come with a
# shasum.BAT on the PATH that runs via a perl.exe not on the PATH leading to error.
return shasum if shasum and subprocess.run(args=[shasum, "--version"]).returncode == 0 else None
try:
subprocess.run(args=[shasum, "--version"], check=True)
return shasum
except (CalledProcessError, OSError):
return None


def test_hash(
Expand Down
26 changes: 24 additions & 2 deletions tests/test_installer.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Copyright 2024 Science project contributors.
# Licensed under the Apache License, Version 2.0 (see LICENSE).

import shutil
import subprocess
from pathlib import Path
from pathlib import Path, PurePath

import pytest
from _pytest.tmpdir import TempPathFactory
Expand All @@ -13,7 +14,28 @@
@pytest.fixture(scope="module")
def installer(build_root: Path) -> list:
installer = build_root / "install.sh"
return [Path(r"C:\Program Files\Git\bin\bash.EXE"), installer] if IS_WINDOWS else [installer]
if IS_WINDOWS:
# TODO(John Sirois): Get rid of all this shenanigans and write an install.ps1 instead:
# https://github.com/a-scie/lift/issues/91

# Given a git for Windows install at C:\Program Files\Git, we will find the git executable
# at one of these two locations:
# + Running under cmd or pwsh, etc.: C:\Program Files\Git\cmd\git.EXE
# + Running under git bash: C:\Program Files\Git\mingw64\bin\git.EXE
# We expect the msys2 root to be at the git for Windows install root, which is
# C:\Program Files\Git in this case.
assert (git := shutil.which("git")) is not None, "This test requires Git bash on Windows."
msys2_root = PurePath(git).parent.parent
if "mingw64" == msys2_root.name:
msys2_root = msys2_root.parent

assert (bash := shutil.which("bash", path=msys2_root / "usr" / "bin")) is not None, (
f"The git executable at {git} does not appear to have msys2 root at the expected path "
f"of {msys2_root}."
)
return [bash, installer]
else:
return [installer]


def run_captured(cmd: list):
Expand Down

0 comments on commit ca486c4

Please sign in to comment.