mirror of
https://github.com/EDeev/converterbot.git
synced 2026-10-07 20:49:33 +03:00
Тесты проверяют номер страницы, шрифт заголовков, списки, структурные заголовки, таблицы, CLI, защиту от zip-бомбы и разбор архива. По тегу v* пакет md2gost уходит на PyPI, образ бота — в GHCR и dcr.deev.su. В requirements.txt убраны неиспользуемые aiohttp, aiofiles, certifi.
41 lines
1.4 KiB
Python
41 lines
1.4 KiB
Python
import io
|
|
import os
|
|
import zipfile
|
|
|
|
import pytest
|
|
|
|
os.environ.setdefault("BOT_TOKEN", "123456:TEST")
|
|
|
|
import bot # noqa: E402
|
|
from rep_to_txt import generate_complete_project_structure # noqa: E402
|
|
|
|
|
|
def test_zip_bomb_is_rejected(tmp_path, monkeypatch):
|
|
monkeypatch.setattr(bot, "MAX_UNPACKED_SIZE", 1000)
|
|
archive = tmp_path / "a.zip"
|
|
with zipfile.ZipFile(archive, "w", zipfile.ZIP_DEFLATED) as z:
|
|
z.writestr("big.txt", "0" * 10_000)
|
|
with pytest.raises(bot.ArchiveTooLarge):
|
|
bot.analyze_archive(str(archive), str(tmp_path))
|
|
|
|
|
|
def test_archive_structure(tmp_path):
|
|
archive = tmp_path / "p.zip"
|
|
with zipfile.ZipFile(archive, "w") as z:
|
|
z.writestr("proj/main.py", "print(1)\n")
|
|
z.writestr("proj/img.png", b"\x89PNG\x00")
|
|
z.writestr("proj/node_modules/x.js", "ignored")
|
|
text = open(bot.analyze_archive(str(archive), str(tmp_path)), encoding="utf-8").read()
|
|
assert "main.py" in text and " 1 | print(1)" in text
|
|
assert "[Image - content not displayed]" in text and "node_modules" not in text
|
|
|
|
|
|
def test_structure_of_missing_path():
|
|
assert generate_complete_project_structure("/no/such/dir").startswith("Error")
|
|
|
|
|
|
def test_docx_conversion_in_bot(tmp_path):
|
|
md = tmp_path / "a.md"
|
|
md.write_text("# Тест\n", encoding="utf-8")
|
|
out = bot.convert_md_to_docx(str(md), str(tmp_path))
|
|
assert zipfile.is_zipfile(io.BytesIO(open(out, "rb").read()))
|