-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from European-XFEL/tests
Tests
- Loading branch information
Showing
3 changed files
with
100 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
name: Tests | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
|
||
jobs: | ||
test_pyenv: | ||
runs-on: ubuntu-latest | ||
name: Test with pyenv | ||
steps: | ||
- name: Install python build tools | ||
# Ref: https://github.com/pyenv/pyenv/wiki#suggested-build-environment | ||
run: | | ||
sudo apt-get update -y | ||
sudo apt-get install -y make build-essential libssl-dev zlib1g-dev \ | ||
libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm \ | ||
libncursesw5-dev xz-utils libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev | ||
- name: Install pyenv | ||
run: | | ||
git clone https://github.com/pyenv/pyenv.git "$HOME/.pyenv" | ||
PYENV_ROOT="$HOME/.pyenv" | ||
PYENV_BIN="$PYENV_ROOT/bin" | ||
echo "$PYENV_BIN" >> $GITHUB_PATH | ||
echo "PYENV_ROOT=$PYENV_ROOT" >> $GITHUB_ENV | ||
- name: Check pyenv version | ||
run: | | ||
pyenv --version | ||
- name: Cache pyenv installed version | ||
uses: actions/cache@v4 | ||
with: | ||
path: ~/.pyenv/versions | ||
key: ${{ runner.os }}-pyenv-3.11.10-b | ||
|
||
# Doing this beforehand should make the test itself faster | ||
- name: Preinstall Python 3.11.10 | ||
run: | | ||
pyenv install -v --skip-existing 3.11.10 | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Test with pytest | ||
run: | | ||
python3 -m pip install pytest | ||
python3 -m pytest -v |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from shutil import which | ||
from subprocess import run, PIPE, STDOUT | ||
import sys | ||
|
||
import pytest | ||
|
||
from env_cache import (EnvsManager, FixedPythonEnvMaker, PyenvEnvMaker) | ||
|
||
@pytest.mark.skipif(sys.version_info.releaselevel != 'final', reason='pre-release Python') | ||
def test_fixed_python(tmp_path): | ||
vi = sys.version_info | ||
version = f"{vi.major}.{vi.minor}.{vi.micro}" | ||
|
||
mgr = EnvsManager(tmp_path, FixedPythonEnvMaker(sys.executable)) | ||
env = mgr.get_env(version, "flit_core==3.10.1") | ||
assert env.is_relative_to(tmp_path) | ||
env_py = env / 'bin' / 'python' | ||
assert env_py.is_file() | ||
r = run([env_py, '-c', 'import flit_core'], stdout=PIPE, stderr=STDOUT) | ||
if r.stdout: | ||
print(r.stdout) | ||
assert r.returncode == 0 | ||
|
||
# Asking for an env with the same specifications should reuse it | ||
env_again = mgr.get_env(version, "flit_core==3.10.1") | ||
assert env_again == env | ||
|
||
|
||
def test_fixed_python_wrong_version(tmp_path): | ||
mgr = EnvsManager(tmp_path, FixedPythonEnvMaker(sys.executable)) | ||
# Assume this test will never run on Python 3.2.1 | ||
with pytest.raises(ValueError, match="not 3.2.1"): | ||
mgr.get_env("3.2.1", "") | ||
|
||
|
||
@pytest.mark.skipif(which('pyenv') is None, reason="pyenv not available") | ||
def test_pyenv(tmp_path): | ||
version = "3.11.10" | ||
mgr = EnvsManager(tmp_path, PyenvEnvMaker()) | ||
env = mgr.get_env(version, "flit_core==3.10.1") | ||
assert env.is_relative_to(tmp_path) | ||
env_py = env / 'bin' / 'python' | ||
assert env_py.is_file() | ||
r = run([env_py, '-c', 'import flit_core'], stdout=PIPE, stderr=STDOUT) | ||
if r.stdout: | ||
print(r.stdout) | ||
assert r.returncode == 0 | ||
|
||
# Asking for an env with the same specifications should reuse it | ||
env_again = mgr.get_env(version, "flit_core==3.10.1") | ||
assert env_again == env |