Skip to content

Commit

Permalink
Merge pull request #210 from aidotse/pdf_tests
Browse files Browse the repository at this point in the history
Added and modified report handler test
  • Loading branch information
henrikfo authored Jan 29, 2025
2 parents 6eee6d3 + cd2f901 commit 25e7b63
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
6 changes: 6 additions & 0 deletions leakpro/reporting/report_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ def _init_pdf(self:Self) -> None:
def _compile_pdf(self:Self) -> None:
"""Method to compile PDF."""

# Support for an empty pdf to compile
if self.latex_content.strip()[-16:] == "\\begin{document}":
self.latex_content += "\\null"
self.logger.info("Warning! You are about to compile an empty pdf.")
self.logger.info("Please ensure that you append your results!")

self.latex_content += """
\\end{document}
"""
Expand Down
25 changes: 24 additions & 1 deletion leakpro/tests/test_report_handler/test_report_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,29 @@ def test_compile_pdf(self:Self) -> None:
self.report_handler._init_pdf()
assert ("documentclass" and "begin") in self.report_handler.latex_content

# Add body to latex content
self.report_handler.latex_content += "body text example"

self.report_handler._compile_pdf()
assert "end" in self.report_handler.latex_content
assert os.path.isfile(f"{self.report_handler.report_dir}/LeakPro_output.tex")
assert os.path.isfile(f"{self.report_handler.report_dir}/LeakPro_output.tex")
assert os.path.isfile(f"{self.report_handler.report_dir}/LeakPro_output.pdf")

def test_create_pdf(self:Self) -> None:
report_handler = ReportHandler(report_dir=self.temp_dir.name, logger=self.logger)

# Load results
report_handler.pdf_results["MIAResult"] = "test_result"

# Create pdf report
report_handler.create_report()

assert os.path.isfile(f"{self.report_handler.report_dir}/LeakPro_output.pdf")

def test_create_empty_pdf(self:Self) -> None:
report_handler = ReportHandler(report_dir=self.temp_dir.name, logger=self.logger)

report_handler._init_pdf()
report_handler._compile_pdf()

assert os.path.isfile(f"{self.report_handler.report_dir}/LeakPro_output.pdf")

0 comments on commit 25e7b63

Please sign in to comment.