Skip to content

Commit 44a594d

Browse files
Add fixtures to conftest
1 parent 62458c5 commit 44a594d

File tree

2 files changed

+36
-33
lines changed

2 files changed

+36
-33
lines changed

tests/conftest.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import pathlib
2+
import shutil
3+
import gzip
4+
5+
import pytest
6+
7+
import sc2ts
8+
9+
10+
@pytest.fixture
11+
def data_cache():
12+
cache_path = pathlib.Path("tests/data/cache")
13+
if not cache_path.exists():
14+
cache_path.mkdir()
15+
return cache_path
16+
17+
18+
@pytest.fixture
19+
def alignments_fasta(data_cache):
20+
cache_path = data_cache / "alignments.fasta"
21+
if not cache_path.exists():
22+
with gzip.open("tests/data/alignments.fasta.gz") as src:
23+
with open(cache_path, "wb") as dest:
24+
shutil.copyfileobj(src, dest)
25+
return cache_path
26+
27+
28+
@pytest.fixture
29+
def alignments_store(data_cache, alignments_fasta):
30+
cache_path = data_cache / "alignments.db"
31+
if not cache_path.exists():
32+
with sc2ts.AlignmentStore(cache_path, "a") as a:
33+
fasta = sc2ts.core.FastaReader(alignments_fasta)
34+
a.append(fasta, show_progress=False)
35+
return sc2ts.AlignmentStore(cache_path)

tests/test_alignments.py

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
import pathlib
2-
import shutil
3-
import gzip
4-
51
import numpy as np
62
import pytest
73
from numpy.testing import assert_array_equal
@@ -10,34 +6,6 @@
106
from sc2ts import core
117

128

13-
@pytest.fixture
14-
def data_cache():
15-
cache_path = pathlib.Path("tests/data/cache")
16-
if not cache_path.exists():
17-
cache_path.mkdir()
18-
return cache_path
19-
20-
21-
@pytest.fixture
22-
def alignments_fasta(data_cache):
23-
cache_path = data_cache / "alignments.fasta"
24-
if not cache_path.exists():
25-
with gzip.open("tests/data/alignments.fasta.gz") as src:
26-
with open(cache_path, "wb") as dest:
27-
shutil.copyfileobj(src, dest)
28-
return cache_path
29-
30-
31-
@pytest.fixture
32-
def alignments_store(data_cache, alignments_fasta):
33-
cache_path = data_cache / "alignments.db"
34-
if not cache_path.exists():
35-
with sa.AlignmentStore(cache_path, "a") as a:
36-
fasta = core.FastaReader(alignments_fasta)
37-
a.append(fasta, show_progress=False)
38-
return sa.AlignmentStore(cache_path)
39-
40-
419
class TestAlignmentsStore:
4210
def test_info(self, alignments_store):
4311
assert "contains" in str(alignments_store)
@@ -117,7 +85,7 @@ def test_lowercase_nucleotide_missing(self, hap):
11785
[0, -2],
11886
],
11987
)
120-
def test_examples(self, a):
88+
def test_error__examples(self, a):
12189
with pytest.raises(ValueError):
12290
sa.decode_alignment(np.array(a))
12391

0 commit comments

Comments
 (0)