Skip to content

Commit

Permalink
fix: account for strs that start with [ but are not json
Browse files Browse the repository at this point in the history
  • Loading branch information
MDavidson17 committed Jul 6, 2022
1 parent f7c02d7 commit eca71e4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
11 changes: 8 additions & 3 deletions scripts/format_source.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import json
from typing import List, cast

from linz_logger import get_log


def format_source(source: List[str]) -> List[str]:
"""Due to Argo constraints if using the basemaps cli the source has a string that contains a list that needs to be split.
example: ["[\"s3://test/image_one.tiff, \"s3://test/image_two.tiff\"]"]
"""Due to Argo constraints if using the basemaps cli list command the source has a string that contains a list that needs to be split.
example: ["[\"s3://test/image_one.tiff\", \"s3://test/image_two.tiff\"]"]
"""
if len(source) == 1 and source[0].startswith("["):
return cast(List[str], json.loads(source[0]))
try:
return cast(List[str], json.loads(source[0]))
except ValueError as e:
get_log().debug("Decoding Json Failed", source=source, msg=e)
return source
9 changes: 9 additions & 0 deletions scripts/tests/format_source_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import linz_logger
from format_source import format_source


Expand Down Expand Up @@ -30,3 +31,11 @@ def test_format_source_multiple_inputs() -> None:
assert isinstance(file_list, list)
assert len(file_list) == 2
assert file_list == ["s3://test/image_one.tiff", "s3://test/image_two.tiff"]

def test_format_source_json_loading_error() -> None:
"""example: --source [s3://test/image_one.tiff"""
source = ["[s3://test/image_one.tiff"]
file_list = format_source(source)
assert isinstance(file_list, list)
assert len(file_list) == 1
assert file_list == ["[s3://test/image_one.tiff"]

0 comments on commit eca71e4

Please sign in to comment.