tests: add new tests

This commit is contained in:
Sina Atalay 2024-05-19 13:55:01 +03:00
parent 24170eb034
commit debce0551c
2 changed files with 63 additions and 6 deletions

View File

@ -1,12 +1,14 @@
import os import os
import shutil import shutil
import subprocess
import sys
from datetime import date as Date
import pydantic import pydantic
import ruamel.yaml import ruamel.yaml
import pytest import pytest
import typer.testing import typer.testing
import rendercv.cli as cli import rendercv.cli as cli
import rendercv.data_models as dm import rendercv.data_models as dm
@ -83,6 +85,12 @@ def test_get_error_message_and_location_and_value_from_a_custom_error():
"position": "Researcher", "position": "Researcher",
}, },
), ),
(
dm.ExperienceEntry,
{
"position": Date(2020, 10, 1),
},
),
( (
dm.ExperienceEntry, dm.ExperienceEntry,
{ {
@ -475,3 +483,7 @@ def test_create_theme_command_theme_already_exists(tmp_path):
result = runner.invoke(cli.app, ["create-theme", "newtheme"]) result = runner.invoke(cli.app, ["create-theme", "newtheme"])
assert "already exists!" in result.stdout assert "already exists!" in result.stdout
def test_main_file():
subprocess.run([sys.executable, "-m", "rendercv", "--help"], check=True)

View File

@ -1,7 +1,7 @@
from datetime import date as Date from datetime import date as Date
import json import json
import pathlib
import os import os
import io
import re import re
import shutil import shutil
@ -140,10 +140,27 @@ def test_read_input_file(input_file_path):
assert isinstance(data_model, dm.RenderCVDataModel) assert isinstance(data_model, dm.RenderCVDataModel)
def test_read_input_file_not_found(): def test_read_input_file_directly_with_contents(input_file_path):
with pytest.raises(FileNotFoundError): input_dictionary = {
invalid_path = pathlib.Path("doesntexist.yaml") "cv": {
dm.read_input_file(invalid_path) "name": "John Doe",
},
"design": {
"theme": "classic",
},
}
# dump the dictionary to a yaml file
yaml_object = ruamel.yaml.YAML()
yaml_object.width = 60
yaml_object.indent(mapping=2, sequence=4, offset=2)
with io.StringIO() as string_stream:
yaml_object.dump(input_dictionary, string_stream)
yaml_string = string_stream.getvalue()
data_model = dm.read_input_file(yaml_string)
assert isinstance(data_model, dm.RenderCVDataModel)
def test_read_input_file_invalid_file(tmp_path): def test_read_input_file_invalid_file(tmp_path):
@ -611,3 +628,31 @@ def test_custom_theme_with_broken_init_file(tmp_path, testdata_directory_path):
"design": {"theme": "dummytheme"}, "design": {"theme": "dummytheme"},
} }
) )
def test_locale_catalog():
data_model = dm.get_a_sample_data_model("John Doe")
data_model.locale_catalog = dm.LocaleCatalog(
month="a",
months="b",
year="c",
years="d",
present="e",
to="f",
abbreviations_for_months=[
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"11",
"12",
],
)
assert dm.locale_catalog == data_model.locale_catalog.model_dump()