Skip to content

Commit

Permalink
Close SearchIO indexes in doctests to avoid ResourceWarning
Browse files Browse the repository at this point in the history
  • Loading branch information
peterjc committed Apr 8, 2013
1 parent 4cfe67b commit 0e4e388
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Bio/SearchIO/__init__.py
Expand Up @@ -448,6 +448,7 @@ def index(filename, format=None, key_function=None, **kwargs):
['gi|156630997:105-1160', 'gi|195230749:301-1383', ..., 'gi|53729353:216-1313'] ['gi|156630997:105-1160', 'gi|195230749:301-1383', ..., 'gi|53729353:216-1313']
>>> search_idx['gi|195230749:301-1383'] >>> search_idx['gi|195230749:301-1383']
QueryResult(id='gi|195230749:301-1383', 5 hits) QueryResult(id='gi|195230749:301-1383', 5 hits)
>>> search_idx.close()
If the file is BGZF compressed, this is detected automatically. Ordinary If the file is BGZF compressed, this is detected automatically. Ordinary
GZIP files are not supported: GZIP files are not supported:
Expand All @@ -458,6 +459,7 @@ def index(filename, format=None, key_function=None, **kwargs):
SearchIO.index('Blast/wnts.xml.bgz', 'blast-xml', key_function=None) SearchIO.index('Blast/wnts.xml.bgz', 'blast-xml', key_function=None)
>>> search_idx['gi|195230749:301-1383'] >>> search_idx['gi|195230749:301-1383']
QueryResult(id='gi|195230749:301-1383', 5 hits) QueryResult(id='gi|195230749:301-1383', 5 hits)
>>> search_idx.close()
You can supply a custom callback function to alter the default identifier You can supply a custom callback function to alter the default identifier
string. This function should accept as its input the QueryResult ID string string. This function should accept as its input the QueryResult ID string
Expand All @@ -472,6 +474,7 @@ def index(filename, format=None, key_function=None, **kwargs):
['156630997:105-1160', ..., '371502086:108-1205', '53729353:216-1313'] ['156630997:105-1160', ..., '371502086:108-1205', '53729353:216-1313']
>>> search_idx['156630997:105-1160'] >>> search_idx['156630997:105-1160']
QueryResult(id='gi|156630997:105-1160', 5 hits) QueryResult(id='gi|156630997:105-1160', 5 hits)
>>> search_idx.close()
Note that the callback function does not change the QueryResult's ID value. Note that the callback function does not change the QueryResult's ID value.
It only changes the key value used to retrieve the associated QueryResult. It only changes the key value used to retrieve the associated QueryResult.
Expand Down

0 comments on commit 0e4e388

Please sign in to comment.