Skip to content

Commit

Permalink
better underscore to readable
Browse files Browse the repository at this point in the history
  • Loading branch information
joamag committed Jul 19, 2018
1 parent 94d2115 commit c139326
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/quorum/test/util.py
Expand Up @@ -352,6 +352,30 @@ def test_underscore_to_readable(self):
self.assertEqual(type(result), str)
self.assertEqual(result, "Hello World Hello World")

result = quorum.underscore_to_readable("hello_world_")
self.assertEqual(type(result), str)
self.assertEqual(result, "Hello world")

result = quorum.underscore_to_readable("hello_world_", capitalize = True)
self.assertEqual(type(result), str)
self.assertEqual(result, "Hello World")

result = quorum.underscore_to_readable("__hello_world__")
self.assertEqual(type(result), str)
self.assertEqual(result, "Hello world")

result = quorum.underscore_to_readable("__hello_world__", capitalize = True)
self.assertEqual(type(result), str)
self.assertEqual(result, "Hello World")

result = quorum.underscore_to_readable("__hello___world__")
self.assertEqual(type(result), str)
self.assertEqual(result, "Hello world")

result = quorum.underscore_to_readable("__hello___world__", capitalize = True)
self.assertEqual(type(result), str)
self.assertEqual(result, "Hello World")

@quorum.secured
def test_generate_identifier(self):
identifier = quorum.generate_identifier(
Expand Down
1 change: 1 addition & 0 deletions src/quorum/util.py
Expand Up @@ -858,6 +858,7 @@ def underscore_to_readable(underscore, capitalize = False):
"""

parts = underscore.split("_")
parts = [part for part in parts if part]
if capitalize: parts = [part[0].upper() + part[1:] for part in parts]
else: parts[0] = parts[0][0].upper() + parts[0][1:]
return " ".join(parts)
Expand Down

0 comments on commit c139326

Please sign in to comment.