Skip to content

Commit

Permalink
pytest: Add initial menu tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mrannanj committed Dec 4, 2024
1 parent 77c707f commit 9dc860b
Show file tree
Hide file tree
Showing 6 changed files with 226 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ cmake-build-debug/
cmake-build-release/
.cache
compile_commands.json
__pycache__
*.pyc
5 changes: 5 additions & 0 deletions lsan.supp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# libconfuse
leak:libconfuse

# SDL leak
leak:has_gl_available
156 changes: 156 additions & 0 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[tool.poetry]
package-mode = false

[tool.poetry.dependencies]
python = "^3.10"
pytest = "^8.3"
pexpect = "^4.9.0"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
41 changes: 41 additions & 0 deletions pytest/test_menus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import sys
import os
import time
from pexpect import popen_spawn, EOF
from contextlib import contextmanager


@contextmanager
def start_openomf():
lsan_env = os.environ
lsan_env["LSAN_OPTIONS"] = "suppressions=../lsan.supp"
openomf_bin = os.environ["OPENOMF_BIN"]
build_dir = os.environ["BUILD_DIR"]
p = popen_spawn.PopenSpawn([openomf_bin, "--force-renderer", "NULL",
"--force-audio-backend", "NULL"],
timeout=60, cwd=build_dir, encoding='utf-8',
logfile=sys.stdout, env=lsan_env)
try:
yield p
finally:
p.wait()


def test_tournament_menu():
with start_openomf() as p:
time.sleep(1)
p.sendline("scene SCENE_MENU")
p.expect("Loaded scene SCENE_MENU", timeout=180)
time.sleep(1)
p.sendline("scene SCENE_MECHLAB")
p.expect("Loaded scene SCENE_MECHLAB", timeout=180)
time.sleep(1)
p.sendline("quit")
p.expect(EOF, timeout=180)


def test_quit():
with start_openomf() as p:
time.sleep(1)
p.sendline("quit")
p.expect(EOF, timeout=60)
11 changes: 11 additions & 0 deletions run_pytest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

if [ -z "$2" ]; then
echo "Usage: $0 <build-dir> <openomf-executable>" >&2
exit 1
fi

export BUILD_DIR="$1"
export OPENOMF_BIN="$2"

exec poetry run pytest -vrP pytest

0 comments on commit 9dc860b

Please sign in to comment.