mirror of https://github.com/eyhc1/rendercv.git
improve test messages
This commit is contained in:
parent
57bdce86a0
commit
bb27b7a1e5
|
@ -40,12 +40,11 @@ jobs:
|
||||||
pip install pytest pytest-cov
|
pip install pytest pytest-cov
|
||||||
pytest --cov-report html --cov="." tests/
|
pytest --cov-report html --cov="." tests/
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
- name: Upload artifacts
|
# - name: Upload referebce files as artifacts
|
||||||
if: ${{matrix.os == 'ubuntu-latest' && matrix.python-version == '3.10'}}
|
# uses: actions/upload-artifact@v3
|
||||||
uses: actions/upload-artifact@v3
|
# with:
|
||||||
with:
|
# name: reference_files
|
||||||
name: reference_files
|
# path: ./tests/reference_files
|
||||||
path: ./tests/reference_files
|
|
||||||
- name: Upload coverage data to smokeshow
|
- name: Upload coverage data to smokeshow
|
||||||
if: ${{matrix.os == 'ubuntu-latest' && matrix.python-version == '3.12'}} # upload coverage once
|
if: ${{matrix.os == 'ubuntu-latest' && matrix.python-version == '3.12'}} # upload coverage once
|
||||||
run: |
|
run: |
|
||||||
|
|
|
@ -102,9 +102,13 @@ class TestDataModel(unittest.TestCase):
|
||||||
}
|
}
|
||||||
with self.subTest(msg="valid date with start_date"):
|
with self.subTest(msg="valid date with start_date"):
|
||||||
event = data_model.Event(**input)
|
event = data_model.Event(**input)
|
||||||
self.assertEqual(event.start_date, Date.fromisoformat(input["start_date"]))
|
self.assertEqual(
|
||||||
self.assertEqual(event.end_date, "present")
|
event.start_date,
|
||||||
self.assertEqual(event.date, None)
|
Date.fromisoformat(input["start_date"]),
|
||||||
|
msg="Start date is not correct.",
|
||||||
|
)
|
||||||
|
self.assertEqual(event.end_date, "present", msg="End date is not correct.")
|
||||||
|
self.assertEqual(event.date, None, msg="Date is not correct.")
|
||||||
|
|
||||||
input = {
|
input = {
|
||||||
"start_date": "2020-01-01",
|
"start_date": "2020-01-01",
|
||||||
|
@ -113,9 +117,13 @@ class TestDataModel(unittest.TestCase):
|
||||||
}
|
}
|
||||||
with self.subTest(msg="valid date with start_date and end_date=present"):
|
with self.subTest(msg="valid date with start_date and end_date=present"):
|
||||||
event = data_model.Event(**input)
|
event = data_model.Event(**input)
|
||||||
self.assertEqual(event.start_date, Date.fromisoformat(input["start_date"]))
|
self.assertEqual(
|
||||||
self.assertEqual(event.end_date, "present")
|
event.start_date,
|
||||||
self.assertEqual(event.date, None)
|
Date.fromisoformat(input["start_date"]),
|
||||||
|
msg="Start date is not correct.",
|
||||||
|
)
|
||||||
|
self.assertEqual(event.end_date, "present", msg="End date is not correct.")
|
||||||
|
self.assertEqual(event.date, None, msg="Date is not correct.")
|
||||||
|
|
||||||
input = {
|
input = {
|
||||||
"start_date": None,
|
"start_date": None,
|
||||||
|
@ -124,9 +132,9 @@ class TestDataModel(unittest.TestCase):
|
||||||
}
|
}
|
||||||
with self.subTest(msg="valid date with custom date"):
|
with self.subTest(msg="valid date with custom date"):
|
||||||
event = data_model.Event(**input)
|
event = data_model.Event(**input)
|
||||||
self.assertEqual(event.start_date, None)
|
self.assertEqual(event.start_date, None, msg="Start date is not correct.")
|
||||||
self.assertEqual(event.end_date, None)
|
self.assertEqual(event.end_date, None, msg="End date is not correct.")
|
||||||
self.assertEqual(event.date, input["date"])
|
self.assertEqual(event.date, input["date"], msg="Date is not correct.")
|
||||||
|
|
||||||
input = {
|
input = {
|
||||||
"start_date": None,
|
"start_date": None,
|
||||||
|
@ -135,9 +143,13 @@ class TestDataModel(unittest.TestCase):
|
||||||
}
|
}
|
||||||
with self.subTest(msg="valid date with ISO date"):
|
with self.subTest(msg="valid date with ISO date"):
|
||||||
event = data_model.Event(**input)
|
event = data_model.Event(**input)
|
||||||
self.assertEqual(event.start_date, None)
|
self.assertEqual(event.start_date, None, msg="Start date is not correct.")
|
||||||
self.assertEqual(event.end_date, None)
|
self.assertEqual(event.end_date, None, msg="End date is not correct.")
|
||||||
self.assertEqual(event.date, Date.fromisoformat(input["date"]))
|
self.assertEqual(
|
||||||
|
event.date,
|
||||||
|
Date.fromisoformat(input["date"]),
|
||||||
|
msg="Date is not correct.",
|
||||||
|
)
|
||||||
|
|
||||||
input = {
|
input = {
|
||||||
"start_date": "2020-01-01",
|
"start_date": "2020-01-01",
|
||||||
|
@ -146,9 +158,15 @@ class TestDataModel(unittest.TestCase):
|
||||||
}
|
}
|
||||||
event = data_model.Event(**input)
|
event = data_model.Event(**input)
|
||||||
with self.subTest(msg="start_date, end_date, and date are all provided"):
|
with self.subTest(msg="start_date, end_date, and date are all provided"):
|
||||||
self.assertEqual(event.date, None)
|
self.assertEqual(event.date, None, msg="Date is not correct.")
|
||||||
self.assertEqual(event.start_date, Date.fromisoformat(input["start_date"]))
|
self.assertEqual(
|
||||||
self.assertEqual(event.end_date, input["end_date"])
|
event.start_date,
|
||||||
|
Date.fromisoformat(input["start_date"]),
|
||||||
|
msg="Start date is not correct.",
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
event.end_date, input["end_date"], msg="End date is not correct."
|
||||||
|
)
|
||||||
|
|
||||||
input = {
|
input = {
|
||||||
"start_date": "2020-01-01",
|
"start_date": "2020-01-01",
|
||||||
|
@ -157,9 +175,9 @@ class TestDataModel(unittest.TestCase):
|
||||||
}
|
}
|
||||||
event = data_model.Event(**input)
|
event = data_model.Event(**input)
|
||||||
with self.subTest(msg="start_date and date are provided"):
|
with self.subTest(msg="start_date and date are provided"):
|
||||||
self.assertEqual(event.start_date, None)
|
self.assertEqual(event.start_date, None, msg="Start date is not correct.")
|
||||||
self.assertEqual(event.end_date, None)
|
self.assertEqual(event.end_date, None, msg="End date is not correct.")
|
||||||
self.assertEqual(event.date, input["date"])
|
self.assertEqual(event.date, input["date"], msg="Date is not correct.")
|
||||||
|
|
||||||
input = {
|
input = {
|
||||||
"start_date": None,
|
"start_date": None,
|
||||||
|
@ -168,9 +186,9 @@ class TestDataModel(unittest.TestCase):
|
||||||
}
|
}
|
||||||
event = data_model.Event(**input)
|
event = data_model.Event(**input)
|
||||||
with self.subTest(msg="end_date and date are provided"):
|
with self.subTest(msg="end_date and date are provided"):
|
||||||
self.assertEqual(event.start_date, None)
|
self.assertEqual(event.start_date, None, msg="Start date is not correct.")
|
||||||
self.assertEqual(event.end_date, None)
|
self.assertEqual(event.end_date, None, msg="End date is not correct.")
|
||||||
self.assertEqual(event.date, input["date"])
|
self.assertEqual(event.date, input["date"], msg="Date is not correct.")
|
||||||
|
|
||||||
input = {
|
input = {
|
||||||
"start_date": None,
|
"start_date": None,
|
||||||
|
@ -179,16 +197,20 @@ class TestDataModel(unittest.TestCase):
|
||||||
}
|
}
|
||||||
event = data_model.Event(**input)
|
event = data_model.Event(**input)
|
||||||
with self.subTest(msg="only date is provided"):
|
with self.subTest(msg="only date is provided"):
|
||||||
self.assertEqual(event.start_date, None)
|
self.assertEqual(event.start_date, None, msg="Start date is not correct.")
|
||||||
self.assertEqual(event.end_date, None)
|
self.assertEqual(event.end_date, None, msg="End date is not correct.")
|
||||||
self.assertEqual(event.date, Date.fromisoformat(input["date"]))
|
self.assertEqual(
|
||||||
|
event.date,
|
||||||
|
Date.fromisoformat(input["date"]),
|
||||||
|
msg="Date is not correct.",
|
||||||
|
)
|
||||||
|
|
||||||
# Inputs without dates:
|
# Inputs without dates:
|
||||||
with self.subTest(msg="no dates"):
|
with self.subTest(msg="no dates"):
|
||||||
event = data_model.Event(**{})
|
event = data_model.Event(**{})
|
||||||
self.assertEqual(event.start_date, None)
|
self.assertEqual(event.start_date, None, msg="Start date is not correct.")
|
||||||
self.assertEqual(event.end_date, None)
|
self.assertEqual(event.end_date, None, msg="End date is not correct.")
|
||||||
self.assertEqual(event.date, None)
|
self.assertEqual(event.date, None, msg="Date is not correct.")
|
||||||
|
|
||||||
# Inputs with invalid dates:
|
# Inputs with invalid dates:
|
||||||
input = {
|
input = {
|
||||||
|
@ -535,7 +557,7 @@ class TestDataModel(unittest.TestCase):
|
||||||
expected = "https://doi.org/10.1103/PhysRevB.76.054309"
|
expected = "https://doi.org/10.1103/PhysRevB.76.054309"
|
||||||
publication = data_model.PublicationEntry(**input)
|
publication = data_model.PublicationEntry(**input)
|
||||||
result = publication.doi_url
|
result = publication.doi_url
|
||||||
self.assertEqual(result, expected)
|
self.assertEqual(result, expected, msg="DOI URL is not correct.")
|
||||||
|
|
||||||
def test_data_connection_url(self):
|
def test_data_connection_url(self):
|
||||||
# Github link:
|
# Github link:
|
||||||
|
|
|
@ -170,13 +170,13 @@ class TestDataModel(unittest.TestCase):
|
||||||
"102.4 ex",
|
"102.4 ex",
|
||||||
]
|
]
|
||||||
for length, exp in zip(lengths, expected):
|
for length, exp in zip(lengths, expected):
|
||||||
with self.subTest(length=length):
|
with self.subTest(length=length, msg="valid input"):
|
||||||
self.assertEqual(rendering.divide_length_by(length, divider), exp)
|
self.assertEqual(rendering.divide_length_by(length, divider), exp)
|
||||||
|
|
||||||
def test_get_today(self):
|
def test_get_today(self):
|
||||||
expected = date.today().strftime("%B %d, %Y")
|
expected = date.today().strftime("%B %d, %Y")
|
||||||
result = rendering.get_today()
|
result = rendering.get_today()
|
||||||
self.assertEqual(expected, result)
|
self.assertEqual(expected, result, msg="Today's date is not correct.")
|
||||||
|
|
||||||
def test_get_path_to_font_directory(self):
|
def test_get_path_to_font_directory(self):
|
||||||
font_name = "test"
|
font_name = "test"
|
||||||
|
@ -188,7 +188,7 @@ class TestDataModel(unittest.TestCase):
|
||||||
font_name,
|
font_name,
|
||||||
)
|
)
|
||||||
result = rendering.get_path_to_font_directory(font_name)
|
result = rendering.get_path_to_font_directory(font_name)
|
||||||
self.assertEqual(expected, result)
|
self.assertEqual(expected, result, msg="Font directory path is not correct.")
|
||||||
|
|
||||||
def test_render_template(self):
|
def test_render_template(self):
|
||||||
test_input = {
|
test_input = {
|
||||||
|
@ -366,7 +366,9 @@ class TestDataModel(unittest.TestCase):
|
||||||
# Check if the output file exists:
|
# Check if the output file exists:
|
||||||
output_folder_path = os.path.join(os.path.dirname(__file__), "output")
|
output_folder_path = os.path.join(os.path.dirname(__file__), "output")
|
||||||
output_file_path = os.path.join(output_folder_path, "John_Doe_CV.tex")
|
output_file_path = os.path.join(output_folder_path, "John_Doe_CV.tex")
|
||||||
self.assertTrue(os.path.exists(output_file_path))
|
self.assertTrue(
|
||||||
|
os.path.exists(output_file_path), msg="LaTeX file couldn't be generated."
|
||||||
|
)
|
||||||
|
|
||||||
# Compare the output file with the reference file:
|
# Compare the output file with the reference file:
|
||||||
reference_file_path = os.path.join(
|
reference_file_path = os.path.join(
|
||||||
|
@ -378,11 +380,15 @@ class TestDataModel(unittest.TestCase):
|
||||||
reference = file.read()
|
reference = file.read()
|
||||||
reference = reference.replace("REPLACETHISWITHTODAY", rendering.get_today())
|
reference = reference.replace("REPLACETHISWITHTODAY", rendering.get_today())
|
||||||
|
|
||||||
self.assertEqual(output, reference)
|
self.assertEqual(
|
||||||
|
output, reference, msg="LaTeX file didn't match the reference."
|
||||||
|
)
|
||||||
|
|
||||||
# Check if the font directory exists:
|
# Check if the font directory exists:
|
||||||
font_directory_path = os.path.join(output_folder_path, "fonts")
|
font_directory_path = os.path.join(output_folder_path, "fonts")
|
||||||
self.assertTrue(os.path.exists(font_directory_path))
|
self.assertTrue(
|
||||||
|
os.path.exists(font_directory_path), msg="Font directory doesn't exist."
|
||||||
|
)
|
||||||
|
|
||||||
required_files = [
|
required_files = [
|
||||||
"EBGaramond-Italic.ttf",
|
"EBGaramond-Italic.ttf",
|
||||||
|
@ -393,7 +399,11 @@ class TestDataModel(unittest.TestCase):
|
||||||
font_files = os.listdir(font_directory_path)
|
font_files = os.listdir(font_directory_path)
|
||||||
for required_file in required_files:
|
for required_file in required_files:
|
||||||
with self.subTest(required_file=required_file):
|
with self.subTest(required_file=required_file):
|
||||||
self.assertIn(required_file, font_files)
|
self.assertIn(
|
||||||
|
required_file,
|
||||||
|
font_files,
|
||||||
|
msg=f"Font file ({required_file}) is missing.",
|
||||||
|
)
|
||||||
|
|
||||||
# Remove the output directory:
|
# Remove the output directory:
|
||||||
shutil.rmtree(output_folder_path)
|
shutil.rmtree(output_folder_path)
|
||||||
|
@ -407,20 +417,27 @@ class TestDataModel(unittest.TestCase):
|
||||||
pdf_file = rendering.run_latex(latex_file_path)
|
pdf_file = rendering.run_latex(latex_file_path)
|
||||||
|
|
||||||
# Check if the output file exists:
|
# Check if the output file exists:
|
||||||
self.assertTrue(os.path.exists(pdf_file))
|
self.assertTrue(
|
||||||
|
os.path.exists(pdf_file), msg="PDF file couldn't be generated."
|
||||||
|
)
|
||||||
|
|
||||||
# Compare the pdf file with the reference pdf file:
|
# Compare the pdf file with the reference pdf file:
|
||||||
reference_pdf_file = pdf_file.replace(".pdf", "_reference.pdf")
|
reference_pdf_file = pdf_file.replace(".pdf", "_reference.pdf")
|
||||||
self.assertTrue(
|
reference_pdf_file_size = os.path.getsize(reference_pdf_file)
|
||||||
os.path.getsize(pdf_file) == os.path.getsize(reference_pdf_file)
|
pdf_file_size = os.path.getsize(pdf_file)
|
||||||
|
ratio = min(reference_pdf_file_size, pdf_file_size) / max(
|
||||||
|
reference_pdf_file_size, pdf_file_size
|
||||||
)
|
)
|
||||||
|
self.assertTrue(ratio > 0.99, msg="PDF file didn't match the reference.")
|
||||||
|
|
||||||
nonexistent_latex_file_path = os.path.join(
|
nonexistent_latex_file_path = os.path.join(
|
||||||
os.path.dirname(__file__), "reference_files", "nonexistent.tex"
|
os.path.dirname(__file__), "reference_files", "nonexistent.tex"
|
||||||
)
|
)
|
||||||
|
|
||||||
with self.subTest(msg="Nonexistent file name"):
|
with self.subTest(msg="Nonexistent file name"):
|
||||||
with self.assertRaises(FileNotFoundError):
|
with self.assertRaises(
|
||||||
|
FileNotFoundError, msg="File not found error didn't raise."
|
||||||
|
):
|
||||||
rendering.run_latex(nonexistent_latex_file_path)
|
rendering.run_latex(nonexistent_latex_file_path)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue