Skip to content

Commit

Permalink
Convert isolated tests to use Tox
Browse files Browse the repository at this point in the history
Remove setuptools upper bound

Skip more tests requiring SDL windows
  • Loading branch information
HexDecimal committed Oct 25, 2023
1 parent 086684f commit e3c33b0
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 16 deletions.
22 changes: 10 additions & 12 deletions .github/workflows/python-package.yml
Expand Up @@ -178,35 +178,33 @@ jobs:
working-directory: docs
run: python -m sphinx -T -E -W --keep-going . _build/html

isolated: # Test installing the package from source.
needs: [ruff, mypy, sdist]
tox:
needs: [ruff]
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ["ubuntu-latest", "windows-latest"]
steps:
- uses: actions/checkout@v3
with:
fetch-depth: ${{ env.git-depth }}
- name: Checkout submodules
run: git submodule update --init --depth 1
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.x
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install wheel
python -m pip install --upgrade pip tox
- name: Install APT dependencies
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install libsdl2-dev
- uses: actions/download-artifact@v3
with:
name: sdist
- name: Build package in isolation
run: |
pip install tcod-*.tar.gz
- name: Confirm package import
- name: Run tox
run: |
python -c "import tcod.context"
tox -vv
linux-wheels:
needs: [ruff, mypy]
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
@@ -1,8 +1,8 @@
[build-system]
requires = [
# Newer versions of setuptools break editable installs
# setuptools >=64.0.0 might break editable installs
# https://github.com/pypa/setuptools/issues/3548
"setuptools >=61.0.0, <64.0.0",
"setuptools >=61.0.0",
"setuptools_scm[toml]>=6.2",
"wheel>=0.37.1",
"cffi>=1.15",
Expand Down
9 changes: 9 additions & 0 deletions tests/conftest.py
Expand Up @@ -14,6 +14,15 @@ def pytest_addoption(parser: pytest.Parser) -> None:
parser.addoption("--no-window", action="store_true", help="Skip tests which need a rendering context.")


@pytest.fixture()
def uses_window(request: pytest.FixtureRequest) -> Iterator[None]:
"""Marks tests which require a rendering context."""
if request.config.getoption("--no-window"):
pytest.skip("This test needs a rendering context.")
yield None
return


@pytest.fixture(scope="session", params=["SDL", "SDL2"])
def session_console(request: pytest.FixtureRequest) -> Iterator[tcod.console.Console]:
if request.config.getoption("--no-window"):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_sdl.py
Expand Up @@ -11,7 +11,7 @@
# ruff: noqa: D103


def test_sdl_window() -> None:
def test_sdl_window(uses_window: None) -> None:
assert tcod.sdl.video.get_grabbed_window() is None
window = tcod.sdl.video.new_window(1, 1)
window.raise_window()
Expand Down Expand Up @@ -54,7 +54,7 @@ def test_sdl_screen_saver() -> None:
assert tcod.sdl.video.screen_saver_allowed() is True


def test_sdl_render() -> None:
def test_sdl_render(uses_window: None) -> None:
window = tcod.sdl.video.new_window(1, 1)
render = tcod.sdl.render.new_renderer(window, software=True, vsync=False, target_textures=True)
render.present()
Expand Down
17 changes: 17 additions & 0 deletions tox.ini
@@ -0,0 +1,17 @@
[tox]
isolated_build = True
env_list =
py311
minversion = 4.4.11

[testenv]
description = run the tests with pytest
package = wheel
wheel_build_env = .pkg
deps =
pytest>=6
pytest-cov
pytest-benchmark
pytest-timeout
commands =
pytest --no-window {tty:--color=yes} {posargs}

0 comments on commit e3c33b0

Please sign in to comment.