stringify, and such

This commit is contained in:
Tyrel Souza 2014-10-30 14:30:22 -04:00
parent 15b0977ab6
commit 53b081bc75
4 changed files with 16 additions and 7 deletions

View File

@ -7,6 +7,9 @@ any number of things together
>>> print glue("any","number","of","things","together",where="anywhere") >>> print glue("any","number","of","things","together",where="anywhere")
any number of things together anywhere any number of things together anywhere
>>> print glue("any","number","of","things","together", "even",["nested","lists"]])
any number of things together even nested lists
``` ```
#Protip #Protip
@ -17,8 +20,8 @@ You should probably just use [str.join](https://docs.python.org/2/library/stdtyp
``` ```
Name Stmts Miss Cover Missing Name Stmts Miss Cover Missing
------------------------------------- -------------------------------------
glue 13 0 100% glue 14 0 100%
tests 20 0 100% tests 24 0 100%
------------------------------------- -------------------------------------
TOTAL 33 0 100% TOTAL 38 0 100%
``` ```

View File

@ -1,6 +1,6 @@
Name Stmts Miss Cover Missing Name Stmts Miss Cover Missing
------------------------------------- -------------------------------------
glue 13 0 100% glue 14 0 100%
tests 20 0 100% tests 24 0 100%
------------------------------------- -------------------------------------
TOTAL 33 0 100% TOTAL 38 0 100%

View File

@ -12,4 +12,5 @@ def glue(*args, **kwargs):
kwargs = collections.OrderedDict(sorted(kwargs.items(), key=lambda t: t[0])) # I dont care what order you submit them in, they will be alphabetical kwargs = collections.OrderedDict(sorted(kwargs.items(), key=lambda t: t[0])) # I dont care what order you submit them in, they will be alphabetical
what_to_glue.extend([v for k,v in kwargs.iteritems()]) # Ignore all your keys, because you're doing this wrong anyway what_to_glue.extend([v for k,v in kwargs.iteritems()]) # Ignore all your keys, because you're doing this wrong anyway
what_to_glue = flatten(what_to_glue) what_to_glue = flatten(what_to_glue)
what_to_glue = [str(x) for x in what_to_glue]
return " ".join(what_to_glue) return " ".join(what_to_glue)

View File

@ -15,7 +15,6 @@ class GlueTests(unittest.TestCase):
def test_named(self): def test_named(self):
output = glue(what="bozo", who="clown") output = glue(what="bozo", who="clown")
print output
assert output == "bozo clown" assert output == "bozo clown"
assert "what" not in output assert "what" not in output
@ -23,5 +22,11 @@ class GlueTests(unittest.TestCase):
output = glue("why", ["would", ["you", "run"], "these"], "tests") output = glue("why", ["would", ["you", "run"], "these"], "tests")
assert output == "why would you run these tests" assert output == "why would you run these tests"
def test_objects(self):
output = glue("why", ["would", ["you", "run"], "these"], "tests", 12345)
assert output == "why would you run these tests 12345"
output = glue("why", ["would", ["you", "run"], "these"], "tests", False)
assert output == "why would you run these tests False"
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()