Commit f1e2602d authored by Martin Schorb's avatar Martin Schorb
Browse files

test args2string

parent a7631b64
......@@ -20,7 +20,11 @@ import requests
def args2string(args, separator='='):
"""
Converts arguments as list or dict into a tring to be issued on CLI
Converts arguments as list or dict into a string to be issued on CLI.
If a keyword argument contains a list, it will be issued multiple times.
{'arg: [1,2,3]} -> ' arg=1 arg=2 arg=3 '
This is according to what some Render CL scripts expect when defining
multiple input files.
:param args: list, dict or str of command line arguments
:param str separator: char to separate/link arguments
......@@ -31,12 +35,12 @@ def args2string(args, separator='='):
if args is None:
argstring = ''
elif type(args) == list:
argstring = " ".join(map(str, args))
argstring = ' ' + " ".join(map(str, args))
elif type(args) == dict:
argstring = str()
for item in args.items():
if type(item[1]) is list:
argstring += ' ' + ' '.join([str(item[0]) + separator + currit for currit in item[1]])
argstring += ' ' + ' '.join([str(item[0]) + separator + str(currit) for currit in item[1]])
else:
argstring += ' ' + separator.join(map(str, item))
elif type(args) == str:
......
#!/usr/bin/env python
'''
tests for functionality in dashUI.utils.launch_jobs
'''
import os
import pytest
from dashUI.utils.launch_jobs import *
# test conversion of argstrings
def test_args2string():
# test Type Error
with pytest.raises(TypeError):
# number
args2string(5)
# module
args2string(os)
inlist = [1, 'a', 'f']
expectedargs = ' 1 a f '
assert args2string(inlist) == expectedargs
indict = {'arg1': 5, 'arg2': 'content', 'arg3': [1, 2, 3]}
expectedargs = ' arg1=5 arg2=content arg3=1 arg3=2 arg3=3 '
assert args2string(indict) == expectedargs
#!/usr/bin/env python
'''
'''
import os
import pytest
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment