62 lines
2.7 KiB
Python
62 lines
2.7 KiB
Python
from pathlib import Path
|
|
from mentor_pdf_export.models import ExportOptions
|
|
from mentor_pdf_export.profiles import write_profile, build_command
|
|
|
|
def test_profile_clears_url_and_preserves_fonts(tmp_path):
|
|
ini = tmp_path / "dxpdf.ini"
|
|
ini.write_text("Color 1\nUrlProperties Value\nStartAcrobat 1\nFont_1 Courier-Bold\n")
|
|
write_profile(ini, ExportOptions())
|
|
lines = ini.read_text().splitlines()
|
|
assert "Color 4" in lines
|
|
assert "UrlProperties " in lines
|
|
assert "StartAcrobat 0" in lines
|
|
assert "Font_1 Courier-Bold" in lines
|
|
assert "ChangeIct2Sch 1" in lines
|
|
assert "VisibleHLs 0" in lines
|
|
|
|
def test_command_is_argument_list_not_shell():
|
|
args = build_command(Path("engine.exe"), Path("工程 x.prj"), Path("x.pdf"), ExportOptions(schematic="ROOT"))
|
|
assert args[:3] == ["engine.exe", "-project", "工程 x.prj"]
|
|
assert args[args.index("-c") + 1] == "4"
|
|
assert args[args.index("-schematic") + 1] == "ROOT"
|
|
assert "-p" in args and "-e" in args and "-i2s" in args
|
|
assert "-s" not in args and "-v" not in args and "-i" not in args
|
|
|
|
def test_disabled_flags_not_enabled():
|
|
args = build_command(Path("engine.exe"), Path("a.prj"), Path("a.pdf"), ExportOptions(popup=False, use_exclusion=False, change_ict=False))
|
|
assert "-p" not in args and "-e" not in args and "-i2s" not in args
|
|
|
|
|
|
def test_stroke_mode_uses_native_verified_attached_switch():
|
|
args=build_command(Path("engine.exe"),Path("a.prj"),Path("a.pdf"),ExportOptions(stroke_fonts=True))
|
|
assert "-uAll" in args
|
|
assert "-u" not in args and "-udx" not in args
|
|
|
|
|
|
def test_explicit_font_and_print_profile_modes():
|
|
options=ExportOptions(font_mapping="arial",print_theme="high_contrast")
|
|
assert options.font_mapping=="arial" and options.print_theme=="high_contrast"
|
|
|
|
|
|
def test_profile_modes_reject_unknown_names():
|
|
import pytest
|
|
with pytest.raises(ValueError,match="字体"):
|
|
ExportOptions(font_mapping="arail\nInjected value")
|
|
with pytest.raises(ValueError,match="配色"):
|
|
ExportOptions(print_theme="unknown")
|
|
|
|
|
|
def test_arial_profile_changes_only_copy_font_configuration(tmp_path):
|
|
ini=tmp_path/"dxpdf.ini";ini.write_text("FONT_CUSTOM_FONTS Courier-Bold\nFont_1 Courier-Bold\n")
|
|
write_profile(ini,ExportOptions(font_mapping="arial"))
|
|
lines=ini.read_text().splitlines()
|
|
assert "FONT_CUSTOM_FONTS Arial" in lines
|
|
assert "Font_1 Arial" in lines
|
|
|
|
|
|
def test_print_theme_controls_effective_background_mode():
|
|
args=build_command(Path("engine.exe"),Path("p.prj"),Path("p.pdf"),ExportOptions(color=2,print_theme="high_contrast"))
|
|
assert args[args.index("-c")+1]=="4"
|
|
args=build_command(Path("engine.exe"),Path("p.prj"),Path("p.pdf"),ExportOptions(print_theme="mono"))
|
|
assert args[args.index("-c")+1]=="3"
|