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 3 2541
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').re ad().encode('ba se64')"
IiIiCmR1bW15ID0 gJycnCgpzb21ldG hpbmcKaGVyZQonJ ycKIiIiCmltcG9y dCBkb2N0ZXN0OyB k
b2N0ZXN0LnRlc3R tb2QoKQo=
Paolino
_______________ _______________ _____
Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB http://mail.yahoo.it
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
This is my file
$ python -c "print open('x.py').re ad().encode('ba se64')"
IiIiCj4+PiBkdW1 teSA9ICcnJwpzb2 1ldGhpbmcKaGVyZ QonJycKIiIiCmlt cG9ydCBkb2N0ZXN 0
OyBkb2N0ZXN0LnR lc3Rtb2QoKQo=
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Edward K. Ream |
last post by:
Hi,
I am trying to run the following docstring using docutils.DocTestSuite:
"""
>>> s = "a\n \t\n\t\t \t\nb"
etc...
"""
However, docutils complains about "inconsistent leading whitespace". Well,
|
by: Christoph Zwerschke |
last post by:
I sometimes use triple quotes in order to produce snippets of multiline
code, like that:
if output == html:
snip = '''<html>
<head><title>Hello, World</title></head>
<body bgcolor="aqua"><h1>What's up?</h1>
</html>'''
else:
snip = 'Hello!'
|
by: Alan G Isaac |
last post by:
> python doctest.py -v
Running doctest.__doc__
Trying: .remove(42)
Expecting:
Traceback (most recent call last):
File "<stdin>", line 1, in ?
ValueError: list.remove(x): x not in list
ok
Trying: x = 12
Expecting: nothing
|
by: Brian van den Broek |
last post by:
Hi all,
I'm posting partly so my problem and solution might be more easily
found by google, and partly out of mere curiosity.
I've just spent a frustrating bit of time figuring out why pydoc
didn't extract a description from my module docstrings. Even though I
had a well formed docstring (one line, followed by a blank line,
followed by the rest of the docstring), when I ran Module docs, my
modules showed up as having "no description"....
|
by: 3KWA |
last post by:
Hi all,
I am wondering what is the standard doctest (test) practice for
functions who's returned value change all the time e.g. forex rate:
import urllib
def get_rate(symbol):
"""get_rate(symbol) connects to yahoo finance to return the rate of
symbol.
| |
by: so.intech |
last post by:
for example,
ret = 0;
for(i=0; i<3; i ++;)
{
for(j=0; j<4; j++;)
{
for(k=0; k<3; k++;)
{
for(m=0; m<4; m++;)
{
|
by: Candace |
last post by:
I have to write a program to find all Pythagorean triples for a right
triangle. I know that the squares of two sides of the triangle must equal
the square of the third (longest) side. However, I am not sure how to use a
triple-nested for...next loop to try all possibilities.
For instance, take a look at these numbers:
a 3 5 7 8 9 11
b 4 12 24 15 40 60
c 5 13 25 17 41 61
|
by: Stuart D. Gathman |
last post by:
I am trying to create a doctest test case for the following:
def quote_value(s):
"""Quote the value for a key-value pair in Received-SPF header field
if needed. No quoting needed for a dot-atom value.
'"abc\\\\\\\\def"'
'"abc..def"'
'""'
'"-all\\\\\\\\x00"'
|
by: thomas.guest |
last post by:
I'm not making progress with the following and would appreciate any
help.
Here's an interpreted Python session.
....
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'f' is not defined
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |