|
3 | 3 |
|
4 | 4 | from os.path import join as pjoin, dirname
|
5 | 5 | import StringIO
|
6 |
| -import PIL.Image |
7 |
| -from nose.tools import assert_true, assert_false, assert_equal, assert_raises |
| 6 | + |
| 7 | +import numpy as np |
| 8 | + |
8 | 9 | from .. import dft
|
9 | 10 | from .. import nifti1
|
10 | 11 |
|
| 12 | +from nose.tools import (assert_true, assert_false, assert_equal, assert_raises) |
| 13 | + |
| 14 | +# Shield optional package imports |
| 15 | +from ..optpkg import optional_package |
| 16 | +# setup_module will raise SkipTest if no dicom to import |
| 17 | +dicom, have_dicom, setup_module = optional_package('dicom') |
| 18 | +PImage, have_pil, _ = optional_package('PIL.Image') |
| 19 | +pil_test = np.testing.dec.skipif(not have_pil, 'could not import PIL.Image') |
| 20 | + |
11 | 21 | data_dir = pjoin(dirname(__file__), 'data')
|
12 | 22 |
|
| 23 | + |
13 | 24 | def test_init():
|
14 | 25 | dft.clear_cache()
|
15 | 26 | dft.update_cache(data_dir)
|
16 |
| - return |
| 27 | + |
17 | 28 |
|
18 | 29 | def test_study():
|
19 | 30 | studies = dft.get_studies(data_dir)
|
@@ -42,32 +53,35 @@ def test_series():
|
42 | 53 | assert_equal(ser.bits_allocated, 16)
|
43 | 54 | assert_equal(ser.bits_stored, 12)
|
44 | 55 |
|
| 56 | + |
45 | 57 | def test_storage_instances():
|
46 | 58 | studies = dft.get_studies(data_dir)
|
47 | 59 | sis = studies[0].series[0].storage_instances
|
48 | 60 | assert_equal(len(sis), 2)
|
49 | 61 | assert_equal(sis[0].instance_number, 1)
|
50 | 62 | assert_equal(sis[1].instance_number, 2)
|
51 |
| - assert_equal(sis[0].uid, |
| 63 | + assert_equal(sis[0].uid, |
52 | 64 | '1.3.12.2.1107.5.2.32.35119.2010011420300180088599504.0')
|
53 |
| - assert_equal(sis[1].uid, |
| 65 | + assert_equal(sis[1].uid, |
54 | 66 | '1.3.12.2.1107.5.2.32.35119.2010011420300180088599504.1')
|
55 | 67 |
|
| 68 | + |
56 | 69 | def test_storage_instance():
|
57 |
| - return |
| 70 | + pass |
58 | 71 |
|
| 72 | + |
| 73 | +@pil_test |
59 | 74 | def test_png():
|
60 | 75 | studies = dft.get_studies(data_dir)
|
61 | 76 | data = studies[0].series[0].as_png()
|
62 |
| - im = PIL.Image.open(StringIO.StringIO(data)) |
| 77 | + im = PImage.open(StringIO.StringIO(data)) |
63 | 78 | assert_equal(im.size, (256, 256))
|
64 |
| - return |
| 79 | + |
65 | 80 |
|
66 | 81 | def test_nifti():
|
67 | 82 | studies = dft.get_studies(data_dir)
|
68 | 83 | data = studies[0].series[0].as_nifti()
|
69 | 84 | assert_equal(len(data), 352 + 2*256*256*2)
|
70 | 85 | h = nifti1.Nifti1Header(data[:348])
|
71 | 86 | assert_equal(h.get_data_shape(), (256, 256, 2))
|
72 |
| - return |
73 | 87 |
|
0 commit comments