[Zope3-dev] help with doctests

2007-07-20 Thread Adam Groszer
Hello,

In z.a.apidoc.browser.README.txt I can write

   browser.open('http://localhost/++apidoc++/non-existent/')
  Traceback (most recent call last):
  ...
  httperror_seek_wrapper: HTTP Error 404: Not Found

(test passes)

but I can't write

   browser.open('http://localhost/++apidoc++/non-existent/')
  Traceback (most recent call last):
  ...
  ...HTTP Error 404: Not Found

it throws:

Failed example:
browser.open('http://localhost/++apidoc++/non-existent/')
Exception raised:
Traceback (most recent call last):
  File U:\zope\svn_zope34\src\zope\testing\doctest.py, line 1348, in __run

compileflags, 1) in test.globs
  File doctest README.txt[3], line 1, in ?
browser.open('http://localhost/++apidoc++/non-existent/')
  File U:\zope\svn_zope34\src\zope\testbrowser\browser.py, line 224, in 
open
self.mech_browser.open(url, data)
  File U:\zope\svn_zope34\src\mechanize\_mechanize.py, line 203, in open
return self._mech_open(url, data)
  File U:\zope\svn_zope34\src\mechanize\_mechanize.py, line 254, in 
_mech_open
raise response
httperror_seek_wrapper: HTTP Error 404: Not Found


what do I miss?

-- 
Best regards,
 Adam  mailto:[EMAIL PROTECTED]

___
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com



AW: [Zope3-dev] help with doctests

2007-07-20 Thread Roger Ineichen
Hi Adam

 Auftrag von Adam Groszer
 Gesendet: Freitag, 20. Juli 2007 09:49
 An: zope3-dev
 Betreff: [Zope3-dev] help with doctests
 
 Hello,
 
 In z.a.apidoc.browser.README.txt I can write 
browser.open('http://localhost/++apidoc++/non-existent/')
   Traceback (most recent call last):
   ...
   httperror_seek_wrapper: HTTP Error 404: Not Found 
 (test passes)
 
 but I can't write
 
browser.open('http://localhost/++apidoc++/non-existent/')
   Traceback (most recent call last):
   ...
   ...HTTP Error 404: Not Found

Did you try:

...HTTP Error 404: Not Found...

Regards
Roger Ineichen
_
END OF MESSAGE

___
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com



Re: AW: [Zope3-dev] help with doctests

2007-07-20 Thread Adam Groszer
Hi Roger!

Yes, it's the same :-(

Friday, July 20, 2007, 9:59:48 AM, you wrote:

RI Hi Adam

 Auftrag von Adam Groszer
 Gesendet: Freitag, 20. Juli 2007 09:49
 An: zope3-dev
 Betreff: [Zope3-dev] help with doctests
 
 Hello,
 
 In z.a.apidoc.browser.README.txt I can write 
browser.open('http://localhost/++apidoc++/non-existent/')
   Traceback (most recent call last):
   ...
   httperror_seek_wrapper: HTTP Error 404: Not Found 
 (test passes)
 
 but I can't write
 
browser.open('http://localhost/++apidoc++/non-existent/')
   Traceback (most recent call last):
   ...
   ...HTTP Error 404: Not Found

RI Did you try:

RI ...HTTP Error 404: Not Found...

RI Regards
RI Roger Ineichen
RI _
RI END OF MESSAGE


___
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com



[Zope3-dev] doctest prb again

2007-07-20 Thread Adam Groszer
Hello,

How to solve the \r\n and \n mismatch between win32 and *nix in the
doctests?

doctest is:

 ctrl.value
'Text inside\narea!\n  '


fails with (on win32):

Failed example:
ctrl.value
Expected:
'Text inside\narea!\n  '
Got:
'  Text inside\r\n  area!\r\n'


ctrl.value comes from a html file in zope.testbrowser.ftests
-- 
Best regards,
 Adam  mailto:[EMAIL PROTECTED]

___
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com



Re: [Zope3-dev] doctest prb again

2007-07-20 Thread Stefan H. Holek

Doesn't NORMALIZE_WHITESPACE help here?

Stefan


On 20. Jul 2007, at 10:09, Adam Groszer wrote:


How to solve the \r\n and \n mismatch between win32 and *nix in the
doctests?


--
Anything that happens, happens.  --Douglas Adams


___
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com



Re[2]: [Zope3-dev] doctest prb again

2007-07-20 Thread Adam Groszer
Hello Stefan,

It seems to be already enabled:
flags = doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS
readme = FunctionalDocFileSuite('README.txt', optionflags=flags,
checker=checker)


