Skip to content

Commit

Permalink
Add run and runtmp pytest fixtures. (#1487)
Browse files Browse the repository at this point in the history
* add 'run' and 'runtmp' test fixtures

* remove unnecessary track_abundance fixture call

* restore original;
  • Loading branch information
ctb authored Apr 28, 2021
1 parent e2dbe24 commit f128e9b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
16 changes: 13 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
7 changes: 2 additions & 5 deletions tests/sourmash_tst_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"Various utilities used by sourmash tests."

import sys
import os
import tempfile
Expand All @@ -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 (
Expand Down Expand Up @@ -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."
Expand Down
20 changes: 9 additions & 11 deletions tests/test_sourmash.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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():
Expand Down

0 comments on commit f128e9b

Please sign in to comment.