-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathtest_fastadir.py
61 lines (39 loc) · 1.38 KB
/
test_fastadir.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import shutil
import tempfile
import pytest
from biocommons.seqrepo.fastadir import FastaDir
def test_write_reread():
# PY2BAGGAGE: Switch to TemporaryDirectory
tmpdir = tempfile.mkdtemp(prefix="seqrepo_pytest_")
fd = FastaDir(tmpdir, writeable=True)
assert fd.store("1", "seq1") == "1"
assert fd.store("2", "seq2") == "2"
fd.commit()
assert fd.store("3", "seq3") == "3"
assert fd.fetch("1") == "seq1"
assert fd.fetch("2") == "seq2"
assert fd.fetch("3") == "seq3"
assert "3" in fd
assert len(fd) == 3
assert fd["3"] == "seq3", "test __getitem__ lookup"
with pytest.raises(KeyError):
fd.fetch("bogus")
shutil.rmtree(tmpdir)
if __name__ == "__main__":
import logging
logging.basicConfig(level=logging.DEBUG)
test_write_reread()
def test_schema_version():
tmpdir = tempfile.mkdtemp(prefix="seqrepo_pytest_")
orig_schema_version = FastaDir.schema_version
with pytest.raises(RuntimeError):
FastaDir.schema_version = lambda x: -1
fd = FastaDir(tmpdir, writeable=True)
FastaDir.schema_version = orig_schema_version
def test_writeability():
tmpdir = tempfile.mkdtemp(prefix="seqrepo_pytest_")
fd = FastaDir(tmpdir, writeable=True)
with pytest.raises(RuntimeError):
fd._writeable = False
fd.store("NC_000001.11", "TGGTGGCACGCGCTTGTAGT")
fd._writeable = True