[Biopython-dev] Re: Post Biopython 1.62 release, clean-up after dropping Python 2.5
Sergei Lebedev
superbobry at gmail.com
Fri Aug 30 09:28:50 EDT 2013
Sure, a common pattern for a lot of BioPython modules seems to be:
# +from __future__ import print_function
def foo():
"""A docstring with print statement.
>>> print "foo"
foo
"""
print "Running foo ..."
# +print("Running foo ...")
if __name__ == "__main__":
import doctest
doctest.testmod()
where foo is some function, which uses print statement in its body. Since we want to switch from print statements to print function we replace print "Running foo ..." with a print() call and add from __future__ import ... to the beginning of the module.
What happens if we try to run the doctests after we've switched to print_function?
$ python /tmp/foo.py
**********************************************************************
File "/tmp/foo.py", line 7, in __main__.foo
Failed example:
print "foo"
Exception raised:
Traceback (most recent call last):
File ".../doctest.py", line 1254, in __run
compileflags, 1) in test.globs
File "<doctest __main__.foo[0]>", line 1
print "foo"
^
SyntaxError: invalid syntax
**********************************************************************
1 items had failures:
1 of 1 in __main__.foo
***Test Failed*** 1 failures.
So, enabling print_function makes doctests using print statement fail with a SyntaxError, as shown by the example above. Thus, if we want to get rid of print statement in the code we have no other choice but to do the same it in the doctests.
Sergei
On August 30, 2013 at 5:14:14 PM, Peter Cock (p.j.a.cock at googlemail.com) wrote:
On Fri, Aug 30, 2013 at 1:58 PM, Sergei Lebedev <superbobry at gmail.com> wrote:
>> (8) Excluding doctests and the Tutorial, use print function
>> rather than print statement. e.g. replace this:
>
> Unfortunately we cannot exclude doctests, because 'from __future__' import
> is module wide, thus the 'doctest.testmod()' will raise a SyntaxError on
> docstrings with print statement.
>
> Sergei
Could you clarify this? Does this cause a problem via:
[Tests]$ python run_tests.py doctest
If you have a small example, copy & paste the "git diff" output here.
Peter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.open-bio.org/pipermail/biopython-dev/attachments/20130830/8d297e64/attachment-0001.html>
More information about the Biopython-dev
mailing list