MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / test_dviread

Function test_dviread

lib/matplotlib/tests/test_dviread.py:68–108  ·  view source on GitHub ↗
(tmp_path, engine, monkeypatch)

Source from the content-addressed store, hash-verified

66 reason="kpsewhich is not available")
67@pytest.mark.parametrize("engine", ["pdflatex", "xelatex", "lualatex"])
68def test_dviread(tmp_path, engine, monkeypatch):
69 dirpath = Path(__file__).parent / "baseline_images/dviread"
70 shutil.copy(dirpath / "test.tex", tmp_path)
71 shutil.copy(cbook._get_data_path("fonts/ttf/DejaVuSans.ttf"), tmp_path)
72 cmd, fmt = {
73 "pdflatex": (["latex", "-no-shell-escape"], "dvi"),
74 "xelatex": (["xelatex", "-no-pdf", "-no-shell-escape"], "xdv"),
75 "lualatex": (["lualatex", "-output-format=dvi", "-no-shell-escape"], "dvi"),
76 }[engine]
77 if shutil.which(cmd[0]) is None:
78 pytest.skip(f"{cmd[0]} is not available")
79 subprocess_run_for_testing(
80 [*cmd, "test.tex"], cwd=tmp_path, check=True, capture_output=True)
81 # dviread must be run from the tmppath directory because {xe,lua}tex output
82 # records the path to DejaVuSans.ttf as it is written in the tex source,
83 # i.e. as a relative path.
84 monkeypatch.chdir(tmp_path)
85 with dr.Dvi(tmp_path / f"test.{fmt}", None) as dvi:
86 try:
87 pages = [*dvi]
88 except FileNotFoundError as exc:
89 for note in getattr(exc, "__notes__", []):
90 if "too-old version of luaotfload" in note:
91 pytest.skip(note)
92 raise
93 data = [
94 {
95 "text": [
96 [
97 t.x, t.y,
98 t._as_unicode_or_name(),
99 t.font.resolve_path().name,
100 round(t.font.size, 2),
101 t.font.effects,
102 ] for t in page.text
103 ],
104 "boxes": [[b.x, b.y, b.height, b.width] for b in page.boxes]
105 } for page in pages
106 ]
107 correct = json.loads((dirpath / f"{engine}.json").read_text())
108 assert data == correct
109
110
111@pytest.mark.skipif(shutil.which("latex") is None, reason="latex is not available")

Callers

nothing calls this directly

Calls 5

PathClass · 0.85
_as_unicode_or_nameMethod · 0.80
resolve_pathMethod · 0.80
copyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…