From f23887323f073acb60ee1279a12d76c563206d36 Mon Sep 17 00:00:00 2001 From: Sina Atalay Date: Tue, 30 Apr 2024 20:52:33 +0300 Subject: [PATCH] tests: improve tests --- tests/test_cli.py | 31 ++++++++++++++++++++++++++++++- tests/test_data_models.py | 11 ++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index a2c34ba..55c5e3d 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -139,7 +139,7 @@ def test_handle_exceptions(exception): @cli.handle_exceptions def function_that_raises_exception(): raise exception - + with pytest.raises(typer.Exit): function_that_raises_exception() @@ -421,6 +421,35 @@ def test_render_command_with_local_latex_command(tmp_path, input_file_path): ) +@pytest.mark.parametrize( + "invalid_arguments", + [ + ["--keywithoutvalue"], + ["--key", "value", "--keywithoutvalue"], + ["keywithoutdashes", "value"], + ["--cv.phone", "invalidphonenumber"], + ["--cv.sections.arbitrary.10", "value"], + ], +) +def test_render_command_with_invalid_arguments( + tmp_path, input_file_path, invalid_arguments +): + # copy input file to the temporary directory to create the output directory there: + input_file_path = shutil.copy(input_file_path, tmp_path) + + result = runner.invoke( + cli.app, + ["render", str(input_file_path)] + invalid_arguments, + ) + + assert ( + "There is a problem with the extra arguments!" in result.stdout + or "should start with double dashes!" in result.stdout + or "does not exist in the data model!" in result.stdout + or "There are some errors in the data model!" in result.stdout + ) + + def test_new_command(tmp_path): # change the current working directory to the temporary directory: os.chdir(tmp_path) diff --git a/tests/test_data_models.py b/tests/test_data_models.py index f8c8148..bddcacf 100644 --- a/tests/test_data_models.py +++ b/tests/test_data_models.py @@ -66,14 +66,23 @@ def test_format_date(date, expected_date_string): ("cv.phone", "+905555555555"), ("cv.email", "test@example.com"), ("cv.sections.education.0.degree", "PhD"), + ("cv.sections.education.0.highlights.1", "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\.([^\.]*?)\.(\d+)", 'sections_input["\\1"][\\2]', key) + 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