From debce0551c0aca3fa2fbcd08a283c53a1349869c Mon Sep 17 00:00:00 2001 From: Sina Atalay Date: Sun, 19 May 2024 13:55:01 +0300 Subject: [PATCH] tests: add new tests --- tests/test_cli.py | 14 +++++++++- tests/test_data_models.py | 55 +++++++++++++++++++++++++++++++++++---- 2 files changed, 63 insertions(+), 6 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index 7bef127..4e188fe 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1,12 +1,14 @@ import os import shutil +import subprocess +import sys +from datetime import date as Date import pydantic import ruamel.yaml import pytest import typer.testing - import rendercv.cli as cli 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", }, ), + ( + dm.ExperienceEntry, + { + "position": Date(2020, 10, 1), + }, + ), ( dm.ExperienceEntry, { @@ -475,3 +483,7 @@ def test_create_theme_command_theme_already_exists(tmp_path): result = runner.invoke(cli.app, ["create-theme", "newtheme"]) assert "already exists!" in result.stdout + + +def test_main_file(): + subprocess.run([sys.executable, "-m", "rendercv", "--help"], check=True) diff --git a/tests/test_data_models.py b/tests/test_data_models.py index f373d14..077f4a8 100644 --- a/tests/test_data_models.py +++ b/tests/test_data_models.py @@ -1,7 +1,7 @@ from datetime import date as Date import json -import pathlib import os +import io import re import shutil @@ -140,10 +140,27 @@ def test_read_input_file(input_file_path): assert isinstance(data_model, dm.RenderCVDataModel) -def test_read_input_file_not_found(): - with pytest.raises(FileNotFoundError): - invalid_path = pathlib.Path("doesntexist.yaml") - dm.read_input_file(invalid_path) +def test_read_input_file_directly_with_contents(input_file_path): + input_dictionary = { + "cv": { + "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): @@ -611,3 +628,31 @@ def test_custom_theme_with_broken_init_file(tmp_path, testdata_directory_path): "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()