summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSylvain Th?nault <sylvain.thenault@logilab.fr>2010-05-21 11:09:46 +0200
committerSylvain Th?nault <sylvain.thenault@logilab.fr>2010-05-21 11:09:46 +0200
commitb04b790f2f7698bc0212f7bd6512d399edbb33c7 (patch)
tree6b59ca4ee953ac9965c800b348576577eb80922f
parenta6681b8b67500689bc0a98272875317c86c063b6 (diff)
parent3ec4893ee725f5d40a4ea870c2c9032bb1453da1 (diff)
downloadlogilab-common-b04b790f2f7698bc0212f7bd6512d399edbb33c7.tar.gz
backport default into stable
-rw-r--r--date.py2
-rw-r--r--test/unittest_testlib.py4
-rw-r--r--testlib.py10
-rw-r--r--textutils.py9
4 files changed, 17 insertions, 8 deletions
diff --git a/date.py b/date.py
index bb5ae1d..6571928 100644
--- a/date.py
+++ b/date.py
@@ -33,7 +33,7 @@ try:
from mx.DateTime import RelativeDateTime, Date, DateTimeType
except ImportError:
from warnings import warn
- warn("mxDateTime not found, endsOfMonth won't be available")
+ warn("mxDateTime not found, endOfMonth won't be available")
endOfMonth = None
DateTimeType = datetime
else:
diff --git a/test/unittest_testlib.py b/test/unittest_testlib.py
index 3514f73..74a8c10 100644
--- a/test/unittest_testlib.py
+++ b/test/unittest_testlib.py
@@ -218,7 +218,9 @@ class TestlibTC(TestCase):
self.assertRaises(AssertionError, self.tc.assertTextEqual, "toto", None)
self.assertRaises(AssertionError, self.tc.assertTextEqual, 3.12, u"toto")
self.assertRaises(AssertionError, self.tc.assertTextEqual, None, u"toto")
-
+ self.tc.assertTextEqual('toto\ntiti', 'toto\ntiti')
+ self.tc.assertTextEqual('toto\ntiti', 'toto\n titi\n', striplines=True)
+ self.assertRaises(AssertionError, self.tc.assertTextEqual, 'toto\ntiti', 'toto\n titi\n')
foo = join(dirname(__file__), 'data', 'foo.txt')
spam = join(dirname(__file__), 'data', 'spam.txt')
text1 = file(foo).read()
diff --git a/testlib.py b/testlib.py
index d6bfedc..21e2ca8 100644
--- a/testlib.py
+++ b/testlib.py
@@ -1491,7 +1491,7 @@ succeeded test into", osp.join(os.getcwd(),FILE_RESTART)
self.fail('\n'.join(['%s\n'%msg_prefix]+read + list(result)))
def assertTextEquals(self, text1, text2, junk=None,
- msg_prefix='Text differ'):
+ msg_prefix='Text differ', striplines=False):
"""compare two multiline strings (using difflib and splitlines())"""
msg = []
if not isinstance(text1, basestring):
@@ -1500,8 +1500,12 @@ succeeded test into", osp.join(os.getcwd(),FILE_RESTART)
msg.append('text2 is not a string (%s)'%(type(text2)))
if msg:
self.fail('\n'.join(msg))
- self._difftext(text1.strip().splitlines(True), text2.strip().splitlines(True),
- junk, msg_prefix)
+ lines1 = text1.strip().splitlines(True)
+ lines2 = text2.strip().splitlines(True)
+ if striplines:
+ lines1 = [line.strip() for line in lines1]
+ lines2 = [line.strip() for line in lines2]
+ self._difftext(lines1, lines2, junk, msg_prefix)
assertTextEqual = assertTextEquals
def assertStreamEquals(self, stream1, stream2, junk=None,
diff --git a/textutils.py b/textutils.py
index 9f80b2e..ed79050 100644
--- a/textutils.py
+++ b/textutils.py
@@ -395,13 +395,13 @@ ANSI_COLORS = {
'white' : "37",
}
-
def _get_ansi_code(color=None, style=None):
"""return ansi escape code corresponding to color and style
:type color: str or None
:param color:
- the color identifier (see `ANSI_COLORS` for available values)
+ the color name (see `ANSI_COLORS` for available values)
+ or the color number when 256 colors are available
:type style: str or None
:param style:
@@ -418,7 +418,10 @@ def _get_ansi_code(color=None, style=None):
style_attrs = splitstrip(style)
for effect in style_attrs:
ansi_code.append(ANSI_STYLES[effect])
- if color:
+ if color.isdigit():
+ ansi_code.extend(['38','5'])
+ ansi_code.append(color)
+ else:
ansi_code.append(ANSI_COLORS[color])
if ansi_code:
return ANSI_PREFIX + ';'.join(ansi_code) + ANSI_END