You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by hw...@apache.org on 2012/03/13 03:21:36 UTC

svn commit: r1299956 - /subversion/trunk/subversion/tests/cmdline/svntest/wc.py

Author: hwright
Date: Tue Mar 13 02:21:36 2012
New Revision: 1299956

URL: http://svn.apache.org/viewvc?rev=1299956&view=rev
Log:
Fix pretty-printing of some datastructures broken in r1299950.

It turns out that we have a few datastructures with pprint() methods in the
Python test suite, which don't really interface with the pprint module, although
they sound like they should.

* subversion/tests/cmdline/svntest/wc.py
  (display_nodes, default_singleton_handler): Use StringIO to build output to
    provide to the logger.

Modified:
    subversion/trunk/subversion/tests/cmdline/svntest/wc.py

Modified: subversion/trunk/subversion/tests/cmdline/svntest/wc.py
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/cmdline/svntest/wc.py?rev=1299956&r1=1299955&r2=1299956&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/cmdline/svntest/wc.py (original)
+++ subversion/trunk/subversion/tests/cmdline/svntest/wc.py Tue Mar 13 02:21:36 2012
@@ -29,6 +29,7 @@ import re
 import urllib
 import logging
 import pprint
+import cStringIO as StringIO
 
 import svntest
 
@@ -898,24 +899,28 @@ def display_nodes(label, path, expected,
   expected = item_to_node(path, expected)
   actual = item_to_node(path, actual)
 
-  output = [
-        "=============================================================\n",
-        "Expected '%s' and actual '%s' in %s tree are different!\n"
-                % (expected.name, actual.name, label),
-        "=============================================================\n",
-        "EXPECTED NODE TO BE:\n",
-        "=============================================================\n",
-        pprint.pformat(expected), '\n',
-        "=============================================================\n",
-        "ACTUAL NODE FOUND:\n",
-        "=============================================================\n",
-        pprint.pformat(actual), '\n',
-    ]
-  logger.warn(''.join(output))
+  o = StringIO()
+  o.write("=============================================================\n")
+  o.write("Expected '%s' and actual '%s' in %s tree are different!\n"
+                % (expected.name, actual.name, label))
+  o.write("=============================================================\n")
+  o.write("EXPECTED NODE TO BE:\n")
+  o.write("=============================================================\n")
+  expected.pprint(o)
+  o.write("=============================================================\n")
+  o.write("ACTUAL NODE FOUND:\n")
+  o.write("=============================================================\n")
+  actual.pprint(o)
+
+  logger.warn(o.getValue())
+  o.close()
 
 ### yanked from tree.py
 def default_singleton_handler(description, path, item):
   node = item_to_node(path, item)
   logger.warn("Couldn't find node '%s' in %s tree" % (node.name, description))
-  logger.warn(pprint.pformat(node))
+  o = StringIO()
+  node.pprint(o)
+  logger.warn(o.getValue())
+  o.close()
   raise svntest.tree.SVNTreeUnequal



Re: svn commit: r1299956 - /subversion/trunk/subversion/tests/cmdline/svntest/wc.py

Posted by Hyrum K Wright <hy...@wandisco.com>.
On Tue, Mar 13, 2012 at 12:57 AM, Greg Stein <gs...@gmail.com> wrote:
> On Mon, Mar 12, 2012 at 22:21,  <hw...@apache.org> wrote:
>> Author: hwright
>> Date: Tue Mar 13 02:21:36 2012
>> New Revision: 1299956
>>
>> URL: http://svn.apache.org/viewvc?rev=1299956&view=rev
>> Log:
>> Fix pretty-printing of some datastructures broken in r1299950.
>>
>> It turns out that we have a few datastructures with pprint() methods in the
>> Python test suite, which don't really interface with the pprint module, although
>> they sound like they should.
>
> I don't understand how .pformat() is different from pprint'ing to a
> stream. What was the underlying cause?

.pformat() isn't itself different from pprint'ing to a stream when
using the module.

What happened here is that we defined some pprint() methods on our own
classes, which took an optional stream argument to which to write.
These methods aren't used by the pprint module in any way, they just
happened to be (confusingly) named the same.

The the underlying cause then was that by using pprint.pformat(), we
weren't getting any of the custom pretty-printing for nodes and trees
that we've all come to know and expect.

-Hyrum



-- 

uberSVN: Apache Subversion Made Easy
http://www.uberSVN.com/

Re: svn commit: r1299956 - /subversion/trunk/subversion/tests/cmdline/svntest/wc.py

Posted by Greg Stein <gs...@gmail.com>.
On Mon, Mar 12, 2012 at 22:21,  <hw...@apache.org> wrote:
> Author: hwright
> Date: Tue Mar 13 02:21:36 2012
> New Revision: 1299956
>
> URL: http://svn.apache.org/viewvc?rev=1299956&view=rev
> Log:
> Fix pretty-printing of some datastructures broken in r1299950.
>
> It turns out that we have a few datastructures with pprint() methods in the
> Python test suite, which don't really interface with the pprint module, although
> they sound like they should.

I don't understand how .pformat() is different from pprint'ing to a
stream. What was the underlying cause?

Thanks,
-g

Re: svn commit: r1299956 - /subversion/trunk/subversion/tests/cmdline/svntest/wc.py

Posted by Hyrum K Wright <hy...@wandisco.com>.
On Tue, Mar 13, 2012 at 1:00 AM, Greg Stein <gs...@gmail.com> wrote:
> On Mon, Mar 12, 2012 at 22:21,  <hw...@apache.org> wrote:
>>...
>> +++ subversion/trunk/subversion/tests/cmdline/svntest/wc.py Tue Mar 13 02:21:36 2012
>> @@ -29,6 +29,7 @@ import re
>>  import urllib
>>  import logging
>>  import pprint
>> +import cStringIO as StringIO
>>...
>> +  o = StringIO()
>
> I don't see how a func-call to a module can possibly work, so I'm
> assuming this code was not actually tested (last minute change?). That
> may also lead to my query about pprint-to-stream vs pformat.

last-minute (and late-night) change.  Fixed in r1300121.

> And, FWIW, the cStringIO module is standard in Python 2.5, so there
> isn't really a need to import "as StringIO" (as you'd see in various
> compat-style import logic).

