Skip to content

Commit

Permalink
Bug fix thanks to @willmayfield! Check both starting/ending
Browse files Browse the repository at this point in the history
characters are brackets for shell variable to be considered an array.
  • Loading branch information
danielabdi-noaa committed Apr 20, 2022
1 parent 17d138e commit 35dc552
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ush/python_utils/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def str_to_list(v):
v = v.strip()
if not v:
return None
if v[0] == '(':
if v[0] == '(' and v[-1] == ')':
v = v[1:-1]
tokens = shlex.split(v)
lst = []
Expand Down
8 changes: 8 additions & 0 deletions ush/python_utils/test_python_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ def test_import_vars(self):
dictionary = { "Hello": "World!" }
import_vars(dictionary=dictionary)
self.assertEqual( Hello, "World!" )
#test array
shell_str='("1" "2") \n'
v = str_to_list(shell_str)
self.assertTrue( isinstance(v,list) )
self.assertEqual(v, [1, 2])
shell_str = '( "1" "2" \n'
v = str_to_list(shell_str)
self.assertFalse( isinstance(v,list) )
def test_config_parser(self):
cfg = { "HRS": [ "1", "2" ] }
shell_str = cfg_to_shell_str(cfg)
Expand Down

0 comments on commit 35dc552

Please sign in to comment.