5
5
from os .path import join as pjoin , dirname
6
6
from io import BytesIO
7
7
from ..testing import suppress_warnings
8
+ import sqlite3
8
9
9
10
with suppress_warnings ():
10
11
from .. import dft
@@ -29,6 +30,24 @@ def setUpModule():
29
30
raise unittest .SkipTest ('Need pydicom for dft tests, skipping' )
30
31
31
32
33
+ class Test_DBclass :
34
+ """Some tests on the database manager class that don't get exercised through the API"""
35
+ def setup_method (self ):
36
+ self ._db = dft ._DB (fname = ":memory:" , verbose = False )
37
+
38
+ def test_repr (self ):
39
+ assert repr (self ._db ) == "<DFT ':memory:'>"
40
+
41
+ def test_cursor_conflict (self ):
42
+ rwc = self ._db .readwrite_cursor
43
+ statement = ("INSERT INTO directory (path, mtime) VALUES (?, ?)" , ("/tmp" , 0 ))
44
+ with pytest .raises (sqlite3 .IntegrityError ):
45
+ # Whichever exits first will commit and make the second violate uniqueness
46
+ with rwc () as c1 , rwc () as c2 :
47
+ c1 .execute (* statement )
48
+ c2 .execute (* statement )
49
+
50
+
32
51
@pytest .fixture
33
52
def db (monkeypatch ):
34
53
"""Build a dft database in memory to avoid cross-process races
@@ -41,20 +60,24 @@ def db(monkeypatch):
41
60
def test_init (db ):
42
61
dft .clear_cache ()
43
62
dft .update_cache (data_dir )
63
+ # Verify a second update doesn't crash
64
+ dft .update_cache (data_dir )
44
65
45
66
46
67
def test_study (db ):
47
- studies = dft .get_studies (data_dir )
48
- assert len (studies ) == 1
49
- assert (studies [0 ].uid ==
50
- '1.3.12.2.1107.5.2.32.35119.30000010011408520750000000022' )
51
- assert studies [0 ].date == '20100114'
52
- assert studies [0 ].time == '121314.000000'
53
- assert studies [0 ].comments == 'dft study comments'
54
- assert studies [0 ].patient_name == 'dft patient name'
55
- assert studies [0 ].patient_id == '1234'
56
- assert studies [0 ].patient_birth_date == '19800102'
57
- assert studies [0 ].patient_sex == 'F'
68
+ # First pass updates the cache, second pass reads it out
69
+ for base_dir in (data_dir , None ):
70
+ studies = dft .get_studies (base_dir )
71
+ assert len (studies ) == 1
72
+ assert (studies [0 ].uid ==
73
+ '1.3.12.2.1107.5.2.32.35119.30000010011408520750000000022' )
74
+ assert studies [0 ].date == '20100114'
75
+ assert studies [0 ].time == '121314.000000'
76
+ assert studies [0 ].comments == 'dft study comments'
77
+ assert studies [0 ].patient_name == 'dft patient name'
78
+ assert studies [0 ].patient_id == '1234'
79
+ assert studies [0 ].patient_birth_date == '19800102'
80
+ assert studies [0 ].patient_sex == 'F'
58
81
59
82
60
83
def test_series (db ):
@@ -83,10 +106,6 @@ def test_storage_instances(db):
83
106
'1.3.12.2.1107.5.2.32.35119.2010011420300180088599504.1' )
84
107
85
108
86
- def test_storage_instance (db ):
87
- pass
88
-
89
-
90
109
@unittest .skipUnless (have_pil , 'could not import PIL.Image' )
91
110
def test_png (db ):
92
111
studies = dft .get_studies (data_dir )
0 commit comments