Skip to content

Commit 32e02d7

Browse files
committed
TEST: Create fresh in-memory database for each dft unit test
1 parent b84e0e1 commit 32e02d7

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

nibabel/tests/test_dft.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,21 @@ def setUpModule():
2929
raise unittest.SkipTest('Need pydicom for dft tests, skipping')
3030

3131

32-
def test_init():
32+
@pytest.fixture
33+
def db(monkeypatch):
34+
"""Build a dft database in memory to avoid cross-process races
35+
and not modify the host filesystem."""
36+
database = dft._DB(fname=":memory:")
37+
monkeypatch.setattr(dft, "DB", database)
38+
yield database
39+
40+
41+
def test_init(db):
3342
dft.clear_cache()
3443
dft.update_cache(data_dir)
3544

3645

37-
def test_study():
46+
def test_study(db):
3847
studies = dft.get_studies(data_dir)
3948
assert len(studies) == 1
4049
assert (studies[0].uid ==
@@ -48,7 +57,7 @@ def test_study():
4857
assert studies[0].patient_sex == 'F'
4958

5059

51-
def test_series():
60+
def test_series(db):
5261
studies = dft.get_studies(data_dir)
5362
assert len(studies[0].series) == 1
5463
ser = studies[0].series[0]
@@ -62,7 +71,7 @@ def test_series():
6271
assert ser.bits_stored == 12
6372

6473

65-
def test_storage_instances():
74+
def test_storage_instances(db):
6675
studies = dft.get_studies(data_dir)
6776
sis = studies[0].series[0].storage_instances
6877
assert len(sis) == 2
@@ -74,19 +83,19 @@ def test_storage_instances():
7483
'1.3.12.2.1107.5.2.32.35119.2010011420300180088599504.1')
7584

7685

77-
def test_storage_instance():
86+
def test_storage_instance(db):
7887
pass
7988

8089

8190
@unittest.skipUnless(have_pil, 'could not import PIL.Image')
82-
def test_png():
91+
def test_png(db):
8392
studies = dft.get_studies(data_dir)
8493
data = studies[0].series[0].as_png()
8594
im = PImage.open(BytesIO(data))
8695
assert im.size == (256, 256)
8796

8897

89-
def test_nifti():
98+
def test_nifti(db):
9099
studies = dft.get_studies(data_dir)
91100
data = studies[0].series[0].as_nifti()
92101
assert len(data) == 352 + 2 * 256 * 256 * 2

0 commit comments

Comments
 (0)