Skip to content
Open
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
5 changes: 4 additions & 1 deletion lean/commands/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,10 @@ def report(backtest_results: Optional[Path],
logger.info(f"Custom HTML template file '{html}' could not be found")

if pdf:
run_options["commands"].append(f'cp /tmp/report.pdf "/Output/{report_destination.name.replace(".html", ".pdf")}"')
pdf_destination = report_destination.with_suffix(".pdf")
if report_destination.suffix.lower() == ".pdf":
pdf_destination = report_destination.with_name(report_destination.name + ".pdf")
run_options["commands"].append(f'cp /tmp/report.pdf "/Output/{pdf_destination.name}"')
if live_results is not None:
run_options["mounts"].append(Mount(target="/Lean/Report/bin/Debug/live-data-source-file.json",
source=str(live_results),
Expand Down
22 changes: 22 additions & 0 deletions tests/commands/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,3 +613,25 @@ def test_report_runs_custom_image_when_given_as_option() -> None:
args, kwargs = docker_manager.run_image.call_args

assert args[0] == DockerImage(name="custom/lean", tag="456")


@pytest.mark.parametrize("destination, pdf_destination", [
("report.html", "report.pdf"),
("report.HTML", "report.pdf"),
("my-report", "my-report.pdf"),
("report.html.backtest.html", "report.html.backtest.pdf"),
("report.pdf", "report.pdf.pdf"),
("report.PDF", "report.PDF.pdf"),
])
def test_report_exports_pdf_to_separate_destination(destination: str, pdf_destination: str) -> None:
docker_manager = mock.Mock()
docker_manager.run_image.side_effect = run_image
initialize_container(docker_manager_to_use=docker_manager)

result = CliRunner().invoke(lean, ["report", "--pdf", "--report-destination", destination])

assert result.exit_code == 0
commands = docker_manager.run_image.call_args.kwargs["commands"]
assert f'cp /tmp/report.html "/Output/{destination}"' in commands
assert f'cp /tmp/report.pdf "/Output/{pdf_destination}"' in commands
assert destination.lower() != pdf_destination.lower()
Loading