Friday, July 20, 2007, 10:18:30 AM, you wrote:

 Doesn't NORMALIZE_WHITESPACE help here?

 Stefan


 On 20. Jul 2007, at 10:09, Adam Groszer wrote:

 How to solve the \r\n and \n mismatch between win32 and *nix in the
 doctests?

 --
 Anything that happens, happens.  --Douglas Adams

-- 
Best regards,
 Adammailto:[EMAIL PROTECTED]

___
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com



Re: [Zope3-dev] doctest prb again

2007-07-20 Thread Marius Gedminas
On Fri, Jul 20, 2007 at 10:09:18AM +0200, Adam Groszer wrote:
 Hello,
 
 How to solve the \r\n and \n mismatch between win32 and *nix in the
 doctests?
 
 doctest is:
 
  ctrl.value
 'Text inside\narea!\n  '
 
 
 fails with (on win32):
 
 Failed example:
 ctrl.value
 Expected:
 'Text inside\narea!\n  '
 Got:
 '  Text inside\r\n  area!\r\n'
 
 
 ctrl.value comes from a html file in zope.testbrowser.ftests

You could do

 ctrl.value.replace('\r', '')

or strip the \r's in the place where you're reading that html file.

Marius Gedminas
-- 
This host is a black hole at HTTP wavelengths. GETs go in, and nothing
comes out, not even Hawking radiation.
-- Graaagh the Mighty on rec.games.roguelike.angband


signature.asc
Description: Digital signature
___
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com



Re[2]: [Zope3-dev] doctest prb again

2007-07-20 Thread Adam Groszer
Hello Marius,

Great, that works ;-)
Thought that there is some more genreic-sane way.

Friday, July 20, 2007, 10:25:02 AM, you wrote:

 On Fri, Jul 20, 2007 at 10:09:18AM +0200, Adam Groszer wrote:
 Hello,
 
 How to solve the \r\n and \n mismatch between win32 and *nix in the
 doctests?
 
 doctest is:
 
  ctrl.value
 'Text inside\narea!\n  '
 
 
 fails with (on win32):
 
 Failed example:
 ctrl.value
 Expected:
 'Text inside\narea!\n  '
 Got:
 '  Text inside\r\n  area!\r\n'
 
 
 ctrl.value comes from a html file in zope.testbrowser.ftests

 You could do

  ctrl.value.replace('\r', '')

 or strip the \r's in the place where you're reading that html file.

 Marius Gedminas

-- 
Best regards,
 Adammailto:[EMAIL PROTECTED]

___
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com



Re: [Zope3-dev] help with doctests

2007-07-20 Thread Marius Gedminas
On Fri, Jul 20, 2007 at 09:48:52AM +0200, Adam Groszer wrote:
 Hello,
 
 In z.a.apidoc.browser.README.txt I can write
 
browser.open('http://localhost/++apidoc++/non-existent/')
   Traceback (most recent call last):
   ...
   httperror_seek_wrapper: HTTP Error 404: Not Found
 
 (test passes)
 
 but I can't write
 
browser.open('http://localhost/++apidoc++/non-existent/')
   Traceback (most recent call last):
   ...
   ...HTTP Error 404: Not Found
 
 it throws:
 
 Failed example:
 browser.open('http://localhost/++apidoc++/non-existent/')
 Exception raised:
 Traceback (most recent call last):
   File U:\zope\svn_zope34\src\zope\testing\doctest.py, line 1348, in 
 __run
 
 compileflags, 1) in test.globs
   File doctest README.txt[3], line 1, in ?
 browser.open('http://localhost/++apidoc++/non-existent/')
   File U:\zope\svn_zope34\src\zope\testbrowser\browser.py, line 224, in 
 open
 self.mech_browser.open(url, data)
   File U:\zope\svn_zope34\src\mechanize\_mechanize.py, line 203, in open
 return self._mech_open(url, data)
   File U:\zope\svn_zope34\src\mechanize\_mechanize.py, line 254, in 
 _mech_open
 raise response
 httperror_seek_wrapper: HTTP Error 404: Not Found
 
 
 what do I miss?

doctests have special rules for exceptions that are different from the
rules of normal output matching.

If a statement raises an exception, the output part must be of the form

  Traceback (most recent call last):
...
  exception type: exception value

You can use ellipsis in the exception value part, IIRC.

Marius Gedminas
-- 
HOST SYSTEM NOT RESPONDING, PROBABLY DOWN. DO YOU WANT TO WAIT? (Y/N)


signature.asc
Description: Digital signature
___
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com



[Zope3-dev] Re: help with doctests

2007-07-20 Thread Philipp von Weitershausen

