Repository navigation
fixed doctest for Bio.TogoWS - #2039
Conversation
| >>> for id in TogoWS.search_iter("pubmed", "diabetes+human", limit=10): | ||
| ... print("PubMed ID: %s" %id) # maybe fetch data with entry? | ||
| PubMed ID: 27374092 | ||
|
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Amended, Thank You.
There was a problem hiding this comment.
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:
>>> from Bio import TogoWS
>>> '20472643' in list(TogoWS.search_iter("pubmed", "togows"))
TrueHowever, 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 Report
@@ Coverage Diff @@
## master #2039 +/- ##
======================================
Coverage 84.9% 84.9%
======================================
Files 315 315
Lines 50543 50543
======================================
Hits 42916 42916
Misses 7627 7627
Continue to review full report at Codecov.
|
|
Note this has to be tested locally, because by default all the continuous integration tests are run with |
|
@peterjc I tested this locally: and: So I guess this can be merged. |
|
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
left a comment
There was a problem hiding this comment.
(Looks like I wrote this some time ago, but didn't click the submit button - I was having trouble under Python 3.7)
| >>> for id in TogoWS.search_iter("pubmed", "diabetes+human", limit=10): | ||
| ... print("PubMed ID: %s" %id) # maybe fetch data with entry? | ||
| PubMed ID: 27374092 | ||
|
|
There was a problem hiding this comment.
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:
>>> from Bio import TogoWS
>>> '20472643' in list(TogoWS.search_iter("pubmed", "togows"))
TrueHowever, 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?
|
@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. |
|
Thanks for the clarification. git remote add svalqui [email protected]:svalqui/biopython.git
git fetch svalqui
git checkout -t svalqui issue_1902_Bio_TogoWSWorks for me on Python 3.7 (although one of the other doctests fails, that's unrelated). |
This pull request addresses issue #1902
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.rstfile and understand that AppVeyor andTravisCI will be used to confirm the Biopython unit tests and
flake8stylechecks pass with these changes.
I have added my name to the alphabetical contributors listings in the files
NEWS.rstandCONTRIB.rstas part of this pull request, am listedalready, or do not wish to be listed. (This acknowledgement is optional.)