Added unittests for utils.py dedent() and list_to_string(). Adjusted list_to_string to correctly handle no endsep.

This commit is contained in:
asechrest 2014-05-06 12:34:08 -04:00
parent 12c2402dac
commit 11ea572f00
2 changed files with 35 additions and 6 deletions

View file

@ -110,16 +110,20 @@ def list_to_string(inlist, endsep="and", addquote=False):
with addquote and endsep
[1,2,3] -> '"1", "2" and "3"'
"""
if not endsep:
endsep = ","
else:
endsep = " " + endsep
if not inlist:
return ""
if addquote:
if len(inlist) == 1:
return "\"%s\"" % inlist[0]
return ", ".join("\"%s\"" % v for v in inlist[:-1]) + " %s %s" % (endsep, "\"%s\"" % inlist[-1])
return ", ".join("\"%s\"" % v for v in inlist[:-1]) + "%s %s" % (endsep, "\"%s\"" % inlist[-1])
else:
if len(inlist) == 1:
return str(inlist[0])
return ", ".join(str(v) for v in inlist[:-1]) + " %s %s" % (endsep, inlist[-1])
return ", ".join(str(v) for v in inlist[:-1]) + "%s %s" % (endsep, inlist[-1])
def wildcard_to_regexp(instring):