Marius Gedminas wrote:

doctests have special rules for exceptions that are different from the
rules of normal output matching.

If a statement raises an exception, the output part must be of the form

  Traceback (most recent call last):
...
  exception type: exception value

You can use ellipsis in the exception value part, IIRC.


But I wouldn't recommend using them. Sometimes, using ellipses are fine, 
but generally they obfuscate the doctest when you're reading it. I 
suggesting using the regex-normalizer [1]. There are many packages out 
there that use it if you're looking for examples.



http://svn.zope.org/zope.testing/trunk/src/zope/testing/renormalizing.py?rev=66267view=auto


--
http://worldcookery.com -- Professional Zope documentation and training
___
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com



[Zope3-dev] Re: doctest prb again

2007-07-20 Thread Philipp von Weitershausen

Adam Groszer wrote:

Great, that works ;-)
Thought that there is some more genreic-sane way.


There is. NORMALIZE_WHITESPACE actually only helps when whatever you're 
outputting actually prints whitespace. Doing this::


   '   '
  '   '

won't invoke the whitespace normalizer. Doing this::

  print '   '
 three spaces

will invoke it, though.



Friday, July 20, 2007, 10:25:02 AM, you wrote:

On Fri, Jul 20, 2007 at 10:09:18AM +0200, Adam Groszer wrote:

Hello,

How to solve the \r\n and \n mismatch between win32 and *nix in the
doctests?

doctest is:

 ctrl.value
'Text inside\narea!\n  '


fails with (on win32):

Failed example:
ctrl.value
Expected:
'Text inside\narea!\n  '
Got:
'  Text inside\r\n  area!\r\n'


ctrl.value comes from a html file in zope.testbrowser.ftests



You could do



 ctrl.value.replace('\r', '')



or strip the \r's in the place where you're reading that html file.



Marius Gedminas





--
http://worldcookery.com -- Professional Zope documentation and training
___
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com



Re: [Zope3-dev] Re: help with doctests

2007-07-20 Thread Adam Groszer
Hello Philipp,

Great, that would solve also the \r\n substitution also (I hope).

Friday, July 20, 2007, 11:27:52 AM, you wrote:

 Marius Gedminas wrote:
 doctests have special rules for exceptions that are different from the
 rules of normal output matching.
 
 If a statement raises an exception, the output part must be of the form
 
   Traceback (most recent call last):
 ...
   exception type: exception value
 
 You can use ellipsis in the exception value part, IIRC.

 But I wouldn't recommend using them. Sometimes, using ellipses are fine,
 but generally they obfuscate the doctest when you're reading it. I 
 suggesting using the regex-normalizer [1]. There are many packages out
 there that use it if you're looking for examples.


 http://svn.zope.org/zope.testing/trunk/src/zope/testing/renormalizing.py?rev=66267view=auto

-- 
Best regards,
 Adammailto:[EMAIL PROTECTED]

___
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com



Re: [Zope3-dev] Re: help with doctests

2007-07-20 Thread Benji York

Philipp von Weitershausen wrote:

Sometimes, using ellipses are fine, but generally they obfuscate the
doctest when you're reading it. I suggesting using the
regex-normalizer [1].


+1
--
Benji York
Senior Software Engineer
Zope Corporation
___
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com



Re: [Zope3-dev] Re: help with doctests

2007-07-20 Thread Jim Fulton


On Jul 20, 2007, at 5:27 AM, Philipp von Weitershausen wrote:


Marius Gedminas wrote:
doctests have special rules for exceptions that are different from  
the

rules of normal output matching.
If a statement raises an exception, the output part must be of the  
form

  Traceback (most recent call last):
...
  exception type: exception value
You can use ellipsis in the exception value part, IIRC.


But I wouldn't recommend using them. Sometimes, using ellipses are  
fine, but generally they obfuscate the doctest when you're reading  
it. I suggesting using the regex-normalizer [1]. There are many  
packages out there that use it if you're looking for examples.



http://svn.zope.org/zope.testing/trunk/src/zope/testing/ 
renormalizing.py?rev=66267view=auto


BTW, a small useful easy project that I don't have time for would be  
to generalize the renormalizer to allow other objects besides regexes.


You now give this a sequences of regex/replacement pairs.

It would be nice to allow callables in addition to regexs.   
Basically, allow items in the sequence to be either:


- a regex+replacement tuple, or

- a callable transformer that reads the text and returns new text.

While regexs and replacements are very powerful, there've been times  
when I wanted the full generality of Python.  I ended up subclassing  
the renormalizer in these cases, but would have preferred not to have  
had to do so.


