469,630 Members | 1,202 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,630 developers. It's quick & easy.

doctest bug with nested triple quotes

I am getting trouble with nested triple quoted strings in doctest.
For instance

$ cat x.py
"""
dummy = '''

something
here
'''
"""
import doctest; doctest.testmod()

$ python x.py

************************************************** ********************
File "x.py", line 2, in __main__
Failed example:
dummy = '''
Exception raised:
Traceback (most recent call last):
File "/usr/lib/python2.4/doctest.py", line 1243, in __run
compileflags, 1) in test.globs
File "<doctest __main__[0]>", line 1
dummy = '''
^
SyntaxError: EOF while scanning triple-quoted string
************************************************** ********************

Is this a know bug? Any workaround? Thanks for comments,
Michele Simionato

Aug 2 '05 #1
3 2256
I can't reproduce the error. Freebsd,python 2.4 runs it.
cat x.py """
dummy = '''

something
here
'''
"""
import doctest; doctest.testmod() python x.py

maybe the file is different. python -c "print open('x.py').read().encode('base64')"

IiIiCmR1bW15ID0gJycnCgpzb21ldGhpbmcKaGVyZQonJycKIi IiCmltcG9ydCBkb2N0ZXN0OyBk
b2N0ZXN0LnRlc3Rtb2QoKQo=

Paolino

___________________________________
Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB
http://mail.yahoo.it
Aug 2 '05 #2
Michele Simionato wrote:
I am getting trouble with nested triple quoted strings in doctest.
For instance

$ cat x.py
"""
dummy = ''' something
here
'''
"""
import doctest; doctest.testmod()

$ python x.py

************************************************** ********************
File "x.py", line 2, in __main__
Failed example:
dummy = '''
Exception raised:
Traceback (most recent call last):
File "/usr/lib/python2.4/doctest.py", line 1243, in __run
compileflags, 1) in test.globs
File "<doctest __main__[0]>", line 1
dummy = '''
^
SyntaxError: EOF while scanning triple-quoted string
************************************************** ********************

Is this a know bug? Any workaround? Thanks for comments,


I think it is your bug. All lines but the first must be prefixed with
sys.PS2. Just add some dots to make it work:

'''
dummy = """

.... something
.... here
.... """
'''
import doctest; doctest.testmod()

Peter
Aug 2 '05 #3
This is my file
$ python -c "print open('x.py').read().encode('base64')"
IiIiCj4+PiBkdW1teSA9ICcnJwpzb21ldGhpbmcKaGVyZQonJy cKIiIiCmltcG9ydCBkb2N0ZXN0
OyBkb2N0ZXN0LnRlc3Rtb2QoKQo=

but anyway I think Peter Otten is right, the problem is with the
missing dots.
It makes sense, actually, but for some reason I would never have
thought
of it (I did not expect doctest to be so smart to strip the dots even
inside a string).
Thanks for the feeback and the quick solution,

Michele Simionato

Aug 2 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Edward K. Ream | last post: by
8 posts views Thread by Christoph Zwerschke | last post: by
2 posts views Thread by Alan G Isaac | last post: by
4 posts views Thread by 3KWA | last post: by
5 posts views Thread by Candace | last post: by
1 post views Thread by Stuart D. Gathman | last post: by
12 posts views Thread by thomas.guest | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.