etomoscow/mff_lora / code /tests /test_acl_main_figures.py
etomoscow's picture
download
raw
4.43 kB
from pathlib import Path
import subprocess
import sys
from xml.etree import ElementTree
from scripts import build_acl_main_figures as figures
main = figures.main
REPO = Path(__file__).resolve().parents[1]
def test_main_renderer_writes_exactly_three_paper_figures(tmp_path):
main(["--repo", str(REPO), "--output-dir", str(tmp_path)])
assert {path.name for path in tmp_path.iterdir()} == {
"fig1_method.svg",
"fig2_accuracy_gain.pdf",
"fig2_accuracy_gain.png",
"fig3_threshold_sensitivity.pdf",
"fig3_threshold_sensitivity.png",
"captions.tex",
}
svg = ElementTree.parse(tmp_path / "fig1_method.svg").getroot()
assert svg.tag.endswith("svg")
svg_text = "".join(svg.itertext())
for label in (
"Same step-0 function",
"PEFT tangent space",
"Fisher-informed tangent space",
"Ineffective region",
"0.04 → 0.92",
"28 → 7",
"26×",
):
assert label in svg_text
captions = (tmp_path / "captions.tex").read_text()
assert captions.count(r"\begin{figure*}") == 1
assert captions.count(r"\end{figure*}") == 1
assert captions.count(r"\begin{figure}") == 2
assert captions.count(r"\end{figure}") == 2
assert r"\includesvg[width=\textwidth]{paper_figures/main/fig1_method}" in captions
assert r"\includegraphics[width=\columnwidth]{paper_figures/main/fig2_accuracy_gain.pdf}" in captions
assert r"\includegraphics[width=\columnwidth]{paper_figures/main/fig3_threshold_sensitivity.pdf}" in captions
assert "fig3_boundaries" not in captions
def test_main_renderer_runs_as_a_script(tmp_path):
result = subprocess.run(
[
sys.executable,
str(REPO / "scripts/build_acl_main_figures.py"),
"--repo",
str(REPO),
"--output-dir",
str(tmp_path),
],
cwd=REPO,
capture_output=True,
text=True,
)
assert result.returncode == 0, result.stderr
assert "wrote 3 main figures" in result.stdout
def test_accuracy_gain_plot_overlays_absolute_methods_and_marks_delta(tmp_path, monkeypatch):
captured = {}
def capture(fig, _output_dir, _stem):
captured["figure"] = fig
return tmp_path / "fig2_accuracy_gain.pdf"
monkeypatch.setattr(figures, "_save", capture)
data = figures.load_data(REPO)
figures.validate(data)
figures.plot_accuracy_gain(data, tmp_path)
ax = captured["figure"].axes[0]
patches = {
gid: [patch for patch in ax.patches if patch.get_gid() == gid]
for gid in ("peft", "fisher", "gain")
}
assert {gid: len(items) for gid, items in patches.items()} == {
"peft": 5,
"fisher": 5,
"gain": 5,
}
assert {bar.get_width() for bar in patches["peft"]} == {
bar.get_width() for bar in patches["fisher"]
}
assert round(patches["peft"][0].get_y() + patches["peft"][0].get_height(), 2) == 80.39
assert round(patches["fisher"][0].get_y() + patches["fisher"][0].get_height(), 2) == 91.22
assert round(patches["gain"][0].get_y(), 2) == 80.39
assert round(patches["gain"][0].get_height(), 2) == 10.83
assert sum(text.arrow_patch is not None for text in ax.texts if hasattr(text, "arrow_patch")) == 5
texts = {text.get_text() for text in ax.texts}
assert "+10.83 pp" in texts
def test_threshold_curve_reports_low_accuracy_rate_across_cutoffs(tmp_path, monkeypatch):
captured = {}
def capture(fig, _output_dir, _stem):
captured["figure"] = fig
return tmp_path / "fig3_threshold_sensitivity.pdf"
monkeypatch.setattr(figures, "_save", capture)
data = figures.load_data(REPO)
figures.validate(data)
figures.plot_threshold_sensitivity(data, tmp_path)
ax = captured["figure"].axes[0]
lines = {line.get_gid(): line for line in ax.lines if line.get_gid()}
peft = lines["peft-threshold"]
fisher = lines["fisher-threshold"]
peft_at_70 = peft.get_ydata()[list(peft.get_xdata()).index(70)]
fisher_at_70 = fisher.get_ydata()[list(fisher.get_xdata()).index(70)]
assert round(peft_at_70, 2) == 37.33
assert round(fisher_at_70, 2) == 9.33
texts = {text.get_text() for text in ax.texts}
assert "28/75 (37%)" in texts
assert "7/75 (9%)" in texts
assert {text.get_fontsize() for text in ax.get_legend().get_texts()} == {6}

Xet Storage Details

Size:
4.43 kB
·
Xet hash:
27fb0883f2f5f17a1b042d52f4898a3bada93997cb73723962c8f4f10e8b7d19

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.