Skip to content

Commit

Permalink
Fixes from review
Browse files Browse the repository at this point in the history
  • Loading branch information
tomuben committed Aug 30, 2024
1 parent ed98132 commit 118e6f7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
16 changes: 12 additions & 4 deletions test/unit/test_language_def_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
),
),
(
"/defaultbfs/default",
"/defaultbfs/default/",
ChrootPath(
bucketfs_name="defaultbfs", bucket_name="default", path_in_bucket=None
),
Expand Down Expand Up @@ -89,16 +89,22 @@ 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)
assert result.chroot_path == expected_chroot_path
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)),
Expand All @@ -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"
Expand Down

0 comments on commit 118e6f7

Please sign in to comment.