As mentioned elsethread, cStringIO is a drop-in replacement for
StringIO, so my habit is to import the former as the latter.  Another
alternative (which we use in some places) is to just import the
StringIO class from either module.

-Hyrum


-- 

uberSVN: Apache Subversion Made Easy
http://www.uberSVN.com/

Re: svn commit: r1299956 - /subversion/trunk/subversion/tests/cmdline/svntest/wc.py

Posted by Greg Stein <gs...@gmail.com>.
On Mon, Mar 12, 2012 at 22:21,  <hw...@apache.org> wrote:
>...
> +++ subversion/trunk/subversion/tests/cmdline/svntest/wc.py Tue Mar 13 02:21:36 2012
> @@ -29,6 +29,7 @@ import re
>  import urllib
>  import logging
>  import pprint
> +import cStringIO as StringIO
>...
> +  o = StringIO()

I don't see how a func-call to a module can possibly work, so I'm
assuming this code was not actually tested (last minute change?). That
may also lead to my query about pprint-to-stream vs pformat.

And, FWIW, the cStringIO module is standard in Python 2.5, so there
isn't really a need to import "as StringIO" (as you'd see in various
compat-style import logic).

>...

Cheers,
-g

> +  o.write("=============================================================\n")
> +  o.write("Expected '%s' and actual '%s' in %s tree are different!\n"
> +                % (expected.name, actual.name, label))
> +  o.write("=============================================================\n")
> +  o.write("EXPECTED NODE TO BE:\n")
> +  o.write("=============================================================\n")
> +  expected.pprint(o)
> +  o.write("=============================================================\n")
> +  o.write("ACTUAL NODE FOUND:\n")
> +  o.write("=============================================================\n")
> +  actual.pprint(o)
> +
> +  logger.warn(o.getValue())
> +  o.close()
>
>  ### yanked from tree.py
>  def default_singleton_handler(description, path, item):
>   node = item_to_node(path, item)
>   logger.warn("Couldn't find node '%s' in %s tree" % (node.name, description))
> -  logger.warn(pprint.pformat(node))
> +  o = StringIO()
> +  node.pprint(o)
> +  logger.warn(o.getValue())
> +  o.close()
>   raise svntest.tree.SVNTreeUnequal
>
>