From d4f2cc807a3acb9a5ca5e70d123bd834c8134484 Mon Sep 17 00:00:00 2001 From: Nicolas Chauvat Date: Thu, 29 Apr 2010 18:30:15 +0200 Subject: [testlib] add option splitlines to assertTextEquals --- test/unittest_testlib.py | 4 +++- testlib.py | 10 +++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/test/unittest_testlib.py b/test/unittest_testlib.py index 75b9219..6f25ea5 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 410fa45..0d0946d 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, -- cgit v1.2.1 From 8b8a9966e49dd29c621d7a33a7f249250b2ffbc5 Mon Sep 17 00:00:00 2001 From: Nicolas Chauvat Date: Thu, 29 Apr 2010 18:35:07 +0200 Subject: [textutils] support 256 colors when available --- textutils.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/textutils.py b/textutils.py index e5ef28e..275bddb 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 -- cgit v1.2.1 From 3ec4893ee725f5d40a4ea870c2c9032bb1453da1 Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Wed, 28 Apr 2010 08:10:58 +0200 Subject: updated warning text to reflect the real name of unavailable method --- date.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/date.py b/date.py index 36f6e86..b01ed1f 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: -- cgit v1.2.1