[Patches] [ python-Patches-1019220 ] Multi-line strings and unittest

SourceForge.net noreply at sourceforge.net
Tue Sep 7 19:21:02 CEST 2004


Patches item #1019220, was opened at 2004-08-30 19:00
Message generated for change (Comment added) made by felixwiemann
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1019220&group_id=5470

Category: Library (Lib)
Group: None
Status: Closed
Resolution: Rejected
Priority: 5
Submitted By: Felix Wiemann (felixwiemann)
Assigned to: Steve Purcell (purcell)
Summary: Multi-line strings and unittest

Initial Comment:
Currently, the output of unittest.py looks like this:


F
======================================================================
FAIL: test_newline (__main__.NewlineTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "unittestnewline.py", line 7, in test_newline
    self.assertEqual('foo\nbar\nbaz', 'foo\nbaz\nbaz')
AssertionError: 'foo\nbar\nbaz' != 'foo\nbaz\nbaz'

----------------------------------------------------------------------
Ran 1 test in 0.001s

FAILED (failures=1)


For long strings to be compared, an output like
'foo\nbar\nbaz' != 'foo\nbaz\nbaz'
isn't particularly useful.

The attached patch makes it look like this for
multi-line strings:


F
======================================================================
FAIL: test_newline (__main__.NewlineTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "unittestnewline.py", line 7, in test_newline
    self.assertEqual('foo\nbar\nbaz', 'foo\nbaz\nbaz')
AssertionError: '''foo
bar
baz''' != '''foo
baz
baz'''

----------------------------------------------------------------------
Ran 1 test in 0.001s

FAILED (failures=1)



The behavior is only changed for strings which contain
newline characters.

I admittedly do not know if there is a problem when
using the patched unittest.py on Windows (due to the
different newline convention).

----------------------------------------------------------------------

>Comment By: Felix Wiemann (felixwiemann)
Date: 2004-09-07 19:21

Message:
Logged In: YES 
user_id=1014490

> I personally like to see the repr()
> version of the strings, since it shows embedded tabs etc;

The patch doesn't change that.  It just replaces \n by real
newlines.

The reason why I wrote this patch is that the Docutils unit
tests often contain very many lines of text, and if
something has changed, it is very handy to be able to copy
some lines of test output into the test files.  But this
only works if the lines contain real newlines -- the long
character sequences with some intermittent '\n's unittest.py
currently produces are almost unusable.

If I've been able convince you, feel free to re-open the
bug.  :-)

----------------------------------------------------------------------

Comment By: Steve Purcell (purcell)
Date: 2004-09-07 17:54

Message:
Logged In: YES 
user_id=21477

Hi Raymond and Felix, 
 
I also don't find this an improvement. I personally like to see the repr() 
version of the strings, since it shows embedded tabs etc; the output 
proposed here makes such differences much less obvious. 
 
More interesting was a patch submitted some time ago that used difflib 
to show the exact differing areas between the unequal strings. I was 
wary of that patch due to the amount of extra code it introduced, and 
an incompatibility with Jython at the time, IIRC. 

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2004-09-07 07:08

Message:
Logged In: YES 
user_id=80475

Steve, would you rule on this one?

I personally do not find it to be an improvement.

Walter Dörwald is also a heavy unittester and may have a
helpful viewpoint.



----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1019220&group_id=5470


More information about the Patches mailing list