From 2b4059855ab4ceae54032bff55da0a6622f1ff01 Mon Sep 17 00:00:00 2001 From: jpic Date: Tue, 29 Jan 2019 15:05:49 +0100 Subject: [PATCH] Add strutils.assemble --- boltons/strutils.py | 19 ++++++++++++++++--- tests/test_strutils.py | 4 ++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/boltons/strutils.py b/boltons/strutils.py index a5baadac..956e62c7 100644 --- a/boltons/strutils.py +++ b/boltons/strutils.py @@ -28,9 +28,9 @@ __all__ = ['camel2under', 'under2camel', 'slugify', 'split_punct_ws', 'unit_len', 'ordinalize', 'cardinalize', 'pluralize', 'singularize', - 'asciify', 'is_ascii', 'is_uuid', 'html2text', 'strip_ansi', - 'bytes2human', 'find_hashtags', 'a10n', 'gunzip_bytes', - 'iter_splitlines', 'indent', 'escape_shell_args', + 'asciify', 'implode', 'is_ascii', 'is_uuid', 'html2text', + 'strip_ansi', 'bytes2human', 'find_hashtags', 'a10n', + 'gunzip_bytes', 'iter_splitlines', 'indent', 'escape_shell_args', 'args2cmd', 'args2sh', 'parse_int_list', 'format_int_list'] @@ -427,6 +427,19 @@ def asciify(text, ignore=False): return ret +def assemble(delimiter, *args): + """Perform a join on args casted to strings. + + Args: + delimiter (str or unicode): The string to use as delimiter between args + args: The + + >>> assemble('-', 1, 'b') == '1-b' + True + """ + return delimiter.join(map(str, args)) + + def is_ascii(text): """Check if a unicode or bytestring, *text*, is composed of ascii characters only. Raises :exc:`ValueError` if argument is not text. diff --git a/tests/test_strutils.py b/tests/test_strutils.py index 4dab6d0d..03ff9215 100644 --- a/tests/test_strutils.py +++ b/tests/test_strutils.py @@ -20,6 +20,10 @@ def test_indent(): assert strutils.indent(to_indent, ' ') == ref +def test_assemble(): + assert strutils.assemble('-', 1, 'b') == '1-b' + + def test_is_uuid(): assert strutils.is_uuid(uuid.uuid4()) == True assert strutils.is_uuid(uuid.uuid4(), version=1) == False