doomcc/tests/play_test.py
yrriban edbf4f2a0e Use os.execv instead of subprocess.run when no further action is taken.
This prevents the underlying file from being marked busy while a
long-running action is happening (e.g. eureka is open).
2025-12-24 18:09:49 -05:00

51 lines
1.5 KiB
Python

import cliff.app
import dcc.play
import logging
import os
import mockito.matchers
import pathlib
import tempfile
logger = logging.getLogger(__name__)
def test_play(expect):
with tempfile.TemporaryDirectory() as td:
tdp = pathlib.Path(td)
tdp.joinpath("config.toml").write_text(
"""
dsda = "dsda-doom/exe"
iwad = "DOOM2.WAD"
complevel = "2"
"""
)
pwp = tdp.joinpath("pwads")
pwp.mkdir()
scp = pwp.joinpath("scythe")
scp.mkdir()
scp.joinpath("config.toml").touch()
scp.joinpath("scythe.wad").touch()
dcc.play.Play.__init__ = lambda self: None
dcc.play.Play.get_epilog = lambda self: ""
rig = dcc.play.Play()
rig._hooks = []
parser = rig.get_parser("test_play")
parsed_args = parser.parse_args(args=["--doom", td, "scythe", "01"])
with expect(os, times=1).execv(
tdp.joinpath("dsda-doom").joinpath("exe"),
[
tdp.joinpath("dsda-doom").joinpath("exe"),
"-iwad",
tdp.joinpath("iwads").joinpath("DOOM2.WAD"),
"-file",
tdp.joinpath("pwads").joinpath("scythe").joinpath("scythe.wad"),
"-complevel",
"2",
"-skill",
"4",
"-warp",
"01",
]
).thenReturn(None):
assert rig.run(parsed_args) is None