From e5efd21b0add344a7a59fb58d282c087e4a39ec4 Mon Sep 17 00:00:00 2001 From: Sina Atalay Date: Mon, 9 Oct 2023 19:57:23 +0200 Subject: [PATCH] avod using bare excepts --- rendercv/__init__.py | 4 +++- rendercv/__main__.py | 5 +++-- rendercv/data_model.py | 7 +++++-- run_rendercv.py | 4 ++-- tests/reference_files/John_Doe_CV.tex | 2 +- tests/test_rendering.py | 6 ++++-- 6 files changed, 18 insertions(+), 10 deletions(-) diff --git a/rendercv/__init__.py b/rendercv/__init__.py index 9425105..b8eb61d 100644 --- a/rendercv/__init__.py +++ b/rendercv/__init__.py @@ -1,6 +1,8 @@ r"""RenderCV package. -It parses the user input YAML/JSON file and validates the data (checks spelling mistakes, checks if the dates are consistent, etc.). Then, with the data, it creates a $\LaTeX$ file and renders it with [TinyTeX](https://yihui.org/tinytex/). +It parses the user input YAML/JSON file and validates the data (checks spelling +mistakes, checks if the dates are consistent, etc.). Then, with the data, it creates a +$\LaTeX$ file and renders it with [TinyTeX](https://yihui.org/tinytex/). """ import logging diff --git a/rendercv/__main__.py b/rendercv/__main__.py index 2915bad..6f4e9f9 100644 --- a/rendercv/__main__.py +++ b/rendercv/__main__.py @@ -25,12 +25,13 @@ def main(args=sys.argv[1:]): " the input file path." ) - input_file_path = sys.argv[1] + # input_file_path = sys.argv[1] file_path = os.path.join(os.getcwd(), input_file_path) data = read_input_file(file_path) output_latex_file = render_template(data) output_pdf_file = run_latex(output_latex_file) logger.info(f"RenderCV: PDF file generated at {output_pdf_file}") + if __name__ == "__main__": - main() \ No newline at end of file + main(args=["tests/inputs/personal.yaml"]) diff --git a/rendercv/data_model.py b/rendercv/data_model.py index 0845a0d..b896bde 100644 --- a/rendercv/data_model.py +++ b/rendercv/data_model.py @@ -191,6 +191,9 @@ def format_date(date: Date) -> str: Returns: str: The formatted date. """ + if not isinstance(date, Date): + raise TypeError("date is not a Date object!") + # Month abbreviations, # taken from: https://web.library.yale.edu/cataloging/months abbreviations_of_months = [ @@ -683,7 +686,7 @@ class Event(BaseModel): # If this runs, it means the date is an ISO format string, and it can be # parsed month_and_year = format_date(self.date) - except: + except TypeError: month_and_year = self.date else: # Then it means start_date and end_date are provided and month_and_year @@ -829,7 +832,7 @@ class PublicationEntry(Event): try: urllib.request.urlopen(doi_url) - except: + except urllib.request.HTTPError: raise ValueError(f"{doi} cannot be found in the DOI System.") return doi diff --git a/run_rendercv.py b/run_rendercv.py index acab402..639aa1d 100644 --- a/run_rendercv.py +++ b/run_rendercv.py @@ -5,10 +5,10 @@ This module is a script to run the RenderCV and generate a CV as a PDF. import os -import rendercv +import rendercv.__main__ as rendercv input_name = "personal" workspace = os.path.dirname(__file__) file_path = os.path.join(workspace, "tests", "inputs", f"{input_name}.yaml") -rendercv(file_path) \ No newline at end of file +rendercv.main(args=[file_path]) diff --git a/tests/reference_files/John_Doe_CV.tex b/tests/reference_files/John_Doe_CV.tex index aec48cd..425334f 100644 --- a/tests/reference_files/John_Doe_CV.tex +++ b/tests/reference_files/John_Doe_CV.tex @@ -101,7 +101,7 @@ \LenToUnit{\paperwidth-1.35 cm}, \LenToUnit{\paperheight-0.675 cm} ){\vtop{{\null}\makebox[0pt][c]{ - \small\color{gray}\emph{Last updated on October 08, 2023} \hspace{\widthof{Last updated on October 08, 2023}} + \small\color{gray}\emph{Last updated on REPLACE_THIS_WITH_TODAY} \hspace{\widthof{Last updated on REPLACE_THIS_WITH_TODAY}} }}}% }% }% diff --git a/tests/test_rendering.py b/tests/test_rendering.py index 042c840..622ae26 100644 --- a/tests/test_rendering.py +++ b/tests/test_rendering.py @@ -5,8 +5,6 @@ import shutil from rendercv import rendering, data_model -from pydantic import ValidationError - class TestDataModel(unittest.TestCase): def test_markdown_to_latex(self): @@ -378,6 +376,9 @@ class TestDataModel(unittest.TestCase): output = file.read() with open(reference_file_path, "r") as file: reference = file.read() + reference = reference.replace( + "REPLACE_THIS_WITH_TODAY", rendering.get_today() + ) self.assertEqual(output, reference) @@ -406,5 +407,6 @@ class TestDataModel(unittest.TestCase): # rendering.run_latex(latex_file_path) + if __name__ == "__main__": unittest.main()