3
0
Fork 0

fix: add make_full_name() function, app handler method

This commit is contained in:
Lance Edgar 2025-01-06 16:36:27 -06:00
parent b3ec7cb9b8
commit 60a25ab342
4 changed files with 41 additions and 1 deletions

View file

@ -33,7 +33,7 @@ import warnings
import humanize
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)
@ -495,6 +495,15 @@ class AppHandler:
"""
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):
"""
Generate a new UUID value.

View file

@ -171,6 +171,26 @@ def make_title(text):
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():
"""
Generate a new v7 UUID value.

View file

@ -384,6 +384,10 @@ app_title = WuttaTest
text = self.app.make_title('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):
uuid = self.app.make_uuid()
self.assertEqual(len(uuid), 32)

View file

@ -263,6 +263,13 @@ class TestMakeTitle(TestCase):
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):
def test_basic(self):