fix: add AppHandler.make_title()
convenience method
This commit is contained in:
parent
27b859c1c7
commit
739dd285aa
|
@ -28,7 +28,7 @@ import importlib
|
||||||
import os
|
import os
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
from wuttjamaican.util import load_entry_points, load_object, make_uuid, parse_bool
|
from wuttjamaican.util import load_entry_points, load_object, make_title, make_uuid, parse_bool
|
||||||
|
|
||||||
|
|
||||||
class AppHandler:
|
class AppHandler:
|
||||||
|
@ -232,6 +232,20 @@ class AppHandler:
|
||||||
|
|
||||||
return Session(**kwargs)
|
return Session(**kwargs)
|
||||||
|
|
||||||
|
def make_title(self, text, **kwargs):
|
||||||
|
"""
|
||||||
|
Return a human-friendly "title" for the given text.
|
||||||
|
|
||||||
|
This is mostly useful for converting a Python variable name (or
|
||||||
|
similar) to a human-friendly string, e.g.::
|
||||||
|
|
||||||
|
make_title('foo_bar') # => 'Foo Bar'
|
||||||
|
|
||||||
|
By default this just invokes
|
||||||
|
:func:`wuttjamaican.util.make_title()`.
|
||||||
|
"""
|
||||||
|
return make_title(text)
|
||||||
|
|
||||||
def make_uuid(self):
|
def make_uuid(self):
|
||||||
"""
|
"""
|
||||||
Generate a new UUID value.
|
Generate a new UUID value.
|
||||||
|
|
|
@ -114,6 +114,21 @@ def load_object(spec):
|
||||||
return getattr(module, name)
|
return getattr(module, name)
|
||||||
|
|
||||||
|
|
||||||
|
def make_title(text):
|
||||||
|
"""
|
||||||
|
Return a human-friendly "title" for the given text.
|
||||||
|
|
||||||
|
This is mostly useful for converting a Python variable name (or
|
||||||
|
similar) to a human-friendly string, e.g.::
|
||||||
|
|
||||||
|
make_title('foo_bar') # => 'Foo Bar'
|
||||||
|
"""
|
||||||
|
text = text.replace('_', ' ')
|
||||||
|
text = text.replace('-', ' ')
|
||||||
|
words = text.split()
|
||||||
|
return ' '.join([x.capitalize() for x in words])
|
||||||
|
|
||||||
|
|
||||||
def make_uuid():
|
def make_uuid():
|
||||||
"""
|
"""
|
||||||
Generate a universally-unique identifier.
|
Generate a universally-unique identifier.
|
||||||
|
|
|
@ -116,6 +116,10 @@ class TestAppHandler(TestCase):
|
||||||
def test_get_title(self):
|
def test_get_title(self):
|
||||||
self.assertEqual(self.app.get_title(), 'WuttJamaican')
|
self.assertEqual(self.app.get_title(), 'WuttJamaican')
|
||||||
|
|
||||||
|
def test_make_title(self):
|
||||||
|
text = self.app.make_title('foo_bar')
|
||||||
|
self.assertEqual(text, "Foo Bar")
|
||||||
|
|
||||||
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)
|
||||||
|
|
|
@ -232,3 +232,10 @@ class TestParseList(TestCase):
|
||||||
self.assertEqual(value[0], 'foo')
|
self.assertEqual(value[0], 'foo')
|
||||||
self.assertEqual(value[1], 'C:\\some path\\with spaces\\and, a comma')
|
self.assertEqual(value[1], 'C:\\some path\\with spaces\\and, a comma')
|
||||||
self.assertEqual(value[2], 'baz')
|
self.assertEqual(value[2], 'baz')
|
||||||
|
|
||||||
|
|
||||||
|
class TestMakeTitle(TestCase):
|
||||||
|
|
||||||
|
def test_basic(self):
|
||||||
|
text = util.make_title('foo_bar')
|
||||||
|
self.assertEqual(text, "Foo Bar")
|
||||||
|
|
Loading…
Reference in a new issue