Files
IPSExtractor/bots/bot_digitador/tests/test_packaging.py
T

36 lines
1.5 KiB
Python

from __future__ import annotations
import importlib.util
from pathlib import Path
from zipfile import ZipFile
from bot_digitador.core.config import REQUIRED_TEMPLATE_NAMES
SCRIPT = Path(__file__).resolve().parents[1] / "scripts" / "package_bot.py"
SPEC = importlib.util.spec_from_file_location("digitador_package_bot", SCRIPT)
assert SPEC and SPEC.loader
package_bot = importlib.util.module_from_spec(SPEC)
SPEC.loader.exec_module(package_bot)
def test_package_is_clean_and_contains_required_templates(tmp_path):
root = tmp_path / "source"
(root / "bot_digitador" / "core").mkdir(parents=True)
(root / "template").mkdir()
for name in ("README.md", "requirements.txt", "run_gui.py", "main.py", ".env.example"):
(root / name).write_text(name, encoding="utf-8")
(root / "bot_digitador" / "core" / "service.py").write_text("pass", encoding="utf-8")
(root / "bot_digitador" / "core" / "cached.pyc").write_bytes(b"cache")
(root / "data").mkdir()
(root / "data" / "gui_settings.json").write_text("secret", encoding="utf-8")
for name in REQUIRED_TEMPLATE_NAMES:
(root / "template" / name).write_bytes(b"png")
target = package_bot.build_package(root=root, output=tmp_path / "bot.zip")
with ZipFile(target) as archive:
names = archive.namelist()
assert "bot_digitador/template/radicado_existente.png" in names
assert not any("__pycache__" in name or name.endswith(".pyc") or "/data/" in name for name in names)