Skip to content

Commit

Permalink
Merge pull request #1164 from betagouv/fix/export-pdf-error-when-no-i…
Browse files Browse the repository at this point in the history
…mage

fix: PDF export error when no measuring point image
  • Loading branch information
wiwski authored Dec 4, 2024
2 parents 56771d2 + a3eb9a5 commit b7a3203
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lab_notebook/pdf_export/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,9 @@ def create_pdf(
story.extend(generate_experimental_conditions_story(run, run_methods))
story.append(Spacer(1, 0.2 * inch))
add_comments(story, run["run_notebook"]["comments"])
story.append(Spacer(1, 0.2 * inch))
story.extend(generate_images_with_points_story(images, tmpdirname))
if images:
story.append(Spacer(1, 0.2 * inch))
story.extend(generate_images_with_points_story(images, tmpdirname))
story.append(PageBreak())
add_table_of_contents(story)
story.append(PageBreak())
Expand Down
43 changes: 43 additions & 0 deletions lab_notebook/tests/pdf_export/test_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,3 +289,46 @@ def test_create_pdf():
f.close()

assert Canvas(f.name, pagesize=A4)


def test_create_pdf_with_no_image():
run = {
"label": "test-run",
"project": {"slug": "test-project", "name": "Test Project"},
"particle_type": "electron",
"energy_in_keV": "100",
"beamline": "test-beamline",
"run_notebook": {"comments": "Test comments"},
}
run_methods = [
mock.Mock(
name="Test Method",
detectors=[
mock.Mock(
name="Test Detector",
filters=["Test Filter"],
)
],
)
]
measuring_points = [
{
"name": "point-test-1",
"comments": "test comment 1",
"object_group": {"label": "object test 1"},
"standard": None,
},
{
"name": "point-test-2",
"comments": "test comment 2",
"object_group": None,
"standard": {"label": "standard test 2"},
},
]
images = []

with tempfile.NamedTemporaryFile("w+b", suffix=".pdf", delete=False) as f:
create_pdf(f.name, run, run_methods, measuring_points, images)
f.close()

assert Canvas(f.name, pagesize=A4)

0 comments on commit b7a3203

Please sign in to comment.