doctest bug with nested triple quotes

  • Thread starter Michele Simionato
  • Start date
M

Michele Simionato

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

$ cat x.py
"""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
 
P

Paolino

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')"
IiIiCmR1bW15ID0gJycnCgpzb21ldGhpbmcKaGVyZQonJycKIiIiCmltcG9ydCBkb2N0ZXN0OyBk
b2N0ZXN0LnRlc3Rtb2QoKQo=

Paolino





___________________________________
Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB
http://mail.yahoo.it
 
P

Peter Otten

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

$ cat x.py
"""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:

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

Peter
 
M

Michele Simionato

This is my file
$ python -c "print open('x.py').read().encode('base64')"
IiIiCj4+PiBkdW1teSA9ICcnJwpzb21ldGhpbmcKaGVyZQonJycKIiIiCmltcG9ydCBkb2N0ZXN0
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top