Skip to content

fixed doctest for Bio.TogoWS - #2039

Merged
peterjc merged 3 commits into
biopython:masterfrom
svalqui:issue_1902_Bio_TogoWS
May 29, 2019
Merged

peterjc merged 3 commits into
biopython:masterfrom
svalqui:issue_1902_Bio_TogoWS

Conversation

@svalqui

@svalqui svalqui commented Apr 30, 2019

Copy link
Copy Markdown
Contributor

This pull request addresses issue #1902

  • I have changed the query so it only returns one value, and added the import; with this the doctest works, however on an online query the result is variable, so this is fragile; If I extend the code to minimize errors, then it defies the purpose of been a clean simple example of how to use TogoWS.
    Looking forward to feedback.
  • I hereby agree to dual licence this and any previous contributions under both
    the Biopython License Agreement AND the BSD 3-Clause License.

  • I have read the CONTRIBUTING.rst file and understand that AppVeyor and
    TravisCI will be used to confirm the Biopython unit tests and flake8 style
    checks pass with these changes.

  • I have added my name to the alphabetical contributors listings in the files
    NEWS.rst and CONTRIB.rst as part of this pull request, am listed
    already, or do not wish to be listed. (This acknowledgement is optional.)

@svalqui
svalqui requested a review from peterjc as a code owner April 30, 2019 07:09
Comment thread Bio/TogoWS/__init__.py
>>> for id in TogoWS.search_iter("pubmed", "diabetes+human", limit=10):
... print("PubMed ID: %s" %id) # maybe fetch data with entry?
PubMed ID: 27374092

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to replace the id (27374092) with an ELLIPSIS (...) because the search result (and thus the first id) will change when new articles with this keywords will be added to Pubmed. The ELLIPSIS (three dots: ...) will match any output.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amended, Thank You.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still fails for me, ELLIPSIS in doctests are very fragile and I try to avoid them:

======================================================================
FAIL: search_iter (Bio.TogoWS)
Doctest: Bio.TogoWS.search_iter
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/doctest.py", line 2198, in runTest
    raise self.failureException(self.format_failure(new.getvalue()))
AssertionError: Failed doctest test for Bio.TogoWS.search_iter
  File "/Users/pc40583/repositories/biopython/build/lib.macosx-10.9-x86_64-3.7/Bio/TogoWS/__init__.py", line 181, in search_iter

----------------------------------------------------------------------
File "/Users/pc40583/repositories/biopython/build/lib.macosx-10.9-x86_64-3.7/Bio/TogoWS/__init__.py", line 193, in Bio.TogoWS.search_iter
Failed example:
    for id in search_iter("pubmed", "lung+cancer+drug", limit=10):
        print(id) # maybe fetch data with entry?
Expected nothing
Got:
    30974169
    30610878
    30345557
    30274116
    30254074
    30138906
    30131696
    29755098
    29732058
    29702190

This is what I meant about online tests being tricky - you have no control over which 10 results will be returned here over time. I didn't get 27374092 for example.

One option here is to do a much narrower search, where we (currently) expect to get a handful of results, and assert a known value is in the list. Like this example with Entrez:

https://github.com/biopython/biopython/blob/biopython-173/Doc/Tutorial/chapter_entrez.tex#L201

>>> from Bio import TogoWS
>>> '20472643' in list(TogoWS.search_iter("pubmed", "togows"))
True

However, I think the original for loop is more useful as an example. So I would go for an RST literal code block here:

You would use this function within a for loop, e.g.::

    from Bio import TogoWS
    for id in search_iter("pubmed", "lung+cancer+drug", limit=10):
        print(id) # maybe fetch data with entry?

@codecov

codecov Bot commented Apr 30, 2019 •

Copy link
Copy Markdown

Codecov Report

Merging #2039 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@          Coverage Diff           @@
##           master   #2039   +/-   ##
======================================
  Coverage    84.9%   84.9%           
======================================
  Files         315     315           
  Lines       50543   50543           
======================================
  Hits        42916   42916           
  Misses       7627    7627
Impacted Files Coverage Δ
Bio/TogoWS/__init__.py 16.55% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d311208...c5b2a1f. Read the comment docs.

@peterjc

peterjc commented May 14, 2019

Copy link
Copy Markdown
Member

Note this has to be tested locally, because by default all the continuous integration tests are run with --offline and will skip this.

@MarkusPiotrowski

Copy link
Copy Markdown
Contributor

@peterjc I tested this locally:

admin@Markus2 MINGW32 /biopython/tests (issue_1902_Bio_TogoWS)
$ python run_tests.py Bio.TogoWS
Python version: 2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 20:19:30) [MSC v.1500 32 bit (Intel)]
Operating system: nt win32
Bio.TogoWS docstring test ... ok
----------------------------------------------------------------------
Ran 1 test in 3.354 seconds


admin@Markus2 MINGW32 /biopython/tests (issue_1902_Bio_TogoWS)
$ python run_tests.py Bio.TogoWS.__init__
Python version: 2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 20:19:30) [MSC v.1500 32 bit (Intel)]
Operating system: nt win32
Bio.TogoWS.__init__ docstring test ... ok
----------------------------------------------------------------------
Ran 1 test in 2.762 seconds

and:

admin@Markus2 MINGW32 /biopython/tests (issue_1902_Bio_TogoWS)
$ python run_tests.py doctest
Bio docstring test ... ok
Bio.Affy docstring test ... ok
Bio.Affy.CelFile docstring test ... ok
...
Bio.TogoWS docstring test ... ok
...

So I guess this can be merged.

@peterjc

peterjc commented May 29, 2019

Copy link
Copy Markdown
Member

Could you try Python 3 as well? I think I had trouble on Python 3.7 (looks like I have a half finished review on GitHub, whoops).

@peterjc peterjc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Looks like I wrote this some time ago, but didn't click the submit button - I was having trouble under Python 3.7)

Comment thread Bio/TogoWS/__init__.py
>>> for id in TogoWS.search_iter("pubmed", "diabetes+human", limit=10):
... print("PubMed ID: %s" %id) # maybe fetch data with entry?
PubMed ID: 27374092

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still fails for me, ELLIPSIS in doctests are very fragile and I try to avoid them:

======================================================================
FAIL: search_iter (Bio.TogoWS)
Doctest: Bio.TogoWS.search_iter
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/doctest.py", line 2198, in runTest
    raise self.failureException(self.format_failure(new.getvalue()))
AssertionError: Failed doctest test for Bio.TogoWS.search_iter
  File "/Users/pc40583/repositories/biopython/build/lib.macosx-10.9-x86_64-3.7/Bio/TogoWS/__init__.py", line 181, in search_iter

----------------------------------------------------------------------
File "/Users/pc40583/repositories/biopython/build/lib.macosx-10.9-x86_64-3.7/Bio/TogoWS/__init__.py", line 193, in Bio.TogoWS.search_iter
Failed example:
    for id in search_iter("pubmed", "lung+cancer+drug", limit=10):
        print(id) # maybe fetch data with entry?
Expected nothing
Got:
    30974169
    30610878
    30345557
    30274116
    30254074
    30138906
    30131696
    29755098
    29732058
    29702190

This is what I meant about online tests being tricky - you have no control over which 10 results will be returned here over time. I didn't get 27374092 for example.

One option here is to do a much narrower search, where we (currently) expect to get a handful of results, and assert a known value is in the list. Like this example with Entrez:

https://github.com/biopython/biopython/blob/biopython-173/Doc/Tutorial/chapter_entrez.tex#L201

>>> from Bio import TogoWS
>>> '20472643' in list(TogoWS.search_iter("pubmed", "togows"))
True

However, I think the original for loop is more useful as an example. So I would go for an RST literal code block here:

You would use this function within a for loop, e.g.::

    from Bio import TogoWS
    for id in search_iter("pubmed", "lung+cancer+drug", limit=10):
        print(id) # maybe fetch data with entry?

@MarkusPiotrowski

Copy link
Copy Markdown
Contributor

@peterjc I think your review is for a former version. The 'trick' was here to finish the doctest with some non-empty printout line. Thus the actual doctest ends with:

    >>> for id in TogoWS.search_iter("pubmed", "diabetes+human", limit=10):
    ...     print("PubMed ID: %s" %id) # maybe fetch data with entry?
    PubMed ID: ...

In fact, without the last line (or just placing an ellipsis on the last line) this would fail.
Can you check the actual test on Python 3? I can also check later (on a different computer).

@peterjc

peterjc commented May 29, 2019

Copy link
Copy Markdown
Member

Thanks for the clarification.

git remote add svalqui [email protected]:svalqui/biopython.git
git fetch svalqui
git checkout -t svalqui issue_1902_Bio_TogoWS

Works for me on Python 3.7 (although one of the other doctests fails, that's unrelated).

@peterjc
peterjc merged commit 2186398 into biopython:master May 29, 2019
@svalqui
svalqui deleted the issue_1902_Bio_TogoWS branch July 17, 2019 00:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants