test: add 11 tests for install.bat file references and version consistency; fix pyproject.toml version 0.8.1->0.8.4

This commit is contained in:
alexpolo1
2026-08-07 09:54:24 +02:00
parent 02e9f7856a
commit 8f9185cde3
3 changed files with 108 additions and 1 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
[project]
name = "botty"
version = "0.8.1"
version = "0.8.4"
description = "Pixelbot for Diablo 2 Resurrected"
requires-python = ">=3.10,<3.11"
dependencies = [
+67
View File
@@ -0,0 +1,67 @@
"""Test that install.bat references files that actually exist in the repo.
Catches: deleted dependency files, renamed requirements, missing environment.yml.
"""
import os
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Files install.bat references by name (not env vars or paths)
REQUIRED_FILES = [
"requirements.txt",
"requirements-win10.txt",
"requirements-win11.txt",
"environment.yml",
"environment-win10.yml",
"environment-win11.yml",
"find_python.bat",
]
# Files that may or may not exist depending on the branch
OPTIONAL_FILES = [
"dependencies/tesseract52.dll",
"dependencies/tesserocr.cp310-win_amd64.pyd",
"dependencies/tesserocr-2.5.2-cp310-cp310-win_amd64.whl",
]
def _exists(name):
return os.path.isfile(os.path.join(ROOT, name))
class TestInstallBatReferences:
def test_required_files_exist(self):
missing = [f for f in REQUIRED_FILES if not _exists(f)]
assert not missing, f"install.bat references missing files: {missing}"
def test_optional_files_at_least_one_exists(self):
existing = [f for f in OPTIONAL_FILES if _exists(f)]
assert len(existing) >= 1, (
"install.bat references tesseract/tesserocr dependencies but none exist in "
"dependencies/ directory — install.bat will silently skip OCR setup"
)
def test_install_bat_exists(self):
assert _exists("install.bat"), "install.bat is missing from repo root"
def test_run_botty_bat_exists(self):
assert _exists("run_botty.bat"), "run_botty.bat is missing from repo root"
def test_config_params_exists(self):
assert _exists("config/params.ini"), "config/params.ini is missing"
def test_config_game_ini_exists(self):
assert _exists("config/game.ini"), "config/game.ini is missing"
def test_tessdata_directory_exists(self):
tessdata = os.path.join(ROOT, "assets", "tessdata")
assert os.path.isdir(tessdata), "assets/tessdata/ directory is missing"
def test_tessdata_has_traineddata(self):
tessdata = os.path.join(ROOT, "assets", "tessdata")
trained = [f for f in os.listdir(tessdata) if f.endswith(".traineddata")]
assert len(trained) >= 1, "assets/tessdata/ has no .traineddata files"
def test_src_main_exists(self):
assert _exists("src/main.py"), "src/main.py is missing"
+40
View File
@@ -0,0 +1,40 @@
"""Test that version.py matches pyproject.toml version.
Catches: version bump in one place but not the other.
"""
import os
import re
import tomllib
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
def _read_version_py():
path = os.path.join(ROOT, "src", "version.py")
with open(path) as f:
content = f.read()
m = re.search(r"__version__\s*=\s*'([^']+)'", content)
return m.group(1) if m else None
def _read_pyproject_version():
path = os.path.join(ROOT, "pyproject.toml")
with open(path, "rb") as f:
data = tomllib.load(f)
return data.get("project", {}).get("version")
class TestVersionConsistency:
def test_version_py_matches_pyproject(self):
v_py = _read_version_py()
v_proj = _read_pyproject_version()
assert v_py is not None, "Could not read __version__ from src/version.py"
assert v_proj is not None, "Could not read version from pyproject.toml"
assert v_py == v_proj, (
f"Version mismatch: version.py={v_py}, pyproject.toml={v_proj}"
)
def test_version_is_semver(self):
v = _read_version_py()
assert re.match(r"^\d+\.\d+\.\d+", v), f"Version '{v}' is not semver"