<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html; charset=ISO-8859-1"
 http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
On 04/03/2010 22:03, Ryan Freckleton wrote:
<blockquote
 cite="mid:318072441003041403j277c8cb3gd3f36e2abac77c20@mail.gmail.com"
 type="cite">On Wed, Mar 3, 2010 at 12:15 PM, Michael Foord <span
 dir="ltr">&lt;<a moz-do-not-send="true"
 href="mailto:fuzzyman@voidspace.org.uk">fuzzyman@voidspace.org.uk</a>&gt;</span>
wrote:<br>
&lt;snip&gt;<br>
  <div class="gmail_quote">
  <div>&nbsp;</div>
  <blockquote class="gmail_quote"
 style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Once
Holger and Benjamin have worked on their ast transformation code it
should be possible to add this to simpletest for better failure
messages with plain asserts.<br>
  </blockquote>
  <div>&lt;snip&gt;<br>
  <br>
Does that mean we're going to get pretty asserts through ast
transforms? As in:<br>
  </div>
  </div>
</blockquote>
<br>
Well, not in unittest itself but in some extension of unittest...<br>
<br>
There is an implementation that could be adapted fairly easily:<br>
<br>
&nbsp;&nbsp;&nbsp;
<a class="moz-txt-link-freetext" href="http://bitbucket.org/hpk42/py-trunk/src/tip/py/_code/_assertionnew.py">http://bitbucket.org/hpk42/py-trunk/src/tip/py/_code/_assertionnew.py</a><br>
<br>
This uses the ast module which is new in Python 2.6, but it could be
backported to use _ast for Python 2.5. There is also an old version
called "<span class="sd">_assertionold.py" that uses the compiler
module present in Python 2.4.<br>
<br>
There is also code in nose that does something similar (stack
introspection rather than ast transformation I *believe*) in nose. If
unittest had a good extension API this could just be implemented as a
unittest extension...<br>
<br>
All the best,<br>
<br>
Michael <br>
</span><br>
<blockquote
 cite="mid:318072441003041403j277c8cb3gd3f36e2abac77c20@mail.gmail.com"
 type="cite">
  <div class="gmail_quote">
  <div><br>
&nbsp;&nbsp;&nbsp; assert obj.froddle() == "baz"<br>
  <br>
gets transformed into like (or at least functionally equivalent to):<br>
  <br>
result = object.froddle()<br>
expected = "baz"<br>
assert result == expected, "%s != %s" % (result, expected)<br>
  </div>
  </div>
  <br>
If so, that's fantastic! The same thought crossed my mind to implement
that with ast transforms, but I don't have enough ast-fu to implement
it.<br>
  <br>
  <br clear="all">
=====<br>
--Ryan E. Freckleton<br>
</blockquote>
<br>
<br>
<pre class="moz-signature" cols="72">-- 
<a class="moz-txt-link-freetext" href="http://www.ironpythoninaction.com/">http://www.ironpythoninaction.com/</a>
<a class="moz-txt-link-freetext" href="http://www.voidspace.org.uk/blog">http://www.voidspace.org.uk/blog</a>

READ CAREFULLY. By accepting and reading this email you agree, on behalf of your employer, to release me from all obligations and waivers arising from any and all NON-NEGOTIATED agreements, licenses, terms-of-service, shrinkwrap, clickwrap, browsewrap, confidentiality, non-disclosure, non-compete and acceptable use policies (&#8221;BOGUS AGREEMENTS&#8221;) that I have entered into with your employer, its partners, licensors, agents and assigns, in perpetuity, without prejudice to my ongoing rights and privileges. You further represent that you have the authority to release me from any BOGUS AGREEMENTS on behalf of your employer.

</pre>
</body>
</html>