diff --git a/tests/conftest.py b/tests/conftest.py index 91a12dd0a9..f4badac793 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,14 +1,24 @@ import os -import matplotlib.pyplot as plt -plt.rcParams.update({'figure.max_open_warning': 0}) - from hypothesis import settings, Verbosity import pytest import matplotlib.pyplot as plt plt.rcParams.update({'figure.max_open_warning': 0}) +from sourmash_tst_utils import TempDirectory, RunnerContext + + +@pytest.fixture +def runtmp(): + with TempDirectory() as location: + yield RunnerContext(location) + + +@pytest.fixture +def run(): + yield RunnerContext(os.getcwd()) + @pytest.fixture(params=[True, False]) def track_abundance(request): diff --git a/tests/sourmash_tst_utils.py b/tests/sourmash_tst_utils.py index 3c84ce1f59..2ab0175e55 100644 --- a/tests/sourmash_tst_utils.py +++ b/tests/sourmash_tst_utils.py @@ -1,5 +1,4 @@ "Various utilities used by sourmash tests." - import sys import os import tempfile @@ -12,10 +11,7 @@ from pkg_resources import Requirement, resource_filename, ResolutionError import traceback from io import open # pylint: disable=redefined-builtin -try: - from StringIO import StringIO -except ImportError: - from io import StringIO +from io import StringIO SIG_FILES = [os.path.join('demo', f) for f in ( @@ -193,6 +189,7 @@ def run_sourmash(self, *args, **kwargs): raise ValueError(self) return self.last_result + sourmash = run_sourmash def run(self, scriptname, *args, **kwargs): "Run a script with the given arguments." diff --git a/tests/test_sourmash.py b/tests/test_sourmash.py index 8d6009c0f2..51c7c8b427 100644 --- a/tests/test_sourmash.py +++ b/tests/test_sourmash.py @@ -859,15 +859,14 @@ def test_gather_query_db_md5_ambiguous(c): assert "Error! Multiple signatures start with md5 '1'" in err -@utils.in_tempdir -def test_gather_lca_db(c): +def test_gather_lca_db(runtmp): # can we do a 'sourmash gather' on an LCA database? query = utils.get_test_data('47+63.fa.sig') lca_db = utils.get_test_data('lca/47+63.lca.json') - c.run_sourmash('gather', query, lca_db) - print(c) - assert 'NC_009665.1 Shewanella baltica OS185' in str(c.last_result.out) + runtmp.sourmash('gather', query, lca_db) + print(runtmp) + assert 'NC_009665.1 Shewanella baltica OS185' in str(runtmp.last_result.out) @utils.in_tempdir @@ -1443,19 +1442,18 @@ def test_search_containment_s10(): assert '16.7%' in out -@utils.in_thisdir -def test_search_containment_s10_no_max(c): +def test_search_containment_s10_no_max(run): # check --containment for s10/s10-small q1 = utils.get_test_data('scaled/genome-s10.fa.gz.sig') q2 = utils.get_test_data('scaled/genome-s10-small.fa.gz.sig') with pytest.raises(ValueError) as exc: - c.run_sourmash('search', q1, q2, '--containment', + run.run_sourmash('search', q1, q2, '--containment', '--max-containment') - print(c.last_result.out) - print(c.last_result.err) - assert "ERROR: cannot specify both --containment and --max-containment!" in c.last_result.err + print(run.last_result.out) + print(run.last_result.err) + assert "ERROR: cannot specify both --containment and --max-containment!" in run.last_result.err def test_search_max_containment_s10_pairwise():