From 7c6856a7e14779bff453d3b702930b9c4c980065 Mon Sep 17 00:00:00 2001 From: Sina Atalay Date: Sat, 1 Jun 2024 15:56:48 +0300 Subject: [PATCH] tests: increase coverage --- pyproject.toml | 2 +- tests/test_cli.py | 22 ++++++++++++++++++++++ tests/test_data_models.py | 21 ++++++++++++++++++++- 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index a39304b..1ff6cfa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -141,4 +141,4 @@ source = ['rendercv'] relative_files = true # don't include jinja templates in the coverage report: -omit = ["*.j2.*"] +omit = ["*.j2.*", "rendercv/__main__.py"] diff --git a/tests/test_cli.py b/tests/test_cli.py index d02f1f2..ee3ea55 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -41,6 +41,11 @@ def test_error(): cli.error("This is an error message.") +def test_error_without_text(): + with pytest.raises(typer.Exit): + cli.error() + + def test_information(): cli.information("This is an information message.") @@ -102,6 +107,14 @@ def test_get_error_message_and_location_and_value_from_a_custom_error(): "end_date": "INVALID END DATE", }, ), + ( + dm.ExperienceEntry, + { + "company": "CERN", + "position": "Researcher", + "highlights": "This is not a list.", + }, + ), ( dm.PublicationEntry, { @@ -139,6 +152,15 @@ def test_get_error_message_and_location_and_value_from_a_custom_error(): }, }, ), + ( + dm.RenderCVDataModel, + { + "cv": { + "name": "John Doe", + }, + "design": {"theme": "UPPERCASE"}, + }, + ), ], ) def test_handle_validation_error(data_model_class, invalid_model): diff --git a/tests/test_data_models.py b/tests/test_data_models.py index 0ecb548..30f36ad 100644 --- a/tests/test_data_models.py +++ b/tests/test_data_models.py @@ -170,6 +170,12 @@ def test_read_input_file_invalid_file(tmp_path): dm.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) + + @pytest.mark.parametrize( "theme", dm.available_themes, @@ -645,7 +651,7 @@ def test_custom_theme_with_broken_init_file(tmp_path, testdata_directory_path): custom_theme_path = tmp_path / "dummytheme" shutil.copytree(reference_custom_theme_path, custom_theme_path, dirs_exist_ok=True) - # remove the __init__.py file: + # overwrite the __init__.py file (syntax error) init_file = custom_theme_path / "__init__.py" init_file.write_text("invalid python code", encoding="utf-8") @@ -658,6 +664,19 @@ def test_custom_theme_with_broken_init_file(tmp_path, testdata_directory_path): } ) + # overwrite the __init__.py file (import error) + init_file = custom_theme_path / "__init__.py" + init_file.write_text("from ... import test", encoding="utf-8") + + os.chdir(tmp_path) + with pytest.raises(pydantic.ValidationError): + dm.RenderCVDataModel( + **{ # type: ignore + "cv": {"name": "John Doe"}, + "design": {"theme": "dummytheme"}, + } + ) + def test_locale_catalog(): data_model = dm.get_a_sample_data_model("John Doe")