mirror of
https://github.com/datafolklabs/cement.git
synced 2026-02-06 14:16:46 +00:00
Resolved Issue 196
This commit is contained in:
parent
c57c13946b
commit
520d3c5981
@ -25,7 +25,7 @@ Bugs:
|
||||
|
||||
Features:
|
||||
|
||||
* None
|
||||
* :issue:`196` - Added utils.misc.wrap
|
||||
|
||||
|
||||
2.1.2 - Thu Nov 1st, 2012 (DEVELOPMENT)
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
import sys
|
||||
import logging
|
||||
from textwrap import TextWrapper
|
||||
|
||||
|
||||
def init_defaults(*sections):
|
||||
@ -86,3 +87,20 @@ def is_true(item):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def wrap(text, width=77, indent=''):
|
||||
"""
|
||||
Wrap text for cleaner output (this is a simple wrapper around
|
||||
`textwrap.TextWrapper` in the standard library).
|
||||
|
||||
:param text: The text to wrap
|
||||
:param width: The max width of a line before breaking
|
||||
:param indent: String to prefix subsequent lines after breaking
|
||||
:returns: str(text)
|
||||
|
||||
"""
|
||||
wrapper = TextWrapper(subsequent_indent=indent, width=width,
|
||||
break_long_words=False,
|
||||
break_on_hyphens=False)
|
||||
return wrapper.fill(text)
|
||||
|
||||
@ -19,3 +19,14 @@ class BackendTestCase(test.CementTestCase):
|
||||
# set logging back to non-debug
|
||||
misc.minimal_logger(__name__, debug=False)
|
||||
pass
|
||||
|
||||
def test_wrap(self):
|
||||
text = "aaaaa bbbbb ccccc"
|
||||
new_text = misc.wrap(text, width=5)
|
||||
parts = new_text.split('\n')
|
||||
self.eq(len(parts), 3)
|
||||
self.eq(parts[1], 'bbbbb')
|
||||
|
||||
new_text = misc.wrap(text, width=5, indent='***')
|
||||
parts = new_text.split('\n')
|
||||
self.eq(parts[2], '***ccccc')
|
||||
Loading…
Reference in New Issue
Block a user