tests: update for the new package structure

This commit is contained in:
Sina Atalay committed 2024-07-05 15:01:02 +03:00
1 parent e9de90ffe4
commit b75139210f
63 files changed
+235 -208

No files matched your search

+23 -23
View File
@@ -15,9 +15,9 @@ import pydantic_extra_types.phone_numbers as pydantic_phone_numbers
import pypdf
import pytest
import rendercv.renderer as r
import rendercv.renderer as renderer
import rendercv.renderer.templater as rt
from rendercv import data as dm
from rendercv import data as data
# RenderCV is being tested by comparing the output to reference files. Therefore,
# reference files should be updated when RenderCV is updated in a way that changes
@@ -133,15 +133,15 @@ def text_entry() -> str:
@pytest.fixture
def rendercv_data_model() -> dm.RenderCVDataModel:
def rendercv_data_model() -> data.RenderCVDataModel:
"""Return a sample RenderCV data model."""
return dm.create_a_sample_data_model()
return data.create_a_sample_data_model()
@pytest.fixture
def rendercv_empty_curriculum_vitae_data_model() -> dm.CurriculumVitae:
def rendercv_empty_curriculum_vitae_data_model() -> data.CurriculumVitae:
"""Return an empty CurriculumVitae data model."""
return dm.CurriculumVitae(sections={"test": ["test"]})
return data.CurriculumVitae(sections={"test": ["test"]})
def return_a_value_for_a_field_type(
@@ -280,11 +280,11 @@ def create_combinations_of_a_model(
@pytest.fixture
def rendercv_filled_curriculum_vitae_data_model(
text_entry, bullet_entry
) -> dm.CurriculumVitae:
) -> data.CurriculumVitae:
"""Return a filled CurriculumVitae data model, where each section has all possible
combinations of entry types.
"""
return dm.CurriculumVitae(
return data.CurriculumVitae(
name="John Doe",
label="Mechanical Engineer",
location="Istanbul, Turkey",
@@ -292,25 +292,25 @@ def rendercv_filled_curriculum_vitae_data_model(
phone="+905419999999", # type: ignore
website="https://example.com", # type: ignore
social_networks=[
dm.SocialNetwork(network="LinkedIn", username="johndoe"),
dm.SocialNetwork(network="GitHub", username="johndoe"),
dm.SocialNetwork(network="Instagram", username="johndoe"),
dm.SocialNetwork(network="ORCID", username="0000-0000-0000-0000"),
dm.SocialNetwork(network="Google Scholar", username="F8IyYrQAAAAJ"),
dm.SocialNetwork(network="Mastodon", username="@johndoe@example.com"),
dm.SocialNetwork(network="StackOverflow", username="12323/johndoe"),
dm.SocialNetwork(network="GitLab", username="johndoe"),
dm.SocialNetwork(network="ResearchGate", username="johndoe"),
dm.SocialNetwork(network="YouTube", username="johndoe"),
data.SocialNetwork(network="LinkedIn", username="johndoe"),
data.SocialNetwork(network="GitHub", username="johndoe"),
data.SocialNetwork(network="Instagram", username="johndoe"),
data.SocialNetwork(network="ORCID", username="0000-0000-0000-0000"),
data.SocialNetwork(network="Google Scholar", username="F8IyYrQAAAAJ"),
data.SocialNetwork(network="Mastodon", username="@johndoe@example.com"),
data.SocialNetwork(network="StackOverflow", username="12323/johndoe"),
data.SocialNetwork(network="GitLab", username="johndoe"),
data.SocialNetwork(network="ResearchGate", username="johndoe"),
data.SocialNetwork(network="YouTube", username="johndoe"),
],
sections={
"Text Entries": [text_entry, text_entry, text_entry],
"Bullet Entries": [bullet_entry, bullet_entry],
"Publication Entries": create_combinations_of_a_model(dm.PublicationEntry),
"Experience Entries": create_combinations_of_a_model(dm.ExperienceEntry),
"Education Entries": create_combinations_of_a_model(dm.EducationEntry),
"Normal Entries": create_combinations_of_a_model(dm.NormalEntry),
"One Line Entries": create_combinations_of_a_model(dm.OneLineEntry),
"Publication Entries": create_combinations_of_a_model(data.PublicationEntry),
"Experience Entries": create_combinations_of_a_model(data.ExperienceEntry),
"Education Entries": create_combinations_of_a_model(data.EducationEntry),
"Normal Entries": create_combinations_of_a_model(data.NormalEntry),
"One Line Entries": create_combinations_of_a_model(data.OneLineEntry),
},
)
+82 -25
View File
@@ -2,6 +2,7 @@ import os
import shutil
import subprocess
import sys
import re
from datetime import date as Date
import pydantic
@@ -11,8 +12,8 @@ import typer.testing
import rendercv.cli as cli
import rendercv.cli.printer as printer
import rendercv.cli.utilities as util
import rendercv.data as dm
import rendercv.cli.utilities as utilities
import rendercv.data as data
from rendercv import __version__
@@ -58,19 +59,19 @@ def test_information():
def test_get_error_message_and_location_and_value_from_a_custom_error():
error_string = "('error message', 'location', 'value')"
result = util.get_error_message_and_location_and_value_from_a_custom_error(
result = utilities.get_error_message_and_location_and_value_from_a_custom_error(
error_string
)
assert result == ("error message", "location", "value")
error_string = """("er'ror message", 'location', 'value')"""
result = util.get_error_message_and_location_and_value_from_a_custom_error(
result = utilities.get_error_message_and_location_and_value_from_a_custom_error(
error_string
)
assert result == ("er'ror message", "location", "value")
error_string = "error message"
result = util.get_error_message_and_location_and_value_from_a_custom_error(
result = utilities.get_error_message_and_location_and_value_from_a_custom_error(
error_string
)
assert result == (None, None, None)
@@ -80,32 +81,32 @@ def test_get_error_message_and_location_and_value_from_a_custom_error():
"data_model_class, invalid_model",
[
(
dm.EducationEntry,
data.EducationEntry,
{
"area": "Mechanical Engineering",
"extra": "Extra",
},
),
(
dm.ExperienceEntry,
data.ExperienceEntry,
{
"company": "CERN",
},
),
(
dm.ExperienceEntry,
data.ExperienceEntry,
{
"position": "Researcher",
},
),
(
dm.ExperienceEntry,
data.ExperienceEntry,
{
"position": Date(2020, 10, 1),
},
),
(
dm.ExperienceEntry,
data.ExperienceEntry,
{
"company": "CERN",
"position": "Researcher",
@@ -114,7 +115,7 @@ def test_get_error_message_and_location_and_value_from_a_custom_error():
},
),
(
dm.ExperienceEntry,
data.ExperienceEntry,
{
"company": "CERN",
"position": "Researcher",
@@ -122,25 +123,25 @@ def test_get_error_message_and_location_and_value_from_a_custom_error():
},
),
(
dm.PublicationEntry,
data.PublicationEntry,
{
"doi": "10.1109/TASC.2023.3340648",
},
),
(
dm.ExperienceEntry,
data.ExperienceEntry,
{
"authors": ["John Doe", "Jane Doe"],
},
),
(
dm.OneLineEntry,
data.OneLineEntry,
{
"name": "My One Line Entry",
},
),
(
dm.CurriculumVitae,
data.CurriculumVitae,
{
"name": "John Doe",
"sections": {
@@ -159,7 +160,7 @@ def test_get_error_message_and_location_and_value_from_a_custom_error():
},
),
(
dm.RenderCVDataModel,
data.RenderCVDataModel,
{
"cv": {
"name": "John Doe",
@@ -188,7 +189,7 @@ def test_print_validation_errors(data_model_class, invalid_model):
],
)
def test_handle_exceptions(exception):
@handlers.handle_exceptions
@printer.handle_and_print_raised_exceptions
def function_that_raises_exception():
raise exception
@@ -210,10 +211,10 @@ def test_live_progress_reporter_class():
@pytest.mark.parametrize(
"folder_name",
["markdown"] + dm.available_themes,
["markdown"] + data.available_themes,
)
def test_copy_templates(tmp_path, folder_name):
copied_path = util.copy_templates(
copied_path = utilities.copy_templates(
folder_name=folder_name,
copy_to=tmp_path,
)
@@ -225,7 +226,7 @@ def test_copy_templates(tmp_path, folder_name):
def test_copy_templates_with_new_folder_name(tmp_path):
copied_path = cli.copy_templates(
copied_path = utilities.copy_templates(
folder_name="markdown",
copy_to=tmp_path,
new_folder_name="new_folder",
@@ -235,12 +236,12 @@ def test_copy_templates_with_new_folder_name(tmp_path):
@pytest.mark.parametrize(
"folder_name",
["markdown"] + dm.available_themes,
["markdown"] + data.available_themes,
)
def test_copy_templates_destinations_exist(tmp_path, folder_name):
(tmp_path / folder_name).mkdir()
copied_path = cli.copy_templates(
copied_path = utilities.copy_templates(
folder_name=folder_name,
copy_to=tmp_path,
)
@@ -521,7 +522,7 @@ def test_new_command_with_existing_files(tmp_path, file_or_folder_name):
@pytest.mark.parametrize(
"based_on",
dm.available_themes,
data.available_themes,
)
def test_create_theme_command(tmp_path, input_file_path, based_on):
# change the current working directory to the temporary directory:
@@ -580,12 +581,12 @@ def test_main_file():
def test_get_latest_version_number_from_pypi():
version = util.get_latest_version_number_from_pypi()
version = utilities.get_latest_version_number_from_pypi()
assert isinstance(version, str)
def test_if_welcome_prints_new_version_available(monkeypatch):
monkeypatch.setattr(cli, "get_latest_version_number_from_pypi", lambda: "99999")
monkeypatch.setattr(utilities, "get_latest_version_number_from_pypi", lambda: "99999")
import contextlib
import io
@@ -620,3 +621,59 @@ def test_warn_if_new_version_is_available(monkeypatch):
monkeypatch.setattr(cli, "get_latest_version_number_from_pypi", lambda: "999")
assert printer.warn_if_new_version_is_available()
@pytest.mark.parametrize(
"key, value",
[
("cv.phone", "+905555555555"),
("cv.email", "test@example.com"),
("cv.sections.education.0.degree", "PhD"),
("cv.sections.education.0.highlights.0", "Did this."),
("cv.sections.this_is_a_new_section", '["This is a text entry."]'),
("design.page_size", "a4paper"),
("design", '{"theme": "engineeringresumes"}'),
],
)
def test_set_or_update_a_value(rendercv_data_model, key, value):
utilities.set_or_update_a_value(rendercv_data_model, key, value)
# replace with regex pattern:
key = re.sub(r"sections\.([^\.]*)", 'sections_input["\\1"]', key)
key = re.sub(r"\.(\d+)", "[\\1]", key)
if value.startswith("{") and value.endswith("}"):
value = eval(value)
elif value.startswith("[") and value.endswith("]"):
value = eval(value)
assert eval(f"rendercv_data_model.{key}") == value
@pytest.mark.parametrize(
"key, value",
[
("cv.phones", "+905555555555"),
("cv.emssdsail", ""),
("cv.sections.education.99.degree", "PhD"),
("dessssign.page_size", "a4paper"),
],
)
def test_set_or_update_a_value_invalid_keys(rendercv_data_model, key, value):
with pytest.raises((ValueError, KeyError, IndexError, AttributeError)):
utilities.set_or_update_a_value(rendercv_data_model, key, value)
@pytest.mark.parametrize(
"key, value",
[
("cv.phone", "+9999995555555555"),
("cv.email", "notanemail***"),
("cv.sections.education.0.highlights", "this is not a list"),
("design.page_size", "invalid_page_size"),
],
)
def test_set_or_update_a_value_invalid_values(rendercv_data_model, key, value):
with pytest.raises(pydantic.ValidationError):
utilities.set_or_update_a_value(rendercv_data_model, key, value)
+65 -104
View File
@@ -1,7 +1,6 @@
import io
import json
import os
import re
import shutil
from datetime import date as Date
@@ -10,7 +9,12 @@ import pytest
import ruamel.yaml
import time_machine
from rendercv import data as dm
from rendercv import data as data
from rendercv.data import generator
from rendercv.data.models import computers
from rendercv.data.models import locale_catalog
from rendercv.data.models import curriculum_vitae
from rendercv.data.models import entry_types
from .conftest import update_testdata
@@ -34,9 +38,9 @@ from .conftest import update_testdata
def test_get_date_object(date, expected_date_object, expected_error):
if expected_error:
with pytest.raises(expected_error):
dm.get_date_object(date)
computers.get_date_object(date)
else:
assert dm.get_date_object(date) == expected_date_object
assert computers.get_date_object(date) == expected_date_object
@pytest.mark.parametrize(
@@ -57,62 +61,7 @@ def test_get_date_object(date, expected_date_object, expected_error):
],
)
def test_format_date(date, expected_date_string):
assert dm.format_date(date) == expected_date_string
@pytest.mark.parametrize(
"key, value",
[
("cv.phone", "+905555555555"),
("cv.email", "test@example.com"),
("cv.sections.education.0.degree", "PhD"),
("cv.sections.education.0.highlights.0", "Did this."),
("cv.sections.this_is_a_new_section", '["This is a text entry."]'),
("design.page_size", "a4paper"),
("design", '{"theme": "engineeringresumes"}'),
],
)
def test_set_or_update_a_value(rendercv_data_model, key, value):
dm.set_or_update_a_value(rendercv_data_model, key, value)
# replace with regex pattern:
key = re.sub(r"sections\.([^\.]*)", 'sections_input["\\1"]', key)
key = re.sub(r"\.(\d+)", "[\\1]", key)
if value.startswith("{") and value.endswith("}"):
value = eval(value)
elif value.startswith("[") and value.endswith("]"):
value = eval(value)
assert eval(f"rendercv_data_model.{key}") == value
@pytest.mark.parametrize(
"key, value",
[
("cv.phones", "+905555555555"),
("cv.emssdsail", ""),
("cv.sections.education.99.degree", "PhD"),
("dessssign.page_size", "a4paper"),
],
)
def test_set_or_update_a_value_invalid_keys(rendercv_data_model, key, value):
with pytest.raises((ValueError, KeyError, IndexError, AttributeError)):
dm.set_or_update_a_value(rendercv_data_model, key, value)
@pytest.mark.parametrize(
"key, value",
[
("cv.phone", "+9999995555555555"),
("cv.email", "notanemail***"),
("cv.sections.education.0.highlights", "this is not a list"),
("design.page_size", "invalid_page_size"),
],
)
def test_set_or_update_a_value_invalid_values(rendercv_data_model, key, value):
with pytest.raises(pydantic.ValidationError):
dm.set_or_update_a_value(rendercv_data_model, key, value)
assert data.format_date(date) == expected_date_string
def test_read_input_file(input_file_path):
@@ -135,9 +84,9 @@ def test_read_input_file(input_file_path):
yaml_object = ruamel.yaml.YAML()
yaml_object.dump(input_dictionary, input_file_path)
data_model = dm.read_input_file(input_file_path)
data_model = data.read_input_file(input_file_path)
assert isinstance(data_model, dm.RenderCVDataModel)
assert isinstance(data_model, data.RenderCVDataModel)
def test_read_input_file_directly_with_contents(input_file_path):
@@ -158,46 +107,46 @@ def test_read_input_file_directly_with_contents(input_file_path):
yaml_object.dump(input_dictionary, string_stream)
yaml_string = string_stream.getvalue()
data_model = dm.read_input_file(yaml_string)
data_model = data.read_input_file(yaml_string)
assert isinstance(data_model, dm.RenderCVDataModel)
assert isinstance(data_model, data.RenderCVDataModel)
def test_read_input_file_invalid_file(tmp_path):
invalid_file_path = tmp_path / "invalid.extension"
invalid_file_path.write_text("dummy content", encoding="utf-8")
with pytest.raises(ValueError):
dm.read_input_file(invalid_file_path)
data.read_input_file(invalid_file_path)
def test_read_input_file_that_doesnt_exist(tmp_path):
non_existent_file_path = tmp_path / "non_existent_file.yaml"
with pytest.raises(FileNotFoundError):
dm.read_input_file(non_existent_file_path)
data.read_input_file(non_existent_file_path)
@pytest.mark.parametrize(
"theme",
dm.available_themes,
data.available_themes,
)
def test_get_a_sample_data_model(theme):
data_model = dm.create_a_sample_data_model("John Doe", theme)
assert isinstance(data_model, dm.RenderCVDataModel)
data_model = data.create_a_sample_data_model("John Doe", theme)
assert isinstance(data_model, data.RenderCVDataModel)
def test_get_a_sample_data_model_invalid_theme():
with pytest.raises(ValueError):
dm.create_a_sample_data_model("John Doe", "invalid")
data.create_a_sample_data_model("John Doe", "invalid")
def test_generate_json_schema():
schema = dm.generate_json_schema()
schema = data.generate_json_schema()
assert isinstance(schema, dict)
def test_generate_json_schema_file(tmp_path):
schema_file_path = tmp_path / "schema.json"
dm.generate_json_schema_file(schema_file_path)
data.generate_json_schema_file(schema_file_path)
assert schema_file_path.exists()
@@ -340,7 +289,9 @@ def test_dates(
expected_date_string_only_years,
expected_time_span,
):
entry_base = dm.EntryBase(start_date=start_date, end_date=end_date, date=date)
entry_base = entry_types.EntryBase(
start_date=start_date, end_date=end_date, date=date
)
assert entry_base.date_string == expected_date_string
assert entry_base.date_string_only_years == expected_date_string_only_years
@@ -357,7 +308,7 @@ def test_dates(
)
def test_publication_dates(publication_entry, date, expected_date_string):
publication_entry["date"] = date
publication_entry = dm.PublicationEntry(**publication_entry)
publication_entry = data.PublicationEntry(**publication_entry)
assert publication_entry.date_string == expected_date_string
@@ -365,7 +316,7 @@ def test_publication_dates(publication_entry, date, expected_date_string):
def test_invalid_publication_dates(publication_entry, date):
with pytest.raises(pydantic.ValidationError):
publication_entry["date"] = date
dm.PublicationEntry(**publication_entry)
data.PublicationEntry(**publication_entry)
@pytest.mark.parametrize(
@@ -385,7 +336,7 @@ def test_invalid_publication_dates(publication_entry, date):
)
def test_invalid_dates(start_date, end_date, date):
with pytest.raises(pydantic.ValidationError):
dm.EntryBase(start_date=start_date, end_date=end_date, date=date)
entry_types.EntryBase(start_date=start_date, end_date=end_date, date=date)
@pytest.mark.parametrize(
@@ -396,7 +347,7 @@ def test_invalid_dates(start_date, end_date, date):
)
def test_doi_url(publication_entry, doi, expected_doi_url):
publication_entry["doi"] = doi
publication_entry = dm.PublicationEntry(**publication_entry)
publication_entry = data.PublicationEntry(**publication_entry)
assert publication_entry.doi_url == expected_doi_url
@@ -414,7 +365,7 @@ def test_doi_url(publication_entry, doi, expected_doi_url):
)
def test_invalid_social_networks(network, username):
with pytest.raises(pydantic.ValidationError):
dm.SocialNetwork(network=network, username=username)
data.SocialNetwork(network=network, username=username)
@pytest.mark.parametrize(
@@ -453,7 +404,7 @@ def test_invalid_social_networks(network, username):
],
)
def test_social_network_url(network, username, expected_url):
social_network = dm.SocialNetwork(network=network, username=username)
social_network = data.SocialNetwork(network=network, username=username)
assert str(social_network.url) == expected_url
@@ -485,18 +436,26 @@ def test_social_network_url(network, username, expected_url):
("bullet_entry", "BulletEntry", "SectionWithBulletEntries"),
],
)
def test_get_entry_and_section_type(
def test_get_entry_type_name_and_section_validator(
entry, expected_entry_type, expected_section_type, request: pytest.FixtureRequest
):
entry = request.getfixturevalue(entry)
entry_type, section_type = dm.get_entry_and_section_type(entry)
entry_type, section_type = (
curriculum_vitae.get_entry_type_name_and_section_validator(
entry, entry_types.available_entry_models
)
)
assert entry_type == expected_entry_type
assert section_type.__name__ == expected_section_type
# initialize the entry with the entry type
if entry_type != "TextEntry":
entry = eval(f"dm.{entry_type}(**entry)")
entry_type, section_type = dm.get_entry_and_section_type(entry)
entry = eval(f"data.{entry_type}(**entry)")
entry_type, section_type = (
curriculum_vitae.get_entry_type_name_and_section_validator(
entry, entry_types.available_entry_models
)
)
assert entry_type == expected_entry_type
assert section_type.__name__ == expected_section_type
@@ -539,7 +498,7 @@ def test_sections(
},
}
cv = dm.CurriculumVitae(**input)
cv = data.CurriculumVitae(**input)
assert len(cv.sections) == 6
for section in cv.sections:
assert len(section.entries) == 2
@@ -555,7 +514,7 @@ def test_sections_with_invalid_entries():
}
]
with pytest.raises(pydantic.ValidationError):
dm.CurriculumVitae(**input)
data.CurriculumVitae(**input)
def test_sections_without_list():
@@ -564,7 +523,7 @@ def test_sections_without_list():
"this section": "does not have a list of entries but a single entry."
}
with pytest.raises(pydantic.ValidationError):
dm.CurriculumVitae(**input)
data.CurriculumVitae(**input)
@pytest.mark.parametrize(
@@ -576,7 +535,7 @@ def test_sections_without_list():
)
def test_invalid_custom_theme(invalid_custom_theme_name):
with pytest.raises(pydantic.ValidationError):
dm.RenderCVDataModel(
data.RenderCVDataModel(
**{
"cv": {"name": "John Doe"},
"design": {"theme": invalid_custom_theme_name},
@@ -589,7 +548,7 @@ def test_custom_theme_with_missing_files(tmp_path):
custom_theme_path.mkdir()
with pytest.raises(pydantic.ValidationError):
os.chdir(tmp_path)
dm.RenderCVDataModel(
data.RenderCVDataModel(
**{ # type: ignore
"cv": {"name": "John Doe"},
"design": {"theme": "customtheme"},
@@ -602,7 +561,7 @@ def test_custom_theme(testdata_directory_path):
testdata_directory_path
/ "test_copy_theme_files_to_output_directory_custom_theme"
)
data_model = dm.RenderCVDataModel(
data_model = data.RenderCVDataModel(
**{ # type: ignore
"cv": {"name": "John Doe"},
"design": {"theme": "dummytheme"},
@@ -628,7 +587,7 @@ def test_custom_theme_without_init_file(tmp_path, testdata_directory_path):
init_file.unlink()
os.chdir(tmp_path)
data_model = dm.RenderCVDataModel(
data_model = data.RenderCVDataModel(
**{ # type: ignore
"cv": {"name": "John Doe"},
"design": {"theme": "dummytheme"},
@@ -655,7 +614,7 @@ def test_custom_theme_with_broken_init_file(tmp_path, testdata_directory_path):
os.chdir(tmp_path)
with pytest.raises(pydantic.ValidationError):
dm.RenderCVDataModel(
data.RenderCVDataModel(
**{ # type: ignore
"cv": {"name": "John Doe"},
"design": {"theme": "dummytheme"},
@@ -668,7 +627,7 @@ def test_custom_theme_with_broken_init_file(tmp_path, testdata_directory_path):
os.chdir(tmp_path)
with pytest.raises(pydantic.ValidationError):
dm.RenderCVDataModel(
data.RenderCVDataModel(
**{ # type: ignore
"cv": {"name": "John Doe"},
"design": {"theme": "dummytheme"},
@@ -677,8 +636,8 @@ def test_custom_theme_with_broken_init_file(tmp_path, testdata_directory_path):
def test_locale_catalog():
data_model = dm.create_a_sample_data_model("John Doe")
data_model.locale_catalog = dm.LocaleCatalog(
data_model = data.create_a_sample_data_model("John Doe")
data_model.locale_catalog = data.LocaleCatalog(
month="a",
months="b",
year="c",
@@ -715,21 +674,21 @@ def test_locale_catalog():
],
)
assert dm.locale_catalog == data_model.locale_catalog.model_dump()
assert locale_catalog.locale_catalog == data_model.locale_catalog.model_dump()
def test_if_local_catalog_resets():
data_model = dm.create_a_sample_data_model("John Doe")
data_model = data.create_a_sample_data_model("John Doe")
data_model.locale_catalog = dm.LocaleCatalog(
data_model.locale_catalog = data.LocaleCatalog(
month="a",
)
assert dm.locale_catalog["month"] == "a"
assert locale_catalog.locale_catalog["month"] == "a"
data_model = dm.create_a_sample_data_model("John Doe")
data_model = data.create_a_sample_data_model("John Doe")
assert dm.locale_catalog["month"] == "month"
assert locale_catalog.locale_catalog["month"] == "month"
def test_dictionary_to_yaml():
@@ -744,7 +703,7 @@ def test_dictionary_to_yaml():
"b": 2,
},
}
yaml_string = dm.dictionary_to_yaml(input_dictionary)
yaml_string = generator.dictionary_to_yaml(input_dictionary)
# load the yaml string
yaml_object = ruamel.yaml.YAML()
@@ -755,14 +714,14 @@ def test_dictionary_to_yaml():
def test_create_a_sample_yaml_input_file(tmp_path):
input_file_path = tmp_path / "input.yaml"
yaml_contents = dm.create_a_sample_yaml_input_file(input_file_path)
yaml_contents = data.create_a_sample_yaml_input_file(input_file_path)
assert input_file_path.exists()
assert yaml_contents == input_file_path.read_text(encoding="utf-8")
def test_default_input_file_doesnt_have_local_catalog():
yaml_contents = dm.create_a_sample_yaml_input_file()
yaml_contents = data.create_a_sample_yaml_input_file()
assert "locale_catalog" not in yaml_contents
@@ -777,7 +736,9 @@ def test_default_input_file_doesnt_have_local_catalog():
],
)
def test_dictionary_key_to_proper_section_title(key, expected_section_title):
assert dm.dictionary_key_to_proper_section_title(key) == expected_section_title
assert (
computers.dictionary_key_to_proper_section_title(key) == expected_section_title
)
# def test_if_available_themes_and_avaialble_theme_options_has_the_same_length():
+65 -56
View File
@@ -8,8 +8,9 @@ import jinja2
import pytest
import time_machine
from rendercv import data as dm
from rendercv import renderer as r
from rendercv import data as data
from rendercv import renderer
from rendercv.renderer import templater
folder_name_dictionary = {
"rendercv_empty_curriculum_vitae_data_model": "empty",
@@ -18,7 +19,7 @@ folder_name_dictionary = {
def test_latex_file_class(tmp_path, rendercv_data_model, jinja2_environment):
latex_file = r.LaTeXFile(rendercv_data_model, jinja2_environment)
latex_file = templater.LaTeXFile(rendercv_data_model, jinja2_environment)
latex_file.get_latex_code()
latex_file.render_a_latex_file(tmp_path / "test.tex")
@@ -77,11 +78,11 @@ def test_latex_file_class(tmp_path, rendercv_data_model, jinja2_environment):
],
)
def test_latex_file_revert_nested_latex_style_commands_method(string, expected_string):
assert r.revert_nested_latex_style_commands(string) == expected_string
assert templater.revert_nested_latex_style_commands(string) == expected_string
def test_markdown_file_class(tmp_path, rendercv_data_model, jinja2_environment):
latex_file = r.MarkdownFile(rendercv_data_model, jinja2_environment)
latex_file = templater.MarkdownFile(rendercv_data_model, jinja2_environment)
latex_file.get_markdown_code()
latex_file.render_a_markdown_file(tmp_path / "test.tex")
@@ -109,13 +110,13 @@ def test_markdown_file_class(tmp_path, rendercv_data_model, jinja2_environment):
],
)
def test_escape_latex_characters_not_strict(string, expected_string):
assert r.escape_latex_characters(string, strict=False) == expected_string
assert templater.escape_latex_characters(string, strict=False) == expected_string
def test_escape_latex_characters_strict():
string = "$a=5_4^3$"
expected_string = "\\$a=5\\_4\\textasciicircum{}3\\$"
assert r.escape_latex_characters(string, strict=True) == expected_string
assert templater.escape_latex_characters(string, strict=True) == expected_string
@pytest.mark.parametrize(
@@ -141,17 +142,17 @@ def test_escape_latex_characters_strict():
],
)
def test_markdown_to_latex(markdown_string, expected_latex_string):
assert r.markdown_to_latex(markdown_string) == expected_latex_string
assert templater.markdown_to_latex(markdown_string) == expected_latex_string
def test_transform_markdown_sections_to_latex_sections(rendercv_data_model):
new_data_model = copy.deepcopy(rendercv_data_model)
new_sections_input = r.transform_markdown_sections_to_latex_sections(
new_sections_input = templater.transform_markdown_sections_to_latex_sections(
new_data_model.cv.sections_input
)
new_data_model.cv.sections_input = new_sections_input
assert isinstance(new_data_model, dm.RenderCVDataModel)
assert isinstance(new_data_model, data.RenderCVDataModel)
assert new_data_model.cv.name == rendercv_data_model.cv.name
assert new_data_model.design == rendercv_data_model.design
assert new_data_model.cv.sections != rendercv_data_model.cv.sections
@@ -176,7 +177,7 @@ def test_transform_markdown_sections_to_latex_sections(rendercv_data_model):
],
)
def test_replace_placeholders_with_actual_values(string, placeholders, expected_string):
result = r.replace_placeholders_with_actual_values(string, placeholders)
result = templater.replace_placeholders_with_actual_values(string, placeholders)
assert result == expected_string
@@ -191,7 +192,7 @@ def test_replace_placeholders_with_actual_values(string, placeholders, expected_
],
)
def test_make_matched_part_something(value, something, match_str, expected):
result = r.make_matched_part_something(value, something, match_str)
result = templater.make_matched_part_something(value, something, match_str)
assert result == expected
@@ -206,7 +207,7 @@ def test_make_matched_part_something(value, something, match_str, expected):
],
)
def test_make_matched_part_bold(value, match_str, expected):
result = r.make_matched_part_bold(value, match_str)
result = templater.make_matched_part_bold(value, match_str)
assert result == expected
@@ -221,7 +222,7 @@ def test_make_matched_part_bold(value, match_str, expected):
],
)
def test_make_matched_part_underlined(value, match_str, expected):
result = r.make_matched_part_underlined(value, match_str)
result = templater.make_matched_part_underlined(value, match_str)
assert result == expected
@@ -236,7 +237,7 @@ def test_make_matched_part_underlined(value, match_str, expected):
],
)
def test_make_matched_part_italic(value, match_str, expected):
result = r.make_matched_part_italic(value, match_str)
result = templater.make_matched_part_italic(value, match_str)
assert result == expected
@@ -251,7 +252,7 @@ def test_make_matched_part_italic(value, match_str, expected):
],
)
def test_make_matched_part_non_line_breakable(value, match_str, expected):
result = r.make_matched_part_non_line_breakable(value, match_str)
result = templater.make_matched_part_non_line_breakable(value, match_str)
assert result == expected
@@ -266,7 +267,7 @@ def test_make_matched_part_non_line_breakable(value, match_str, expected):
],
)
def test_abbreviate_name(name, expected):
result = r.abbreviate_name(name)
result = templater.abbreviate_name(name)
assert result == expected
@@ -284,7 +285,7 @@ def test_abbreviate_name(name, expected):
],
)
def test_divide_length_by(length, divider, expected):
result = r.divide_length_by(length, divider)
result = templater.divide_length_by(length, divider)
assert math.isclose(
float(result[:-2]), float(expected[:-2]), rel_tol=1e-2
), f"Expected {expected}, but got {result}"
@@ -296,35 +297,37 @@ def test_divide_length_by(length, divider, expected):
)
def test_invalid_divide_length_by(length, divider):
with pytest.raises(ValueError):
r.divide_length_by(length, divider)
templater.divide_length_by(length, divider)
def test_get_an_item_with_a_specific_attribute_value():
entry_objects = [
dm.OneLineEntry(
data.OneLineEntry(
label="Test1",
details="Test2",
),
dm.OneLineEntry(
data.OneLineEntry(
label="Test3",
details="Test4",
),
]
result = r.get_an_item_with_a_specific_attribute_value(
result = templater.get_an_item_with_a_specific_attribute_value(
entry_objects, "label", "Test3"
)
assert result == entry_objects[1]
result = r.get_an_item_with_a_specific_attribute_value(
result = templater.get_an_item_with_a_specific_attribute_value(
entry_objects, "label", "DoesntExist"
)
assert result is None
with pytest.raises(AttributeError):
r.get_an_item_with_a_specific_attribute_value(entry_objects, "invalid", "Test5")
templater.get_an_item_with_a_specific_attribute_value(
entry_objects, "invalid", "Test5"
)
def test_setup_jinja2_environment():
env = r.setup_jinja2_environment()
env = templater.setup_jinja2_environment()
# Check if the returned object is a jinja2.Environment instance
assert isinstance(env, jinja2.Environment)
@@ -350,7 +353,7 @@ def test_setup_jinja2_environment():
@pytest.mark.parametrize(
"theme_name",
dm.available_themes,
data.available_themes,
)
@pytest.mark.parametrize(
"curriculum_vitae_data_model",
@@ -367,7 +370,7 @@ def test_render_a_latex_file(
curriculum_vitae_data_model,
):
cv_data_model = request.getfixturevalue(curriculum_vitae_data_model)
data_model = dm.RenderCVDataModel(
data_model = data.RenderCVDataModel(
cv=cv_data_model,
design={"theme": theme_name},
)
@@ -378,7 +381,7 @@ def test_render_a_latex_file(
)
def render_a_latex_file(output_directory_path, reference_file_or_directory_path):
r.render_a_latex_file(data_model, output_directory_path)
renderer.render_a_latex_file(data_model, output_directory_path)
assert run_a_function_and_check_if_output_is_the_same_as_reference(
render_a_latex_file,
@@ -392,14 +395,14 @@ def test_if_render_a_latex_file_can_create_a_new_directory(
):
new_directory = tmp_path / "new_directory"
latex_file_path = r.render_a_latex_file(rendercv_data_model, new_directory)
latex_file_path = renderer.render_a_latex_file(rendercv_data_model, new_directory)
assert latex_file_path.exists()
@pytest.mark.parametrize(
"theme_name",
dm.available_themes,
data.available_themes,
)
@pytest.mark.parametrize(
"curriculum_vitae_data_model",
@@ -416,7 +419,7 @@ def test_render_a_markdown_file(
curriculum_vitae_data_model,
):
cv_data_model = request.getfixturevalue(curriculum_vitae_data_model)
data_model = dm.RenderCVDataModel(
data_model = data.RenderCVDataModel(
cv=cv_data_model,
design={"theme": theme_name},
)
@@ -427,7 +430,7 @@ def test_render_a_markdown_file(
)
def render_a_markdown_file(output_directory_path, reference_file_or_directory_path):
r.render_a_markdown_file(data_model, output_directory_path)
renderer.render_a_markdown_file(data_model, output_directory_path)
assert run_a_function_and_check_if_output_is_the_same_as_reference(
render_a_markdown_file,
@@ -441,14 +444,16 @@ def test_if_render_a_markdown_file_can_create_a_new_directory(
):
new_directory = tmp_path / "new_directory"
latex_file_path = r.render_a_markdown_file(rendercv_data_model, new_directory)
latex_file_path = renderer.render_a_markdown_file(
rendercv_data_model, new_directory
)
assert latex_file_path.exists()
@pytest.mark.parametrize(
"theme_name",
dm.available_themes,
data.available_themes,
)
def test_copy_theme_files_to_output_directory(
run_a_function_and_check_if_output_is_the_same_as_reference, theme_name
@@ -458,7 +463,7 @@ def test_copy_theme_files_to_output_directory(
def copy_theme_files_to_output_directory(
output_directory_path, reference_file_or_directory_path
):
r.copy_theme_files_to_output_directory(theme_name, output_directory_path)
renderer.copy_theme_files_to_output_directory(theme_name, output_directory_path)
assert run_a_function_and_check_if_output_is_the_same_as_reference(
copy_theme_files_to_output_directory,
@@ -481,7 +486,7 @@ def test_copy_theme_files_to_output_directory_custom_theme(
dummytheme_path.mkdir(parents=True, exist_ok=True)
# create a txt file called test.txt in the custom theme directory:
for entry_type_name in dm.available_entry_types:
for entry_type_name in data.available_entry_types:
pathlib.Path(dummytheme_path / f"{entry_type_name}.j2.tex").touch()
pathlib.Path(dummytheme_path / "Header.j2.tex").touch()
@@ -504,7 +509,7 @@ def test_copy_theme_files_to_output_directory_custom_theme(
# create reference_directory_path:
os.chdir(dummytheme_path.parent)
r.copy_theme_files_to_output_directory(
renderer.copy_theme_files_to_output_directory(
theme_name=theme_name,
output_directory_path=reference_directory_path,
)
@@ -516,7 +521,7 @@ def test_copy_theme_files_to_output_directory_custom_theme(
# copy the auxiliary theme files to tmp_path:
os.chdir(dummytheme_path.parent)
r.copy_theme_files_to_output_directory(
renderer.copy_theme_files_to_output_directory(
theme_name=theme_name,
output_directory_path=output_directory_path,
)
@@ -530,12 +535,14 @@ def test_copy_theme_files_to_output_directory_custom_theme(
def test_copy_theme_files_to_output_directory_nonexistent_theme():
with pytest.raises(FileNotFoundError):
r.copy_theme_files_to_output_directory("nonexistent_theme", pathlib.Path("."))
renderer.copy_theme_files_to_output_directory(
"nonexistent_theme", pathlib.Path(".")
)
@pytest.mark.parametrize(
"theme_name",
dm.available_themes,
data.available_themes,
)
@pytest.mark.parametrize(
"curriculum_vitae_data_model",
@@ -555,7 +562,7 @@ def test_render_a_latex_file_and_copy_theme_files(
f"{theme_name}_{folder_name_dictionary[curriculum_vitae_data_model]}"
)
data_model = dm.RenderCVDataModel(
data_model = data.RenderCVDataModel(
cv=request.getfixturevalue(curriculum_vitae_data_model),
design={"theme": theme_name},
)
@@ -563,7 +570,9 @@ def test_render_a_latex_file_and_copy_theme_files(
def render_a_latex_file_and_copy_theme_files(
output_directory_path, reference_file_or_directory_path
):
r.render_a_latex_file_and_copy_theme_files(data_model, output_directory_path)
renderer.render_a_latex_file_and_copy_theme_files(
data_model, output_directory_path
)
assert run_a_function_and_check_if_output_is_the_same_as_reference(
render_a_latex_file_and_copy_theme_files,
@@ -573,7 +582,7 @@ def test_render_a_latex_file_and_copy_theme_files(
@pytest.mark.parametrize(
"theme_name",
dm.available_themes,
data.available_themes,
)
@pytest.mark.parametrize(
"curriculum_vitae_data_model",
@@ -583,7 +592,7 @@ def test_render_a_latex_file_and_copy_theme_files(
],
)
@time_machine.travel("2024-01-01")
def test_render_pdf_from_latex(
def test_render_a_pdf_from_latex(
request: pytest.FixtureRequest,
run_a_function_and_check_if_output_is_the_same_as_reference,
theme_name,
@@ -609,7 +618,7 @@ def test_render_pdf_from_latex(
shutil.copytree(latex_sources_path, output_directory_path, dirs_exist_ok=True)
# convert the latex code to a pdf
r.render_pdf_from_latex(output_directory_path / f"{name}_CV.tex")
renderer.render_a_pdf_from_latex(output_directory_path / f"{name}_CV.tex")
assert run_a_function_and_check_if_output_is_the_same_as_reference(
function=generate_pdf_file,
@@ -621,12 +630,12 @@ def test_render_pdf_from_latex(
def test_render_pdf_from_latex_nonexistent_latex_file():
with pytest.raises(FileNotFoundError):
file_path = pathlib.Path("file_doesnt_exist.tex")
r.render_pdf_from_latex(file_path)
renderer.render_a_pdf_from_latex(file_path)
@pytest.mark.parametrize(
"theme_name",
dm.available_themes,
data.available_themes,
)
@pytest.mark.parametrize(
"curriculum_vitae_data_model",
@@ -636,7 +645,7 @@ def test_render_pdf_from_latex_nonexistent_latex_file():
],
)
@time_machine.travel("2024-01-01")
def test_render_html_from_markdown(
def test_render_an_html_from_markdown(
run_a_function_and_check_if_output_is_the_same_as_reference,
theme_name,
curriculum_vitae_data_model,
@@ -662,7 +671,7 @@ def test_render_html_from_markdown(
shutil.copy(markdown_source_path, output_directory_path)
# convert markdown to html
r.render_html_from_markdown(output_directory_path / markdown_file_name)
renderer.render_an_html_from_markdown(output_directory_path / markdown_file_name)
assert run_a_function_and_check_if_output_is_the_same_as_reference(
function=render_html_from_markdown,
@@ -674,10 +683,10 @@ def test_render_html_from_markdown(
def test_render_html_from_markdown_nonexistent_markdown_file():
with pytest.raises(FileNotFoundError):
file_path = pathlib.Path("file_doesnt_exist.md")
r.render_html_from_markdown(file_path)
renderer.render_an_html_from_markdown(file_path)
def test_render_a_markdown_file_single_page(
def test_render_pngs_from_pdf_single_page(
run_a_function_and_check_if_output_is_the_same_as_reference,
):
output_file_name = "classic_empty_1.png"
@@ -696,7 +705,7 @@ def test_render_a_markdown_file_single_page(
shutil.copy(pdf_path, output_directory_path)
# convert pdf to pngs
r.render_a_markdown_file(output_directory_path / pdf_file_name)
renderer.render_pngs_from_pdf(output_directory_path / pdf_file_name)
assert run_a_function_and_check_if_output_is_the_same_as_reference(
generate_pngs,
@@ -705,7 +714,7 @@ def test_render_a_markdown_file_single_page(
)
def test_render_a_markdown_file(
def test_render_pngs_from_pdf(
run_a_function_and_check_if_output_is_the_same_as_reference,
):
reference_directory_name = "pngs"
@@ -723,7 +732,7 @@ def test_render_a_markdown_file(
shutil.copy(pdf_path, output_directory_path)
# convert pdf to pngs
r.render_a_markdown_file(output_directory_path / pdf_file_name)
renderer.render_pngs_from_pdf(output_directory_path / pdf_file_name)
# remove the pdf file
(output_directory_path / pdf_file_name).unlink()
@@ -734,7 +743,7 @@ def test_render_a_markdown_file(
)
def test_pdf_to_png_nonexistent_pdf_file():
def test_render_pngs_from_pdf_nonexistent_pdf_file():
with pytest.raises(FileNotFoundError):
file_path = pathlib.Path("file_doesnt_exist.pdf")
r.render_a_markdown_file(file_path)
renderer.render_pngs_from_pdf(file_path)