-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add 'testseq' function #1306
base: master
Are you sure you want to change the base?
Add 'testseq' function #1306
Conversation
Tests/run_tests.py
Outdated
# Skip doctest for all modules outside of 'Bio' package prior to Python 3.3 | ||
if float(sys.version[:3]) < 3.3: | ||
for i, name in enumerate(DOCTEST_MODULES): | ||
if is_outside_bio(name): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the extra function is needed, how about if not name.split(".", 1)[0].startswith("Bio"):
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. Will implement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hang on, on reflection this would be clearer: if not name.startswith(("Bio.", "BioSQL.")):
Note this is passing a tuple of two elements as the argument to the starts-with method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fewer operations in fewer keystrokes. Awesome!
I will wait until the CI tests are finished before I commit anything further.
Tests/run_tests.py
Outdated
@@ -70,6 +70,13 @@ def is_numpy(): | |||
return False | |||
|
|||
|
|||
def is_outside_bio(name): | |||
name = name.split(".") | |||
if "Bio" in name[0]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd use name[0].startswith("Bio")
or maybe even name[0] in ["Bio", "BioSQL"]
to be explicit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See later comment on where this function was being used.
2. Remove reference to 'ModuleNotFoundError' 3. Simplify 'manually_import' function for only python 2.7
Codecov Report
@@ Coverage Diff @@
## master #1306 +/- ##
==========================================
+ Coverage 83.36% 84.24% +0.88%
==========================================
Files 317 319 +2
Lines 48642 48912 +270
==========================================
+ Hits 40551 41208 +657
+ Misses 8091 7704 -387
Continue to review full report at Codecov.
|
Alright! Done. Unless anyone has other concerns? I ended up removing a lot of the code from the "manually_import" function since it just isn't necessary after python version 3.3. |
Tests/run_tests.py
Outdated
@@ -165,6 +166,12 @@ def is_numpy(): | |||
DOCTEST_MODULES.remove("Bio.SeqIO") | |||
DOCTEST_MODULES.remove("Bio.SearchIO") | |||
|
|||
# Skip doctests for all modules outside Bio & BioSQL prior to Python 3.3 | |||
if float(sys.version[:3]) < 3.3: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I should have spotted this earlier - you should not assume you can break up the version string like that.
Instead use sys.version_info
which is a (named) tuple, i.e. something like this should work?
if sys.version_info < (3, 3):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a problem.
The style checks failed on Travis, but it was not your fault:
Its been fixed in c759829 If you are comfortable with the Because of the namespace and import issues, I'm going to ask for a second opinion before merging this... http://mailman.open-bio.org/pipermail/biopython-dev/2017-July/021808.html |
module_path = os.path.join(module_path, step) | ||
name = name[-1][:-3] | ||
import imp | ||
return imp.load_source(name, module_path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although the method is hacky, I can see it's utility. As more code is added to the "Scripts" directory will we need to call this method from other tests in the "Tests" directory? Would it be more suitable to move this method to a generic "utils" module?
I just see that this can become a common issue with code added to Scripts directory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we do end up with more code in Scripts/
being tested like this, then that seems like a good idea. Right now having the code here seems fine to me.
Adam Kurkiewicz on the mailing list http://mailman.open-bio.org/pipermail/biopython-dev/2017-July/021813.html reports a stochastic failure:
|
Everything in this pull request has been discussed earlier with the exception of the very last item. I have wrapped the 'manually_import' function in a try/except block. My reason for doing this is below:
Python has a built-in import utility module that gives access to import internals. Over the last few versions of python, this built-in module has gone through several re-works. My concern is that it will be changed further in the future. If that happens, the 'unit test will cause an import error.
Since importing works fine in Python 3.3 and beyond, I have wrapped the call to the "manually_import" function in a try/except block. The unit test will now attempt to import the module normally before it tries to use the "manually_import" function.
This change will allow the unit test to continue working regardless of whether the import utility module is re-worked in subsequent versions of python.