mirror of https://github.com/eyhc1/rendercv.git
improve tests
This commit is contained in:
parent
8285fe7c79
commit
a9a004ab04
Binary file not shown.
|
@ -0,0 +1,148 @@
|
||||||
|
cv:
|
||||||
|
academic_projects:
|
||||||
|
- date: Spring 2022
|
||||||
|
highlights:
|
||||||
|
- Test 1
|
||||||
|
- Test 2
|
||||||
|
location: Istanbul, Turkey
|
||||||
|
name: Academic Project 1
|
||||||
|
url: https://example.com
|
||||||
|
- highlights:
|
||||||
|
- Test 1
|
||||||
|
- Test 2
|
||||||
|
name: Academic Project 2
|
||||||
|
url: https://example.com
|
||||||
|
- end_date: "2022-05-01"
|
||||||
|
highlights:
|
||||||
|
- Test 1
|
||||||
|
- Test 2
|
||||||
|
location: Istanbul, Turkey
|
||||||
|
name: Academic Project 3
|
||||||
|
start_date: "2022-02-01"
|
||||||
|
url: https://example.com
|
||||||
|
certificates:
|
||||||
|
- name: Certificate 1
|
||||||
|
education:
|
||||||
|
- area: Mechanical Engineering
|
||||||
|
end_date: "1985-01-01"
|
||||||
|
gpa: 3.80/4.00
|
||||||
|
highlights:
|
||||||
|
- Test 1
|
||||||
|
- Test 2
|
||||||
|
institution: Bogazici University
|
||||||
|
location: Istanbul, Turkey
|
||||||
|
start_date: "1980-09-01"
|
||||||
|
study_type: BS
|
||||||
|
transcript_url: https://example.com/
|
||||||
|
url: https://boun.edu.tr
|
||||||
|
- area: Mechanical Engineering, Student Exchange Program
|
||||||
|
end_date: "2022-01-15"
|
||||||
|
institution: The University of Texas at Austin
|
||||||
|
location: Austin, TX, USA
|
||||||
|
start_date: "2021-08-01"
|
||||||
|
url: https://utexas.edu
|
||||||
|
email: john@doe.com
|
||||||
|
extracurricular_activities:
|
||||||
|
- company: Test Company 1
|
||||||
|
highlights:
|
||||||
|
- Lead and train members for intercollegiate alpine ski races in Turkey and organize
|
||||||
|
skiing events.
|
||||||
|
position: Test Position 1
|
||||||
|
- company: Test Company 1
|
||||||
|
date: Summer 2019 and 2020
|
||||||
|
highlights:
|
||||||
|
- Test 1
|
||||||
|
- Test 2
|
||||||
|
- Test 3
|
||||||
|
location: Izmir, Turkey
|
||||||
|
position: Test Position 1
|
||||||
|
label: Engineer at CERN
|
||||||
|
location: Geneva, Switzerland
|
||||||
|
name: John Doe
|
||||||
|
personal_projects:
|
||||||
|
- name: Personal Project 1
|
||||||
|
phone: "+905413769286"
|
||||||
|
publications:
|
||||||
|
- authors:
|
||||||
|
- Cetin Yilmaz
|
||||||
|
- Gregory M Hulbert
|
||||||
|
- Noboru Kikuchi
|
||||||
|
cited_by: 243
|
||||||
|
date: "2007-08-01"
|
||||||
|
doi: 10.1103/PhysRevB.76.054309
|
||||||
|
journal: Physical Review B
|
||||||
|
title: Phononic band gaps induced by inertial amplification in periodic media
|
||||||
|
section_order:
|
||||||
|
- Education
|
||||||
|
- Work Experience
|
||||||
|
- Academic Projects
|
||||||
|
- Certificates
|
||||||
|
- Personal Projects
|
||||||
|
- Skills
|
||||||
|
- Test Scores
|
||||||
|
- Extracurricular Activities
|
||||||
|
- Publications
|
||||||
|
skills:
|
||||||
|
- details: C++, C, Python, JavaScript, MATLAB, Lua, LaTeX
|
||||||
|
name: Programming
|
||||||
|
- details: GMSH, GetDP, CalculiX
|
||||||
|
name: CAE
|
||||||
|
social_networks:
|
||||||
|
- network: LinkedIn
|
||||||
|
username: dummy
|
||||||
|
- network: GitHub
|
||||||
|
username: sinaatalay
|
||||||
|
test_scores:
|
||||||
|
- date: "2022-10-01"
|
||||||
|
details: 120/120
|
||||||
|
name: TOEFL
|
||||||
|
- details: 9.0/9.0
|
||||||
|
name: IELTS
|
||||||
|
url: https://example.com
|
||||||
|
website: https://example.com
|
||||||
|
work_experience:
|
||||||
|
- company: Company 1
|
||||||
|
end_date: present
|
||||||
|
highlights:
|
||||||
|
- Test 1
|
||||||
|
- Test 2
|
||||||
|
- Test 3
|
||||||
|
location: Geneva, Switzerland
|
||||||
|
position: Position 1
|
||||||
|
start_date: "2023-02-01"
|
||||||
|
url: https://example.com
|
||||||
|
- company: Company 2
|
||||||
|
end_date: "2023-02-01"
|
||||||
|
highlights:
|
||||||
|
- Test 1
|
||||||
|
- Test 2
|
||||||
|
- Test 3
|
||||||
|
location: Geneva, Switzerland
|
||||||
|
position: Position 2
|
||||||
|
start_date: "1986-02-01"
|
||||||
|
url: https://example.com
|
||||||
|
design:
|
||||||
|
font: EBGaramond
|
||||||
|
options:
|
||||||
|
date_and_location_width: 3.6 cm
|
||||||
|
margins:
|
||||||
|
entry_area:
|
||||||
|
left: 0.2 cm
|
||||||
|
right: 0.2 cm
|
||||||
|
vertical_between: 0.12 cm
|
||||||
|
highlights_area:
|
||||||
|
left: 0.6 cm
|
||||||
|
top: 0.12 cm
|
||||||
|
vertical_between_bullet_points: 0.07 cm
|
||||||
|
page:
|
||||||
|
bottom: 1.35 cm
|
||||||
|
left: 1.35 cm
|
||||||
|
right: 1.35 cm
|
||||||
|
top: 1.35 cm
|
||||||
|
section_title:
|
||||||
|
bottom: 0.13 cm
|
||||||
|
top: 0.13 cm
|
||||||
|
primary_color: rgb(0,79,144)
|
||||||
|
show_last_updated_date: true
|
||||||
|
show_timespan_in_experience_entries: true
|
||||||
|
theme: classic
|
|
@ -107,7 +107,7 @@ class TestDataModel(unittest.TestCase):
|
||||||
"theme": "classic",
|
"theme": "classic",
|
||||||
}
|
}
|
||||||
with self.subTest(msg="valid theme"):
|
with self.subTest(msg="valid theme"):
|
||||||
design = data_model.Design(**input) # type: ignore
|
design = data_model.Design(**input) # type: ignore
|
||||||
self.assertEqual(design.theme, input["theme"])
|
self.assertEqual(design.theme, input["theme"])
|
||||||
|
|
||||||
# Nonexistent theme:
|
# Nonexistent theme:
|
||||||
|
@ -116,7 +116,36 @@ class TestDataModel(unittest.TestCase):
|
||||||
}
|
}
|
||||||
with self.subTest(msg="nonexistent theme"):
|
with self.subTest(msg="nonexistent theme"):
|
||||||
with self.assertRaises(ValidationError):
|
with self.assertRaises(ValidationError):
|
||||||
data_model.Design(**input) # type: ignore
|
data_model.Design(**input) # type: ignore
|
||||||
|
|
||||||
|
def test_data_design_show_timespan_in(self):
|
||||||
|
# Valid show_timespan_in:
|
||||||
|
input = {
|
||||||
|
"design": {
|
||||||
|
"options": {
|
||||||
|
"show_timespan_in": ["Work Experience"],
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"cv": {
|
||||||
|
"name": "John Doe",
|
||||||
|
"work_experience": [
|
||||||
|
{
|
||||||
|
"company": "My Company",
|
||||||
|
"position": "My Position",
|
||||||
|
"start_date": "2020-01-01",
|
||||||
|
"end_date": "2021-01-01",
|
||||||
|
}
|
||||||
|
],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
with self.subTest(msg="valid show_timespan_in"):
|
||||||
|
data_model.RenderCVDataModel(**input)
|
||||||
|
|
||||||
|
# Nonexistent show_timespan_in:
|
||||||
|
del input["cv"]["work_experience"]
|
||||||
|
with self.subTest(msg="nonexistent show_timespan_in"):
|
||||||
|
with self.assertRaises(ValidationError):
|
||||||
|
data_model.RenderCVDataModel(**input)
|
||||||
|
|
||||||
def test_data_event_check_dates(self):
|
def test_data_event_check_dates(self):
|
||||||
# Inputs with valid dates:
|
# Inputs with valid dates:
|
||||||
|
|
|
@ -3,6 +3,8 @@ import os
|
||||||
import json
|
import json
|
||||||
from datetime import date
|
from datetime import date
|
||||||
import shutil
|
import shutil
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
|
||||||
from rendercv import rendering, data_model
|
from rendercv import rendering, data_model
|
||||||
|
|
||||||
|
@ -95,6 +97,14 @@ class TestRendering(unittest.TestCase):
|
||||||
with self.assertRaises(ValueError):
|
with self.assertRaises(ValueError):
|
||||||
rendering.markdown_link_to_url(input)
|
rendering.markdown_link_to_url(input)
|
||||||
|
|
||||||
|
def test_make_it_something(self):
|
||||||
|
# invalid input:
|
||||||
|
input = "test"
|
||||||
|
keyword = "invalid keyword"
|
||||||
|
with self.subTest(msg="invalid keyword"):
|
||||||
|
with self.assertRaises(ValueError):
|
||||||
|
rendering.make_it_something(input, keyword)
|
||||||
|
|
||||||
def test_make_it_bold(self):
|
def test_make_it_bold(self):
|
||||||
input = "some text"
|
input = "some text"
|
||||||
expected = r"\textbf{some text}"
|
expected = r"\textbf{some text}"
|
||||||
|
@ -395,18 +405,18 @@ class TestRendering(unittest.TestCase):
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
data = data_model.RenderCVDataModel(**test_input) # type: ignore
|
data = data_model.RenderCVDataModel(**test_input) # type: ignore
|
||||||
rendering.render_template(data=data, output_path=os.path.dirname(__file__))
|
output_file_path = rendering.render_template(
|
||||||
|
data=data, output_path=os.path.dirname(__file__)
|
||||||
|
)
|
||||||
|
|
||||||
# Check if the output file exists:
|
# Check if the output file exists:
|
||||||
output_folder_path = os.path.join(os.path.dirname(__file__), "output")
|
|
||||||
output_file_path = os.path.join(output_folder_path, "John_Doe_CV.tex")
|
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
os.path.exists(output_file_path), msg="LaTeX file couldn't be generated."
|
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(
|
||||||
os.path.dirname(__file__), "reference_files", "John_Doe_CV.tex"
|
os.path.dirname(__file__), "reference_files", "John_Doe_CV_test.tex"
|
||||||
)
|
)
|
||||||
with open(output_file_path, "r") as file:
|
with open(output_file_path, "r") as file:
|
||||||
output = file.read()
|
output = file.read()
|
||||||
|
@ -419,6 +429,7 @@ class TestRendering(unittest.TestCase):
|
||||||
)
|
)
|
||||||
|
|
||||||
# Check if the font directory exists:
|
# Check if the font directory exists:
|
||||||
|
output_folder_path = os.path.dirname(output_file_path)
|
||||||
font_directory_path = os.path.join(output_folder_path, "fonts")
|
font_directory_path = os.path.join(output_folder_path, "fonts")
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
os.path.exists(font_directory_path), msg="Font directory doesn't exist."
|
os.path.exists(font_directory_path), msg="Font directory doesn't exist."
|
||||||
|
@ -444,7 +455,7 @@ class TestRendering(unittest.TestCase):
|
||||||
|
|
||||||
def test_run_latex(self):
|
def test_run_latex(self):
|
||||||
latex_file_path = os.path.join(
|
latex_file_path = os.path.join(
|
||||||
os.path.dirname(__file__), "reference_files", "John_Doe_CV.tex"
|
os.path.dirname(__file__), "reference_files", "John_Doe_CV_test.tex"
|
||||||
)
|
)
|
||||||
|
|
||||||
with self.subTest(msg="Existent file name"):
|
with self.subTest(msg="Existent file name"):
|
||||||
|
@ -456,7 +467,7 @@ class TestRendering(unittest.TestCase):
|
||||||
)
|
)
|
||||||
|
|
||||||
# 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("_test.pdf", "_reference.pdf")
|
||||||
reference_pdf_file_size = os.path.getsize(reference_pdf_file)
|
reference_pdf_file_size = os.path.getsize(reference_pdf_file)
|
||||||
pdf_file_size = os.path.getsize(pdf_file)
|
pdf_file_size = os.path.getsize(pdf_file)
|
||||||
ratio = min(reference_pdf_file_size, pdf_file_size) / max(
|
ratio = min(reference_pdf_file_size, pdf_file_size) / max(
|
||||||
|
@ -474,6 +485,33 @@ class TestRendering(unittest.TestCase):
|
||||||
):
|
):
|
||||||
rendering.run_latex(nonexistent_latex_file_path)
|
rendering.run_latex(nonexistent_latex_file_path)
|
||||||
|
|
||||||
|
def test_main(self):
|
||||||
|
# Change the working directory to the root of the project:
|
||||||
|
workspace_path = os.path.dirname(os.path.dirname(__file__))
|
||||||
|
|
||||||
if __name__ == "__main__":
|
test_input_file_path = os.path.join(
|
||||||
unittest.main()
|
workspace_path, "tests", "reference_files", "John_Doe_CV_test.yaml"
|
||||||
|
)
|
||||||
|
subprocess.run(
|
||||||
|
[sys.executable, "-m", "rendercv", 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"))
|
||||||
|
|
||||||
|
# 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_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.99, msg="PDF file didn't match the reference.")
|
||||||
|
|
Loading…
Reference in New Issue