Fwd: [py-dev] py.test munging strings in asserts?
Timothy Grant
timothy.grant at gmail.com
Sat Apr 22 07:33:52 CEST 2006
Meant to reply all and only replied to Jan.
---------- Forwarded message ----------
From: Timothy Grant <timothy.grant at gmail.com>
Date: Apr 21, 2006 3:09 PM
Subject: Re: [py-dev] py.test munging strings in asserts?
To: Jan Balster <jan at balster.info>
While the test for equality my not be affected by the truncation of
the output, the ability to effectively debug the FAILURE of the
assertion is negatively impacted by this. When I have two long
strings that are almost but not quite equal, how am I to go about
debugging the test failure, when the discrepancy may be hidden by the
"..."
I could easily envision (having done this in the past with other
tools) writing a command line utility that would look for an assertion
that contained a long string comparison, and then diff the two strings
to help point out where the problem is.
I realize that py.test allows me to use "print" to my heart's content,
but I that makes the output even MORE verbose.
I'd love any suggestions.
On 4/21/06, Jan Balster <jan at balster.info> wrote:
> Hi Timothy!
>
> The output is truncated to 240 characters, which is exactly the length of your
> strings in the output. The dots are only indicators, that the output was truncated.
> See py/test/terminal/terminal.py:439 and py/code/save_repr.py for explanations.
> As stated in the comments, we probably need a command line switch to toggle the
> behavior.
>
> The test of equality is not affected by the truncation of the output! If you
> write the text to stdout or a file, you will see it in it's whole glory.
>
> example:
>
> def test_output():
> long_string = '/' * 238 # 238 + two "'" for the string representation == 240
> longer_string = 'start' + long_string + 'end' # will be truncated
>
> print longer_string
>
> assert long_string == longer_string
>
> If you have any further questions, don't hesitate to ask!
>
> Cheers,
> Jan
>
>
> > I'm writing a test to test some HTML output and the test fails for
> > several reasons, all of which I understand but one.
> >
> > Here's the output (I've surrounded the problem area with *** to make
> > it a little more visible.
> >
> > ========================================================
> > def test_error_summary():
> > text = '''<html>
> > <head>
> > <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
> > <title>PyTestMate</title>
> >
> > <style type="text/css">
> > .error {color : #FF0000}
> > </style>
> >
> > </head>
> > <body>
> > <p>Error in <a
> > href="txmt://open/?url=file:///Users/tjg/code/textmate/test_pytestmate.py&line=17">/Users/tjg/code/textmate/test_pytestmate.py</a>
> > at line 17</p>
> > <pre>
> > [/Users/tjg/code/textmate/test_pytestmate.py:17]
> > </pre>
> > </body>
> > </html>'''
> >
> > assert pytestmate.create_output(
> > ['[/Users/tjg/code/textmate/test_pytestmate.py:17]']
> > E ) == text
> >> assert '<html>\n<head>\n<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\n<title>PyTestMate</title>\n\n***<...mate/test_pytestmate.py***</a> at line 17<br/><pre>[/Users/tjg/code/textmate/test_pytestmate.py:17]</pre></body>\n</html>' == '<html>\n<head>\n<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\n<title>PyTestMate</title>\n\n***<...st_pytestmate.py***</a> at line 17</p>\n<pre>\n[/Users/tjg/code/textmate/test_pytestmate.py:17]\n</pre>\n</body>\n</html>'
> > + where '<html>\n<head>\n<meta http-equiv="Content-Type"
> > content="text/html; charset=utf-8"
> > />\n<title>PyTestMate</title>\n\n<...mate/test_pytestmate.py</a> at
> > line 17<br/><pre>[/Users/tjg/code/textmate/test_pytestmate.py:17]</pre></body>\n</html>'
> > = <function create_output at
> > 0x42e870>(['[/Users/tjg/code/textmate/test_pytestmate.py:17]'])
> > + where <function create_output at 0x42e870> =
> > pytestmate.create_output
> >
> > [/Users/tjg/code/textmate/test_pytestmate.py:55]
> > ===============================================
> >
> > granted the left side of that equality could be messed up due to
> > create_output() NOT doing the right thing. But the right side is
> > simply the contents of the variable "text" so WHY is the first part of
> > the path being substituted with "..."?
> >
> > Any insight greatly appreciated.
> >
> >
> > --
> > Stand Fast,
> > tjg.
> > _______________________________________________
> > py-dev mailing list
> > py-dev at codespeak.net
> > http://codespeak.net/mailman/listinfo/py-dev
> >
>
--
Stand Fast,
tjg.
--
Stand Fast,
tjg.
More information about the py-dev
mailing list