fix: add make_full_name()
function, app handler method
This commit is contained in:
parent
b3ec7cb9b8
commit
60a25ab342
|
@ -33,7 +33,7 @@ import warnings
|
||||||
import humanize
|
import humanize
|
||||||
|
|
||||||
from wuttjamaican.util import (load_entry_points, load_object,
|
from wuttjamaican.util import (load_entry_points, load_object,
|
||||||
make_title, make_uuid, make_true_uuid,
|
make_title, make_full_name, make_uuid, make_true_uuid,
|
||||||
progress_loop, resource_path, simple_error)
|
progress_loop, resource_path, simple_error)
|
||||||
|
|
||||||
|
|
||||||
|
@ -495,6 +495,15 @@ class AppHandler:
|
||||||
"""
|
"""
|
||||||
return make_title(text)
|
return make_title(text)
|
||||||
|
|
||||||
|
def make_full_name(self, *parts):
|
||||||
|
"""
|
||||||
|
Make a "full name" from the given parts.
|
||||||
|
|
||||||
|
This is a convenience wrapper around
|
||||||
|
:func:`~wuttjamaican.util.make_full_name()`.
|
||||||
|
"""
|
||||||
|
return make_full_name(*parts)
|
||||||
|
|
||||||
def make_true_uuid(self):
|
def make_true_uuid(self):
|
||||||
"""
|
"""
|
||||||
Generate a new UUID value.
|
Generate a new UUID value.
|
||||||
|
|
|
@ -171,6 +171,26 @@ def make_title(text):
|
||||||
return ' '.join([x.capitalize() for x in words])
|
return ' '.join([x.capitalize() for x in words])
|
||||||
|
|
||||||
|
|
||||||
|
def make_full_name(*parts):
|
||||||
|
"""
|
||||||
|
Make a "full name" from the given parts.
|
||||||
|
|
||||||
|
:param \*parts: Distinct name values which should be joined
|
||||||
|
together to make the full name.
|
||||||
|
|
||||||
|
:returns: The full name.
|
||||||
|
|
||||||
|
For instance::
|
||||||
|
|
||||||
|
make_full_name('First', '', 'Last', 'Suffix')
|
||||||
|
# => "First Last Suffix"
|
||||||
|
"""
|
||||||
|
parts = [(part or '').strip()
|
||||||
|
for part in parts]
|
||||||
|
parts = [part for part in parts if part]
|
||||||
|
return ' '.join(parts)
|
||||||
|
|
||||||
|
|
||||||
def make_true_uuid():
|
def make_true_uuid():
|
||||||
"""
|
"""
|
||||||
Generate a new v7 UUID value.
|
Generate a new v7 UUID value.
|
||||||
|
|
|
@ -384,6 +384,10 @@ app_title = WuttaTest
|
||||||
text = self.app.make_title('foo_bar')
|
text = self.app.make_title('foo_bar')
|
||||||
self.assertEqual(text, "Foo Bar")
|
self.assertEqual(text, "Foo Bar")
|
||||||
|
|
||||||
|
def test_make_full_name(self):
|
||||||
|
name = self.app.make_full_name('Fred', '', 'Flintstone', '')
|
||||||
|
self.assertEqual(name, "Fred Flintstone")
|
||||||
|
|
||||||
def test_make_uuid(self):
|
def test_make_uuid(self):
|
||||||
uuid = self.app.make_uuid()
|
uuid = self.app.make_uuid()
|
||||||
self.assertEqual(len(uuid), 32)
|
self.assertEqual(len(uuid), 32)
|
||||||
|
|
|
@ -263,6 +263,13 @@ class TestMakeTitle(TestCase):
|
||||||
self.assertEqual(text, "Foo Bar")
|
self.assertEqual(text, "Foo Bar")
|
||||||
|
|
||||||
|
|
||||||
|
class TestMakeFullName(TestCase):
|
||||||
|
|
||||||
|
def test_basic(self):
|
||||||
|
name = mod.make_full_name('Fred', '', 'Flintstone', '')
|
||||||
|
self.assertEqual(name, 'Fred Flintstone')
|
||||||
|
|
||||||
|
|
||||||
class TestProgressLoop(TestCase):
|
class TestProgressLoop(TestCase):
|
||||||
|
|
||||||
def test_basic(self):
|
def test_basic(self):
|
||||||
|
|
Loading…
Reference in a new issue