tests: test rendercv_settings

This commit is contained in:
Sina Atalay
2024-09-07 18:47:02 -04:00
parent 980466ffaf
commit f8a8809ff0
2 changed files with 181 additions and 1 deletions

View File

@@ -14,6 +14,8 @@ import rendercv.cli as cli
import rendercv.cli.printer as printer
import rendercv.cli.utilities as utilities
import rendercv.data as data
import rendercv.data.generator as generator
import rendercv.data.reader as reader
from rendercv import __version__
@@ -750,7 +752,7 @@ def test_set_or_update_a_value(rendercv_data_model, key, value):
value = eval(value)
if key == "cv.sections":
assert "test_title" in updated_model.cv.sections_input
assert "test_title" in updated_model.cv.sections_input # type: ignore
else:
assert eval(f"updated_model.{key}") == value
@@ -791,3 +793,132 @@ def test_relative_input_file_path_with_custom_output_paths(tmp_path, input_file_
)
assert (tmp_path / "test.pdf").exists()
def test_render_command_with_input_file_settings(tmp_path, input_file_path):
# change the current working directory to the temporary directory:
os.chdir(tmp_path)
# read the input file as a dictionary:
input_dictionary = reader.read_a_yaml_file(input_file_path)
# append rendercv_settings:
input_dictionary["rendercv_settings"] = {
"render_command": {
"pdf_path": "test.pdf",
"latex_path": "test.tex",
"markdown_path": "test.md",
"html_path": "test.html",
"png_path": "test.png",
}
}
# write the input dictionary to a new input file:
new_input_file_path = tmp_path / "new_input_file.yaml"
yaml_content = generator.dictionary_to_yaml(input_dictionary)
new_input_file_path.write_text(yaml_content, encoding="utf-8")
result = runner.invoke(
cli.app,
[
"render",
str(new_input_file_path.relative_to(tmp_path)),
],
)
print(result.stdout)
assert (tmp_path / "test.pdf").exists()
assert (tmp_path / "test.tex").exists()
assert (tmp_path / "test.md").exists()
assert (tmp_path / "test.html").exists()
assert (tmp_path / "test.png").exists()
assert "Your CV is rendered!" in result.stdout
def test_render_command_with_input_file_settings_2(tmp_path, input_file_path):
# change the current working directory to the temporary directory:
os.chdir(tmp_path)
# read the input file as a dictionary:
input_dictionary = reader.read_a_yaml_file(input_file_path)
# append rendercv_settings:
input_dictionary["rendercv_settings"] = {
"render_command": {
"dont_generate_html": True,
"dont_generate_markdown": True,
"dont_generate_png": True,
}
}
# write the input dictionary to a new input file:
new_input_file_path = tmp_path / "new_input_file.yaml"
yaml_content = generator.dictionary_to_yaml(input_dictionary)
new_input_file_path.write_text(yaml_content, encoding="utf-8")
result = runner.invoke(
cli.app,
[
"render",
str(new_input_file_path.relative_to(tmp_path)),
],
)
print(result.stdout)
assert (tmp_path / "rendercv_output" / "John_Doe_CV.pdf").exists()
assert not (tmp_path / "rendercv_output" / "John_Doe_CV.md").exists()
assert not (tmp_path / "rendercv_output" / "John_Doe_CV.html").exists()
assert not (tmp_path / "rendercv_output" / "John_Doe_CV_1.png").exists()
@pytest.mark.parametrize(
("option", "new_value"),
[
("pdf-path", "override.pdf"),
("latex-path", "override.tex"),
("markdown-path", "override.md"),
("html-path", "override.html"),
("png-path", "override.png"),
],
)
def test_render_command_overriding_input_file_settings(
tmp_path, input_file_path, option, new_value
):
# change the current working directory to the temporary directory:
os.chdir(tmp_path)
# read the input file as a dictionary:s
input_dictionary = reader.read_a_yaml_file(input_file_path)
# append rendercv_settings:
input_dictionary["rendercv_settings"] = {
"render_command": {
"pdf_path": "test.pdf",
"latex_path": "test.tex",
"markdown_path": "test.md",
"html_path": "test.html",
"png_path": "test.png",
}
}
# write the input dictionary to a new input file:
new_input_file_path = tmp_path / "new_input_file.yaml"
yaml_content = generator.dictionary_to_yaml(input_dictionary)
new_input_file_path.write_text(yaml_content, encoding="utf-8")
result = runner.invoke(
cli.app,
[
"render",
str(new_input_file_path.relative_to(tmp_path)),
f"--{option}",
new_value,
],
)
print(result.stdout)
assert (tmp_path / new_value).exists()
assert "Your CV is rendered!" in result.stdout

View File

@@ -722,6 +722,22 @@ def test_if_local_catalog_resets():
assert locale_catalog.locale_catalog["month"] == "month"
def test_curriculum_vitae():
data.CurriculumVitae(name="Test Doe")
assert curriculum_vitae.curriculum_vitae == {"name": "Test Doe"}
def test_if_curriculum_vitae_resets():
data.CurriculumVitae(name="Test Doe")
assert curriculum_vitae.curriculum_vitae["name"] == "Test Doe"
data.create_a_sample_data_model("John Doe")
assert curriculum_vitae.curriculum_vitae["name"] == "John Doe"
def test_dictionary_to_yaml():
input_dictionary = {
"test_list": [
@@ -791,3 +807,36 @@ def test_make_a_url_clean(url, expected_clean_url):
data.PublicationEntry(title="Test", authors=["test"], url=url).clean_url
== expected_clean_url
)
@pytest.mark.parametrize(
"path_name, expected_value",
[
("NAME_IN_SNAKE_CASE", "John_Doe"),
("NAME_IN_LOWER_SNAKE_CASE", "john_doe"),
("NAME_IN_UPPER_SNAKE_CASE", "JOHN_DOE"),
("NAME_IN_KEBAB_CASE", "John-Doe"),
("NAME_IN_LOWER_KEBAB_CASE", "john-doe"),
("NAME_IN_UPPER_KEBAB_CASE", "JOHN-DOE"),
("NAME", "John Doe"),
("FULL_MONTH_NAME", "January"),
("MONTH_ABBREVIATION", "Jan"),
("MONTH", "1"),
("MONTH_IN_TWO_DIGITS", "01"),
("YEAR", "2024"),
("YEAR_IN_TWO_DIGITS", "24"),
],
)
@time_machine.travel("2024-01-01")
def test_render_command_settings_placeholders(path_name, expected_value):
data.CurriculumVitae(name="John Doe")
render_command_settings = data.RenderCommandSettings(
pdf_path=path_name,
latex_path=path_name,
html_path=path_name,
markdown_path=path_name,
output_folder_name=path_name,
)
assert render_command_settings.pdf_path.name == expected_value # type: ignore