Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added and modified report handler test #210

Merged
merged 3 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")