From 118e6f70d9957f18a4a1578f673d4e816796d527 Mon Sep 17 00:00:00 2001 From: Thomas Ubensee <34603111+tomuben@users.noreply.github.com> Date: Fri, 30 Aug 2024 18:43:48 -0300 Subject: [PATCH] Fixes from review --- .../lib/tasks/upload/language_def_parser.py | 15 ++++++++++----- test/unit/test_language_def_parser.py | 16 ++++++++++++---- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/exasol_script_languages_container_tool/lib/tasks/upload/language_def_parser.py b/exasol_script_languages_container_tool/lib/tasks/upload/language_def_parser.py index dba1831..295114e 100644 --- a/exasol_script_languages_container_tool/lib/tasks/upload/language_def_parser.py +++ b/exasol_script_languages_container_tool/lib/tasks/upload/language_def_parser.py @@ -14,11 +14,16 @@ def _parse_builtin_language_definition(url: str) -> BuiltInLanguageDefinitionURL: - lang = url.replace("builtin_", "") - for slc_builtin_language in SLCLanguage: - if slc_builtin_language.name.lower() == lang.lower(): - return BuiltInLanguageDefinitionURL(language=slc_builtin_language) - raise ValueError(f"Unknown builtin language: {url}") + language = url.replace("builtin_", "") + try: + slc_language = next( + slc_language_enum + for slc_language_enum in SLCLanguage + if slc_language_enum.name.lower() == language.lower() + ) + except StopIteration: + raise ValueError(f"Unknown builtin language: {url}") + return BuiltInLanguageDefinitionURL(language=slc_language) def _build_udf_client_abs_path_from_fragments( diff --git a/test/unit/test_language_def_parser.py b/test/unit/test_language_def_parser.py index 629b1cf..fb42fd9 100644 --- a/test/unit/test_language_def_parser.py +++ b/test/unit/test_language_def_parser.py @@ -25,7 +25,7 @@ ), ), ( - "/defaultbfs/default", + "/defaultbfs/default/", ChrootPath( bucketfs_name="defaultbfs", bucket_name="default", path_in_bucket=None ), @@ -89,9 +89,13 @@ def test_lang_def_parser( param, expected_param, ): - lang_def = ( - f"PYTHON3_TEST=localzmq+protobuf://{chroot_path}{param}#{udf_client_path}" - ) + if udf_client_path: + lang_def = ( + f"PYTHON3_TEST=localzmq+protobuf://{chroot_path}{param}#{udf_client_path}" + ) + else: + lang_def = f"PYTHON3_TEST=localzmq+protobuf://{chroot_path}{param}" + alias, result = parse_language_definition(lang_def) assert alias == "PYTHON3_TEST" assert isinstance(result, LanguageDefinitionURL) @@ -99,6 +103,8 @@ def test_lang_def_parser( assert result.udf_client_path == expected_udf_client_path assert result.parameters == expected_param + assert f"{alias}={result}" == lang_def + BUILTIN_LANGUAGES = [ ("builtin_java", BuiltInLanguageDefinitionURL(language=SLCLanguage.Java)), @@ -118,6 +124,8 @@ def test_lang_def_parser_builtin( assert isinstance(result, BuiltInLanguageDefinitionURL) assert result == expected + assert f"{alias}={result}" == lang_def + def test_lang_def_parser_invalid_builtin(): lang_def = f"PYTHON3_TEST=builtin_rust"