From e739c10d24f60176c8183bc4def39c6829dea099 Mon Sep 17 00:00:00 2001 From: Sina Atalay Date: Sat, 1 Jun 2024 15:10:59 +0300 Subject: [PATCH] cli: fix relative input file paths (#95) --- rendercv/cli.py | 2 +- tests/test_cli.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/rendercv/cli.py b/rendercv/cli.py index d2e5146..b6b5024 100644 --- a/rendercv/cli.py +++ b/rendercv/cli.py @@ -676,7 +676,7 @@ def cli_command_render( """Generate a $\\LaTeX$ CV from a YAML input file.""" welcome() - input_file_path = pathlib.Path(input_file_name) + input_file_path = pathlib.Path(input_file_name).absolute() output_directory = pathlib.Path.cwd() / output_folder_name # change the current working directory to the input file's directory (because diff --git a/tests/test_cli.py b/tests/test_cli.py index 10a5486..d02f1f2 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -3,6 +3,7 @@ import shutil import subprocess import sys from datetime import date as Date +import pathlib import pydantic import ruamel.yaml @@ -240,6 +241,34 @@ def test_render_command(tmp_path, input_file_path): assert "Your CV is rendered!" in result.stdout +def test_render_command_with_relative_input_file_path(tmp_path, input_file_path): + new_folder = tmp_path / "another_folder" + new_folder.mkdir() + new_input_file_path = new_folder / input_file_path.name + + shutil.copy(input_file_path, new_input_file_path) + + os.chdir(tmp_path) + result = runner.invoke( + cli.app, ["render", str(new_input_file_path.relative_to(tmp_path))] + ) + + output_folder_path = tmp_path / "rendercv_output" + pdf_file_path = output_folder_path / "John_Doe_CV.pdf" + latex_file_path = output_folder_path / "John_Doe_CV.tex" + markdown_file_path = output_folder_path / "John_Doe_CV.md" + html_file_path = output_folder_path / "John_Doe_CV_PASTETOGRAMMARLY.html" + png_file_path = output_folder_path / "John_Doe_CV_1.png" + + assert output_folder_path.exists() + assert pdf_file_path.exists() + assert latex_file_path.exists() + assert markdown_file_path.exists() + assert html_file_path.exists() + assert png_file_path.exists() + assert "Your CV is rendered!" in result.stdout + + def test_render_command_with_different_output_path(input_file_path, tmp_path): result = run_render_command( input_file_path,