v0.6.0 BigUpdate
Example document / build (push) Has been cancelled
Python application / build (push) Has been cancelled

This commit is contained in:
Igor20264
2026-10-20 11:38:06 +03:00
parent daa84f8bce
commit 8223e0ac14
77 changed files with 12158 additions and 117 deletions
+51 -1
View File
@@ -17,6 +17,7 @@ from md2gost.office import (
fix_continuations_with_engine,
resolve_office_engine,
)
from md2gost.office.detect import clear_office_engine_cache
from md2gost.office import uno_fix
from md2gost.office import uno_profile
from md2gost.office.uno_cli import soffice_cli_path
@@ -49,6 +50,13 @@ def test_parser_office_engine_libre():
assert req.office_engine == "libre"
@pytest.fixture(autouse=True)
def _clear_office_cache():
clear_office_engine_cache()
yield
clear_office_engine_cache()
@patch("md2gost.office.detect._detect_word")
@patch("md2gost.office.detect._find_soffice_install")
def test_resolve_auto_prefers_word(mock_lo, mock_word):
@@ -112,6 +120,29 @@ def test_detect_libre_from_custom_path(tmp_path):
assert install.python_path == str(python_bin)
@patch("md2gost.office.detect._word_com_available", return_value=True)
def test_detect_word_without_starting_com(_mock_avail):
install = detect_office_install("word")
assert install is not None
assert install.engine == "word"
@patch("md2gost.office.detect._detect_word")
@patch("md2gost.office.detect._find_soffice_install")
def test_resolve_auto_cached_on_second_call(mock_lo, mock_word):
mock_word.return_value = OfficeInstall(engine="word", label="Microsoft Word")
mock_lo.return_value = OfficeInstall(
engine="libre",
label="LibreOffice",
soffice_path=r"C:\LibreOffice\program\soffice.exe",
python_path=r"C:\LibreOffice\program\python.exe",
)
first = resolve_office_engine("auto")
second = resolve_office_engine("auto")
assert first == second == ("word", mock_word.return_value)
mock_word.assert_called_once()
@patch("md2gost.office.dispatch.fix_continuations")
@patch("md2gost.office.dispatch.resolve_office_engine")
def test_dispatch_word_backend(mock_resolve, mock_word_fix):
@@ -122,6 +153,21 @@ def test_dispatch_word_backend(mock_resolve, mock_word_fix):
mock_word_fix.assert_called_once()
@patch("md2gost.office.dispatch.fix_continuations")
@patch("md2gost.office.dispatch.resolve_office_engine")
def test_dispatch_uses_preresolved_install(mock_resolve, mock_word_fix):
install = OfficeInstall(engine="word", label="Microsoft Word")
mock_word_fix.return_value = FixResult(True, splits=1, message="ok")
result = fix_continuations_with_engine(
"report.docx",
engine="word",
install=install,
)
assert result.ok is True
mock_resolve.assert_not_called()
mock_word_fix.assert_called_once()
@patch("md2gost.office.dispatch.fix_continuations_uno")
@patch("md2gost.office.dispatch.resolve_office_engine")
def test_dispatch_libre_backend(mock_resolve, mock_uno):
@@ -199,7 +245,9 @@ def test_uno_call_method_or_attribute():
assert uno_call(_DocAttr(), "Text") == "attr"
def test_uno_worker_env_includes_program_dir():
def test_uno_worker_env_includes_program_dir(monkeypatch):
monkeypatch.setenv("PYTHONHOME", r"C:\Python310")
monkeypatch.setenv("PYTHONPATH", r"C:\Python310\Lib")
install = OfficeInstall(
engine="openoffice",
label="OpenOffice",
@@ -209,6 +257,8 @@ def test_uno_worker_env_includes_program_dir():
worker_dir = Path(r"C:\temp\worker")
with patch.object(uno_fix, "_office_program_dir", return_value=Path(r"C:\OpenOffice 4\program")):
env, cwd = uno_fix._uno_worker_env(worker_dir, install)
assert "PYTHONHOME" not in env
assert r"C:\Python310\Lib" not in env["PYTHONPATH"]
assert r"C:\OpenOffice 4\program" in env["PYTHONPATH"]
assert str(worker_dir) in env["PYTHONPATH"]
assert cwd == Path(r"C:\OpenOffice 4\program")