Permalink
Browse files

Fix doctest helper function

The idea of the helper function is to allow you to edit any module,
for example Bio/Align/__init__.py, and then run its doctests in situ.
This should work from the Biopython root, Bio, Bio/Align, Bio/Tests/,
etc.

The old code was wrongly defaulting to the __file__ value of the
Bio/_utilts.py but that could give you the location of an installed
Biopython. This now defaults to the current directory.
  • Loading branch information...
1 parent dfb082f commit d9e4a40c93ce582c6ac09036b442c841c6705c43 @peterjc peterjc committed Dec 30, 2012
Showing with 21 additions and 22 deletions.
  1. +21 −22 Bio/_utils.py
View
@@ -57,33 +57,32 @@ def find_test_dir(start_dir=None):
"""Finds the absolute path of Biopython's Tests directory.
Arguments:
- start_dir -- Initial directory to begin lookup.
+ start_dir -- Initial directory to begin lookup (default to current dir)
If the directory is not found up the filesystem's root directory, an
exception will be raised.
"""
- # no callbacks in function signatures!
- # defaults to the current _utils directory
- if start_dir is None:
- start_dir = os.path.dirname(os.path.abspath(__file__))
-
- # raise error if search goes all the way to root without results
- # to prevent infinite loop
- # this happens when the Bio directory is not a parent directory of the
- # running module
- if start_dir == os.path.dirname(start_dir):
- raise IOError("Biopython directory not found")
-
- parent, cur = os.path.split(start_dir)
- if cur == MOD_DIR:
- target_dir = os.path.join(parent, TEST_DIR)
- assert os.path.isdir(target_dir), \
- "Directory %r not found in Biopython's test directory" % \
- TEST_DIR
- return target_dir
-
- return find_test_dir(start_dir=parent)
+ if not start_dir:
+ # no callbacks in function signatures!
+ # defaults to the current directory
+ # (using __file__ would give the installed Biopython)
+ start_dir = "."
+
+ target = os.path.abspath(start_dir)
+ while True:
+ if os.path.isdir(os.path.join(target, MOD_DIR)) \
+ and os.path.isdir(os.path.join(target, TEST_DIR)):
+ #Good, we're in the Biopython root now
+ return os.path.abspath(os.path.join(target, TEST_DIR))
+ #Recurse up the tree
+ #TODO - Test this on Windows
+ new, tmp = os.path.split(target)
+ if target == new:
+ #Reached root
+ break
+ target = new
+ raise ValueError("Not within Biopython source tree: %r" % os.path.abspath(start_dir))
def run_doctest(target_dir=None, *args, **kwargs):

0 comments on commit d9e4a40

Please sign in to comment.