From 116c21456f96e72882aec53404e6e3775531f800 Mon Sep 17 00:00:00 2001 From: yrriban Date: Mon, 19 Jan 2026 13:05:29 -0500 Subject: [PATCH] Minor fixes to testing whether a demo exists. Add a unit test to validate functionality of this tricky corner of code. --- doomcc/doom_base.py | 6 ++++-- tests/doom_base_test.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 tests/doom_base_test.py diff --git a/doomcc/doom_base.py b/doomcc/doom_base.py index 16ae0f3..c12a867 100644 --- a/doomcc/doom_base.py +++ b/doomcc/doom_base.py @@ -132,8 +132,10 @@ class WadMap(Wad): ] if len(candidates) == 0: raise Exception( - "no suitable demo candidates for WAD {} MAP {} name {}.".format( - self.wad, self.map, self.name_string + "no suitable demo candidates for WAD {} MAP {}{}.".format( + self.wad, + self.map, + f" name {self._name}" if self._name else "", ) ) if len(candidates) == 1: diff --git a/tests/doom_base_test.py b/tests/doom_base_test.py new file mode 100644 index 0000000..5510fee --- /dev/null +++ b/tests/doom_base_test.py @@ -0,0 +1,28 @@ +import doomcc.doom_base +import os +import pathlib +import pytest +import tempfile + +class Workbench: + pass + +def test_demo_in_path(): + w = Workbench() + w.demo_in_path = lambda: doomcc.doom_base.WadMap.demo_in_path(w) + w._file_base = lambda path: doomcc.doom_base.WadMap._file_base(w, path) + w.wad = pathlib.Path("scythe") + w.map = "01" + w.name_string = "_index" + w._name = "index" + with tempfile.TemporaryDirectory() as td: + w.demos = pathlib.Path(td) + with pytest.raises(Exception): + w.demo_in_path() + + dp = pathlib.Path(td).joinpath("scythe") + os.mkdir(dp) + dp.joinpath("scythe_map01_index.lmp").touch() + assert w.demo_in_path() == dp.joinpath("scythe_map01_index.lmp") + dp.joinpath("scythe_map01_index-00028.lmp").touch() + assert w.demo_in_path() == dp.joinpath("scythe_map01_index-00028.lmp")