Jim

--
Jim Fulton  mailto:[EMAIL PROTECTED]Python 
Powered!
CTO (540) 361-1714  
http://www.python.org
Zope Corporationhttp://www.zope.com http://www.zope.org



___
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com



Re: [Zope3-dev] Re: help with doctests

2007-07-20 Thread Marius Gedminas
On Fri, Jul 20, 2007 at 07:57:12AM -0400, Jim Fulton wrote:
 On Jul 20, 2007, at 5:27 AM, Philipp von Weitershausen wrote:
 I suggesting using the regex-normalizer [1]. There are many  
 packages out there that use it if you're looking for examples.
 
 http://svn.zope.org/zope.testing/trunk/src/zope/testing/renormalizing.py?rev=66267view=auto
 
 BTW, a small useful easy project that I don't have time for would be  
 to generalize the renormalizer to allow other objects besides regexes.

It already does, in a way.  It doesn't call re.compile by itself, so
you can pass it anything that implements a ``sub`` method, not
necessarily regexes.

class LowercaseTransformer(object):
def sub(replacement, text):
return text.lower()

checker = RENormalizing([(LowercaseTransformer(), None)])

 You now give this a sequences of regex/replacement pairs.
 
 It would be nice to allow callables in addition to regexs.
 Basically, allow items in the sequence to be either:
 
 - a regex+replacement tuple, or
 
 - a callable transformer that reads the text and returns new text.

So essentially you want nicer syntax for the above.  Should be easy to do:

Index: renormalizing.py
===
--- renormalizing.py(revision 78151)
+++ renormalizing.py(working copy)
@@ -181,15 +181,21 @@ class RENormalizing(doctest.OutputChecke
 
 
 def __init__(self, patterns):
-self.patterns = patterns
+self.transformers = map(self._cook, patterns)
+
+def _cook(self, pattern):
+if callable(pattern):
+return pattern
+regexp, replacement = pattern
+return lambda text: regexp.sub(replacement, text)
 
 def check_output(self, want, got, optionflags):
 if got == want:
 return True
 
-for pattern, repl in self.patterns:
-want = pattern.sub(repl, want)
-got = pattern.sub(repl, got)
+for transformer in self.transformers:
+want = transformer(want)
+got = transformer(got)
 
 return doctest.OutputChecker.check_output(self, want, got, optionflags)
 
@@ -208,9 +214,9 @@ class RENormalizing(doctest.OutputChecke
 # Dang, this isn't as easy to override as we might wish
 original = want
 
-for pattern, repl in self.patterns:
-want = pattern.sub(repl, want)
-got = pattern.sub(repl, got)
+for transformer in self.transformers:
+want = transformer(want)
+got = transformer(got)
 
 # temporarily hack example with normalized want:
 example.want = want


Do you want me to write unit tests for this and commit?

Marius Gedminas
-- 
C is quirky, flawed, and an enormous success.
-- Dennis M. Ritchie


signature.asc
Description: Digital signature
___
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com



[Zope3-dev] Re: doctest prb again

2007-07-20 Thread Marius Gedminas
On Fri, Jul 20, 2007 at 11:30:08AM +0200, Philipp von Weitershausen wrote:
 Adam Groszer wrote:
 Great, that works ;-)
 Thought that there is some more genreic-sane way.
 
 There is. NORMALIZE_WHITESPACE actually only helps when whatever you're 
 outputting actually prints whitespace. Doing this::
 
'   '
   '   '
 
 won't invoke the whitespace normalizer.

I'm pretty certain you're mistaken here:

 import doctest
 def test1():
... 
...  '   ' # doctest: +NORMALIZE_WHITESPACE
... ' '
... 
... 
 doctest.testmod()
(0, 1)

The test passes.  What wouldn't work, though, is if you tried to match
whitespace that is not expressed as whitespace in your test, e.g. tabs:

 def test2():
... r
...  '\t\t ' # doctest: +NORMALIZE_WHITESPACE
... '\t'
... 
... 
 doctest.testmod()
**
File /home/mg/.python, line 25, in __main__.test2
Failed example:
'\t\t' # doctest: +NORMALIZE_WHITESPACE
Expected:
'\t'
Got:
'\t\t'
**
1 items had failures:
   1 of   1 in __main__.test2
***Test Failed*** 1 failures.
*** DocTestRunner.merge: '__main__.test1' in both testers; summing outcomes.
*** DocTestRunner.merge: '__main__' in both testers; summing outcomes.
(1, 2)

Marius Gedminas
-- 
America and England are two countries separated by a common language.


signature.asc
Description: Digital signature
___
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com