doctest Hassles!
Douglas Garstang
doug at pobox.com
Tue Mar 12 12:28:11 EST 2002
I posted a question yesterday about how to get doctest to interpret
output from the execution of an external program. It was suggested I
use:
ls=os.popen("/bin/ls","r").read()
instead of trying to use spawnv. Well, when I print the value of ls, I
get:
'
example.py
example.pyc
tester.py
'
Notice the blank line at the end. Where did that come from? There
isn't a file with no name in my directory, so why would it print an
empty line? Also, why is the output in ONE column instead of across
the screen (as in a normal ls) when spawnv is used? All I did was
print the output of the ls command, but the output is different.
Now, in my code I have:
def tester3():
"""
>>> import os
>>> ls=os.popen("/bin/ls","r").read()
>>> print ls
example.py
example.pyc
tester.py
"""
It ignores the blank line at the end, as the docs say it will. On a
side note, I've had this problem before with python, trying to read
text config files. As soon as it hit an empty line, reading would
stop! Huh?
So, as a result, it ignores the empty line on the expect, but gets it
on the output, and the test fails!
What am I missing here? I would imagine that executing external
programs is central to testing, but it seems to be _really_ difficult.
More information about the Python-list
mailing list