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
@@ -0,0 +1,68 @@
|
||||
"""Regression: ordinary UI defaults must generate readable reference-style output."""
|
||||
import os
|
||||
import sys
|
||||
import threading
|
||||
import xml.etree.ElementTree as ET
|
||||
from pathlib import Path
|
||||
from pypdf import PdfReader
|
||||
from pypdf.generic import ContentStream
|
||||
from mentor_pdf_export.models import ExportOptions
|
||||
from mentor_pdf_export.profiles import build_command
|
||||
from mentor_pdf_export.pdf_styles import apply_pdf_style
|
||||
from mentor_pdf_export.engine import run_engine
|
||||
from mentor_pdf_export.ui import MainWindow
|
||||
from test_pdf_styles import legacy_pdf
|
||||
|
||||
|
||||
def test_font_repair_uses_native_mapped_text_not_dxd_stroke_fallback():
|
||||
cmd=build_command(Path('sch2pdf.exe'),Path('demo.prj'),Path('demo.pdf'),ExportOptions(font_mapping='arial',legacy_gbk=True))
|
||||
assert '-udx' not in cmd and '-uAll' not in cmd
|
||||
|
||||
|
||||
def test_reference_palette_is_child_only_and_role_specific(tmp_path,monkeypatch):
|
||||
from mentor_pdf_export.profiles import prepare_native_environment
|
||||
monkeypatch.setenv('WDIR',r'D:\Mentor\standard')
|
||||
monkeypatch.setenv('MENTOR_TEST_LICENSE','inherited')
|
||||
before=dict(os.environ)
|
||||
env=prepare_native_environment(tmp_path,ExportOptions(print_theme='reference'))
|
||||
assert dict(os.environ)==before
|
||||
cfg=Path(env['WDIR'].split(';')[0])
|
||||
assert cfg.is_relative_to(tmp_path)
|
||||
tree=ET.parse(cfg/'DxDesigner.xml')
|
||||
def color(name):return tree.find(f"./DxDesigner/OBJECTS/object[@name='{name}']/key[@name='COLOR']").get('value')
|
||||
assert color('NET')=='0xff0000'
|
||||
assert color('PIN')=='0x008080'
|
||||
assert color('LINE')=='0x0000ff'
|
||||
assert color('BOX')=='0x800080'
|
||||
assert color('CIRCLE')=='0x008000'
|
||||
assert color('LABEL')=='0x008000'
|
||||
assert color('ATTRIBUTE')=='0x388e8e' # Reference's inherited component values; pins remain #008080.
|
||||
assert env['WDIR'].endswith(r';D:\Mentor\standard')
|
||||
assert env['MENTOR_TEST_LICENSE']=='inherited'
|
||||
assert prepare_native_environment(tmp_path,ExportOptions(print_theme='original')) is None
|
||||
|
||||
|
||||
def test_engine_passes_environment_to_owned_child_only(tmp_path,monkeypatch):
|
||||
monkeypatch.setenv('MENTOR_PDF_ENV_TEST','parent')
|
||||
env=dict(os.environ);env['MENTOR_PDF_ENV_TEST']='child'
|
||||
rc=run_engine([sys.executable,'-c',"import os;print(os.environ['MENTOR_PDF_ENV_TEST'])"],tmp_path,tmp_path/'logs',threading.Event(),10,env=env)
|
||||
assert rc==0
|
||||
assert (tmp_path/'logs/stdout.log').read_text().strip()=='child'
|
||||
assert os.environ['MENTOR_PDF_ENV_TEST']=='parent'
|
||||
|
||||
|
||||
def test_plain_ui_defaults_repair_chinese_without_recoloring_or_thickening(qtbot,tmp_path):
|
||||
window=MainWindow();qtbot.addWidget(window)
|
||||
opts=window.options()
|
||||
assert opts.print_theme=='reference'
|
||||
cmd=build_command(Path('sch2pdf.exe'),Path('工程.prj'),Path('工程.pdf'),opts)
|
||||
assert '-udx' not in cmd
|
||||
file=tmp_path/'native.pdf';legacy_pdf(file,'注意事项 音频 Ω μ ± ×')
|
||||
before=PdfReader(file);ops=ContentStream(before.pages[0].get_contents(),before).operations
|
||||
geometry=[(a,b) for a,b in ops if b in (b'm',b'l',b're',b'w',b'rg',b'RG')]
|
||||
report=apply_pdf_style(file,opts)
|
||||
reader=PdfReader(file);text=reader.pages[0].extract_text()
|
||||
assert '注意事项' in text and '音频' in text
|
||||
assert all(s in text for s in ('Ω','μ','±','×'))
|
||||
assert report.repaired_strings==1 and report.fallback_strings==1
|
||||
assert geometry==[(a,b) for a,b in ContentStream(reader.pages[0].get_contents(),reader).operations if b in (b'm',b'l',b're',b'w',b'rg',b'RG')]
|
||||
Reference in new issue
Block a user