tests: improve tests

This commit is contained in:
Sina Atalay 2024-04-30 20:52:33 +03:00
parent e6d51cca84
commit f23887323f
2 changed files with 40 additions and 2 deletions

View File

@ -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)

View File

@ -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