From c239b0002e4c60282a7d90ea40ce06fb4ea90b66 Mon Sep 17 00:00:00 2001 From: Sina Atalay Date: Fri, 19 Jul 2024 17:40:52 +0300 Subject: [PATCH] data: allow custom theme names with digits (#127) --- rendercv/data/models/design.py | 6 ++--- tests/test_cli.py | 43 ++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/rendercv/data/models/design.py b/rendercv/data/models/design.py index 454b3f37..c513fe0d 100644 --- a/rendercv/data/models/design.py +++ b/rendercv/data/models/design.py @@ -57,10 +57,10 @@ def validate_design_options( # It is a custom theme. Validate it: theme_name: str = str(design["theme"]) - # Check if the theme name is valid: - if not theme_name.isalpha(): + # Custom theme should only contain letters and digits: + if not theme_name.isalnum(): raise ValueError( - "The custom theme name should contain only letters.", + "The custom theme name should only contain letters and digits.", "theme", # this is the location of the error theme_name, # this is value of the error ) diff --git a/tests/test_cli.py b/tests/test_cli.py index ead9f370..9079ac8a 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -563,6 +563,49 @@ def test_new_command_with_existing_files(tmp_path, file_or_folder_name): assert "already exists!" in result.stdout +@pytest.mark.parametrize( + "custom_theme_name", + [ + "CustomTheme", + "CustomTheme123", + "MYCUSTOMTHEME", + "mycustomtheme", + ], +) +def test_custom_theme_names(tmp_path, input_file_path, custom_theme_name): + # change the current working directory to the temporary directory: + os.chdir(tmp_path) + + result = runner.invoke(cli.app, ["create-theme", custom_theme_name]) + + new_theme_source_files_path = tmp_path / custom_theme_name + + assert new_theme_source_files_path.exists() + assert (new_theme_source_files_path / "__init__.py").exists() + + # test if the new theme is actually working: + input_file_path = shutil.copy(input_file_path, tmp_path) + + result = runner.invoke( + cli.app, ["render", str(input_file_path), "--design.theme", custom_theme_name] + ) + + output_folder_path = tmp_path / "rendercv_output" + pdf_file_path = output_folder_path / "John_Doe_CV.pdf" + latex_file_path = output_folder_path / "John_Doe_CV.tex" + markdown_file_path = output_folder_path / "John_Doe_CV.md" + html_file_path = output_folder_path / "John_Doe_CV.html" + png_file_path = output_folder_path / "John_Doe_CV_1.png" + + assert output_folder_path.exists() + assert pdf_file_path.exists() + assert latex_file_path.exists() + assert markdown_file_path.exists() + assert html_file_path.exists() + assert png_file_path.exists() + assert "Your CV is rendered!" in result.stdout + + @pytest.mark.parametrize( "based_on", data.available_themes,