diff --git a/rendercv/rendering.py b/rendercv/rendering.py index 5f8a024..5f47d9f 100644 --- a/rendercv/rendering.py +++ b/rendercv/rendering.py @@ -444,36 +444,36 @@ def run_latex(latex_file_path: str) -> str: ) # Run TinyTeX: - with subprocess.Popen( - [ - executable, - f"{latex_file_name}", - "&&", - executable, - f"{latex_file_name}", - ], - cwd=os.path.dirname(latex_file_path), - stdout=subprocess.PIPE, - stdin=subprocess.DEVNULL, # don't allow TinyTeX to ask for user input - text=True, - shell=True, - ) as latex_process: - output, error = latex_process.communicate() + def run(): + with subprocess.Popen( + [ + executable, + f"{latex_file_name}", + ], + cwd=os.path.dirname(latex_file_path), + stdout=subprocess.PIPE, + stdin=subprocess.DEVNULL, # don't allow TinyTeX to ask for user input + text=True, + ) as latex_process: + output, error = latex_process.communicate() - if latex_process.returncode != 0: - # Find the error line: - for line in output.split("\n"): - if line.startswith("! "): - error_line = line.replace("! ", "") - break + if latex_process.returncode != 0: + # Find the error line: + for line in output.split("\n"): + if line.startswith("! "): + error_line = line.replace("! ", "") + break - raise RuntimeError( - "Running TinyTeX has failed with the following error:", - f"{error_line}", - "If you can't solve the problem, please try to re-install RenderCV," - " or open an issue on GitHub.", - ) + raise RuntimeError( + "Running TinyTeX has failed with the following error:", + f"{error_line}", + "If you can't solve the problem, please try to re-install RenderCV," + " or open an issue on GitHub.", + ) + run() + run() # run twice for cross-references + # check if the PDF file is generated: if not os.path.exists(output_file_path): raise FileNotFoundError( diff --git a/tests/test_cli.py b/tests/test_cli.py index 3045dda..3c516ed 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -12,35 +12,39 @@ class TestCLI(unittest.TestCase): # Change the working directory to the root of the project: workspace_path = os.path.dirname(os.path.dirname(__file__)) - test_input_file_path = os.path.join( - workspace_path, - "tests", - "reference_files", - "John_Doe_CV_yaml_reference.yaml", - ) - subprocess.run( - [sys.executable, "-m", "rendercv", "render", test_input_file_path], - check=True, - ) + with self.subTest(msg="Correct input"): + test_input_file_path = os.path.join( + workspace_path, + "tests", + "reference_files", + "John_Doe_CV_yaml_reference.yaml", + ) + subprocess.run( + [sys.executable, "-m", "rendercv", "render", test_input_file_path], + check=True, + ) - # Read the necessary information and remove the output directory: - output_file_path = os.path.join(workspace_path, "output", "John_Doe_CV.pdf") - pdf_file_size = os.path.getsize(output_file_path) - file_exists = os.path.exists(output_file_path) - shutil.rmtree(os.path.join(workspace_path, "output")) + # Read the necessary information and remove the output directory: + output_file_path = os.path.join(workspace_path, "output", "John_Doe_CV.pdf") + pdf_file_size = os.path.getsize(output_file_path) + file_exists = os.path.exists(output_file_path) + shutil.rmtree(os.path.join(workspace_path, "output")) - # Check if the output file exists: - self.assertTrue(file_exists, msg="PDF file couldn't be generated.") + # Check if the output file exists: + self.assertTrue(file_exists, msg="PDF file couldn't be generated.") - # Compare the pdf file with the reference pdf file: - reference_pdf_file = os.path.join( - workspace_path, "tests", "reference_files", "John_Doe_CV_pdf_reference.pdf" - ) - reference_pdf_file_size = os.path.getsize(reference_pdf_file) - ratio = min(reference_pdf_file_size, pdf_file_size) / max( - reference_pdf_file_size, pdf_file_size - ) - self.assertTrue(ratio > 0.98, msg="PDF file didn't match the reference.") + # Compare the pdf file with the reference pdf file: + reference_pdf_file = os.path.join( + workspace_path, + "tests", + "reference_files", + "John_Doe_CV_pdf_reference.pdf", + ) + reference_pdf_file_size = os.path.getsize(reference_pdf_file) + ratio = min(reference_pdf_file_size, pdf_file_size) / max( + reference_pdf_file_size, pdf_file_size + ) + self.assertTrue(ratio > 0.98, msg="PDF file didn't match the reference.") # Wrong input: with self.subTest(msg="Wrong input"):