release: ship validated Mentor PDF exporter v1.0.0
This commit is contained in:
1 parent
d4928af5b6
commit
0334f2b85b
50 files changed
+3998
-219
No files matched your search
+63
-3
@@ -1,4 +1,5 @@
|
||||
import json
|
||||
import pytest
|
||||
from pathlib import Path
|
||||
from mentor_pdf_export.cli import main
|
||||
|
||||
@@ -7,7 +8,8 @@ def test_self_check_writes_machine_readable_report(tmp_path):
|
||||
report=tmp_path / "check.json"
|
||||
assert main(["--self-check","--report",str(report)]) == 0
|
||||
data=json.loads(report.read_text(encoding="utf-8"))
|
||||
assert data["version"] == "0.1.0"
|
||||
from mentor_pdf_export import __version__
|
||||
assert data["version"] == __version__
|
||||
assert "engine_available" in data
|
||||
|
||||
|
||||
@@ -29,7 +31,7 @@ def test_report_inside_source_is_rejected_before_export(project_factory,tmp_path
|
||||
project=project_factory()
|
||||
protected=project.parent/"settings.json";protected.write_text("original")
|
||||
engine=tmp_path/"sch2pdf.exe";engine.write_bytes(b"fake")
|
||||
def runner(args,*rest):
|
||||
def runner(args,*rest,env=None):
|
||||
writer=PdfWriter();writer.add_blank_page(width=500,height=400)
|
||||
with Path(args[args.index("-a")+1]).open("wb") as out:writer.write(out)
|
||||
return 0
|
||||
@@ -48,7 +50,7 @@ def test_queue_destinations_protect_every_source_before_first_export(project_fac
|
||||
a=project_factory("a");b=project_factory("b")
|
||||
engine=tmp_path/"sch2pdf.exe";engine.write_bytes(b"fake")
|
||||
before=fingerprint(b.parent)
|
||||
def runner(args,*rest):
|
||||
def runner(args,*rest,env=None):
|
||||
writer=PdfWriter();writer.add_blank_page(width=500,height=400)
|
||||
with Path(args[args.index("-a")+1]).open("wb") as out:writer.write(out)
|
||||
return 0
|
||||
@@ -70,3 +72,61 @@ def test_self_check_can_refresh_its_own_report(tmp_path):
|
||||
report=tmp_path/"self-check.json"
|
||||
assert main(["--self-check","--report",str(report)]) == 0
|
||||
assert main(["--self-check","--report",str(report)]) == 0
|
||||
|
||||
|
||||
def test_cli_accepts_explicit_print_and_font_profiles(tmp_path):
|
||||
report=tmp_path/"style-check.json"
|
||||
assert main(["--self-check","--font-mapping","arial","--print-theme","high_contrast","--report",str(report)])==0
|
||||
|
||||
|
||||
def test_cli_rejects_library_replacement_in_direct_mode(tmp_path):
|
||||
assert main(["--self-check","--library",str(tmp_path/"matching.lmc")])==2
|
||||
|
||||
|
||||
@pytest.mark.parametrize('strict',[False,True])
|
||||
def test_cli_native_update_warning_exit_and_strict_fallback(project_factory,tmp_path,monkeypatch,strict):
|
||||
from mentor_pdf_export import cli
|
||||
from mentor_pdf_export.exporter import Exporter
|
||||
from pypdf import PdfWriter
|
||||
project=project_factory();engine=tmp_path/'sch2pdf.exe';engine.write_bytes(b'fake')
|
||||
def runner(args,*rest,env=None):
|
||||
writer=PdfWriter();writer.add_blank_page(width=500,height=400)
|
||||
with Path(args[args.index('-a')+1]).open('wb') as out:writer.write(out)
|
||||
(project.parent/'database/icdb.dat').write_bytes(b'native update');return 0
|
||||
monkeypatch.setattr(cli,'Exporter',lambda engine,runs:Exporter(engine,runs,runner=runner))
|
||||
report=tmp_path/'report.json'
|
||||
args=['--export',str(project),'--engine',str(engine),'--output',str(tmp_path/'pdfs'),'--runs-root',str(tmp_path/'runs'),'--report',str(report)]
|
||||
if strict:args.append('--strict-source')
|
||||
assert main(args)==(1 if strict else 0)
|
||||
result=json.loads(report.read_text(encoding='utf-8'))['results'][0]
|
||||
assert result['status']==('uncertain' if strict else 'success')
|
||||
if not strict:assert result['warnings'] and Path(result['output']).is_file()
|
||||
|
||||
|
||||
def test_cli_strict_source_flag_reaches_ui(qtbot,tmp_path,monkeypatch):
|
||||
from mentor_pdf_export import ui
|
||||
original=ui.MainWindow;windows=[]
|
||||
def capture(*args,**kwargs):
|
||||
window=original(*args,**kwargs);qtbot.addWidget(window);windows.append(window);return window
|
||||
monkeypatch.setattr(ui,'MainWindow',capture)
|
||||
assert main(['--strict-source','--ui-smoke',str(tmp_path/'ui.png')])==0
|
||||
assert windows[0].strict_source_check.isChecked()
|
||||
|
||||
|
||||
@pytest.mark.parametrize('flags,exit_code',[
|
||||
(['--font-mapping','preserve'],0),
|
||||
(['--font-mapping','preserve','--no-legacy-gbk'],0),
|
||||
(['--font-mapping','preserve','--legacy-gbk'],2),
|
||||
])
|
||||
def test_cli_preserve_normalizes_implicit_not_explicit_gbk(project_factory,tmp_path,monkeypatch,flags,exit_code):
|
||||
from mentor_pdf_export import cli
|
||||
from mentor_pdf_export.exporter import Exporter
|
||||
from pypdf import PdfWriter
|
||||
project=project_factory();engine=tmp_path/'sch2pdf.exe';engine.write_bytes(b'fake')
|
||||
def runner(args,*rest,env=None):
|
||||
writer=PdfWriter();writer.add_blank_page(width=500,height=400)
|
||||
with Path(args[args.index('-a')+1]).open('wb') as out:writer.write(out)
|
||||
return 0
|
||||
monkeypatch.setattr(cli,'Exporter',lambda e,r:Exporter(e,r,runner=runner))
|
||||
rc=main(['--export',str(project),'--engine',str(engine),'--output',str(tmp_path/'out'),'--runs-root',str(tmp_path/'runs'),*flags])
|
||||
assert rc==exit_code
|
||||
Reference in new issue
Block a user