Skip to content

Commit 027f522

Browse files
committed
Convert isolated tests to use Tox
Remove setuptools upper bound Skip more tests requiring SDL windows
1 parent 086684f commit 027f522

File tree

6 files changed

+42
-18
lines changed

6 files changed

+42
-18
lines changed

.github/workflows/python-package.yml

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -178,35 +178,33 @@ jobs:
178178
working-directory: docs
179179
run: python -m sphinx -T -E -W --keep-going . _build/html
180180

181-
isolated: # Test installing the package from source.
182-
needs: [ruff, mypy, sdist]
181+
tox:
182+
needs: [ruff]
183183
runs-on: ${{ matrix.os }}
184184
strategy:
185185
matrix:
186186
os: ["ubuntu-latest", "windows-latest"]
187187
steps:
188+
- uses: actions/checkout@v3
189+
with:
190+
fetch-depth: ${{ env.git-depth }}
191+
- name: Checkout submodules
192+
run: git submodule update --init --depth 1
188193
- name: Set up Python
189194
uses: actions/setup-python@v4
190195
with:
191196
python-version: 3.x
192197
- name: Install Python dependencies
193198
run: |
194-
python -m pip install --upgrade pip
195-
pip install wheel
199+
python -m pip install --upgrade pip tox
196200
- name: Install APT dependencies
197201
if: runner.os == 'Linux'
198202
run: |
199203
sudo apt-get update
200204
sudo apt-get install libsdl2-dev
201-
- uses: actions/download-artifact@v3
202-
with:
203-
name: sdist
204-
- name: Build package in isolation
205-
run: |
206-
pip install tcod-*.tar.gz
207-
- name: Confirm package import
205+
- name: Run tox
208206
run: |
209-
python -c "import tcod.context"
207+
tox -vv
210208
211209
linux-wheels:
212210
needs: [ruff, mypy]

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[build-system]
22
requires = [
3-
# Newer versions of setuptools break editable installs
3+
# setuptools >=64.0.0 might break editable installs
44
# https://github.com/pypa/setuptools/issues/3548
5-
"setuptools >=61.0.0, <64.0.0",
5+
"setuptools >=61.0.0",
66
"setuptools_scm[toml]>=6.2",
77
"wheel>=0.37.1",
88
"cffi>=1.15",

tests/conftest.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ def pytest_addoption(parser: pytest.Parser) -> None:
1414
parser.addoption("--no-window", action="store_true", help="Skip tests which need a rendering context.")
1515

1616

17+
@pytest.fixture()
18+
def uses_window(request: pytest.FixtureRequest) -> Iterator[None]:
19+
"""Marks tests which require a rendering context."""
20+
if request.config.getoption("--no-window"):
21+
pytest.skip("This test needs a rendering context.")
22+
yield None
23+
return
24+
25+
1726
@pytest.fixture(scope="session", params=["SDL", "SDL2"])
1827
def session_console(request: pytest.FixtureRequest) -> Iterator[tcod.console.Console]:
1928
if request.config.getoption("--no-window"):

tests/test_sdl.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# ruff: noqa: D103
1212

1313

14-
def test_sdl_window() -> None:
14+
def test_sdl_window(uses_window: None) -> None:
1515
assert tcod.sdl.video.get_grabbed_window() is None
1616
window = tcod.sdl.video.new_window(1, 1)
1717
window.raise_window()
@@ -47,14 +47,14 @@ def test_sdl_window_bad_types() -> None:
4747
tcod.sdl.video.Window(tcod.ffi.new("SDL_Rect*"))
4848

4949

50-
def test_sdl_screen_saver() -> None:
50+
def test_sdl_screen_saver(uses_window: None) -> None:
5151
tcod.sdl.sys.init()
5252
assert tcod.sdl.video.screen_saver_allowed(False) is False
5353
assert tcod.sdl.video.screen_saver_allowed(True) is True
5454
assert tcod.sdl.video.screen_saver_allowed() is True
5555

5656

57-
def test_sdl_render() -> None:
57+
def test_sdl_render(uses_window: None) -> None:
5858
window = tcod.sdl.video.new_window(1, 1)
5959
render = tcod.sdl.render.new_renderer(window, software=True, vsync=False, target_textures=True)
6060
render.present()

tests/test_tcod.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def test_recommended_size(console: tcod.console.Console) -> None:
186186

187187

188188
@pytest.mark.filterwarnings("ignore")
189-
def test_context() -> None:
189+
def test_context(uses_window: None) -> None:
190190
with tcod.context.new_window(32, 32, renderer=tcod.RENDERER_SDL2):
191191
pass
192192
WIDTH, HEIGHT = 16, 4

tox.ini

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[tox]
2+
isolated_build = True
3+
env_list =
4+
py311
5+
minversion = 4.4.11
6+
7+
[testenv]
8+
description = run the tests with pytest
9+
package = wheel
10+
wheel_build_env = .pkg
11+
deps =
12+
pytest>=6
13+
pytest-cov
14+
pytest-benchmark
15+
pytest-timeout
16+
commands =
17+
pytest --no-window {tty:--color=yes} {posargs}

0 commit comments

Comments
 (0)