|
4 | 4 |
|
5 | 5 | from nibabel.optpkg import optional_package
|
6 | 6 |
|
7 |
| -from ..utils import find_private_section |
| 7 | +from ..utils import find_private_section as fps |
8 | 8 | from .test_dicomwrappers import DATA, DATA_PHILIPS
|
9 | 9 |
|
10 | 10 | pydicom, _, setup_module = optional_package('pydicom')
|
|
13 | 13 | def test_find_private_section_real():
|
14 | 14 | # Find section containing named private creator information
|
15 | 15 | # On real data first
|
16 |
| - assert find_private_section(DATA, 0x29, 'SIEMENS CSA HEADER') == 0x1000 |
17 |
| - assert find_private_section(DATA, 0x29, 'SIEMENS MEDCOM HEADER2') == 0x1100 |
18 |
| - assert find_private_section(DATA_PHILIPS, 0x29, 'SIEMENS CSA HEADER') == None |
19 |
| - # Make fake datasets |
| 16 | + assert fps(DATA, 0x29, 'SIEMENS CSA HEADER') == 0x1000 |
| 17 | + assert fps(DATA, 0x29, b'SIEMENS CSA HEADER') == 0x1000 |
| 18 | + assert fps(DATA, 0x29, re.compile('SIEMENS CSA HEADER')) == 0x1000 |
| 19 | + assert fps(DATA, 0x29, 'NOT A HEADER') is None |
| 20 | + assert fps(DATA, 0x29, 'SIEMENS MEDCOM HEADER2') == 0x1100 |
| 21 | + assert fps(DATA_PHILIPS, 0x29, 'SIEMENS CSA HEADER') == None |
| 22 | + |
| 23 | + |
| 24 | +def test_find_private_section_fake(): |
| 25 | + # Make and test fake datasets |
20 | 26 | ds = pydicom.dataset.Dataset({})
|
| 27 | + assert fps(ds, 0x11, 'some section') is None |
21 | 28 | ds.add_new((0x11, 0x10), 'LO', b'some section')
|
22 |
| - assert find_private_section(ds, 0x11, 'some section') == 0x1000 |
23 |
| - ds.add_new((0x11, 0x11), 'LO', b'anther section') |
| 29 | + assert fps(ds, 0x11, 'some section') == 0x1000 |
| 30 | + ds.add_new((0x11, 0x11), 'LO', b'another section') |
24 | 31 | ds.add_new((0x11, 0x12), 'LO', b'third section')
|
25 |
| - assert find_private_section(ds, 0x11, 'third section') == 0x1200 |
26 |
| - # Wrong 'OB' is acceptable for VM (should be 'LO') |
| 32 | + assert fps(ds, 0x11, 'third section') == 0x1200 |
| 33 | + # Technically incorrect 'OB' is acceptable for VM (should be 'LO') |
27 | 34 | ds.add_new((0x11, 0x12), 'OB', b'third section')
|
28 |
| - assert find_private_section(ds, 0x11, 'third section') == 0x1200 |
| 35 | + assert fps(ds, 0x11, 'third section') == 0x1200 |
29 | 36 | # Anything else not acceptable
|
30 | 37 | ds.add_new((0x11, 0x12), 'PN', b'third section')
|
31 |
| - assert find_private_section(ds, 0x11, 'third section') is None |
| 38 | + assert fps(ds, 0x11, 'third section') is None |
32 | 39 | # The input (DICOM value) can be a string insteal of bytes
|
33 | 40 | ds.add_new((0x11, 0x12), 'LO', 'third section')
|
34 |
| - assert find_private_section(ds, 0x11, 'third section') == 0x1200 |
| 41 | + assert fps(ds, 0x11, 'third section') == 0x1200 |
35 | 42 | # Search can be bytes as well as string
|
36 | 43 | ds.add_new((0x11, 0x12), 'LO', b'third section')
|
37 |
| - assert find_private_section(ds, 0x11, b'third section') == 0x1200 |
| 44 | + assert fps(ds, 0x11, b'third section') == 0x1200 |
38 | 45 | # Search with string or bytes must be exact
|
39 |
| - assert find_private_section(ds, 0x11, b'third sectio') is None |
40 |
| - assert find_private_section(ds, 0x11, 'hird sectio') is None |
| 46 | + assert fps(ds, 0x11, b'third sectio') is None |
| 47 | + assert fps(ds, 0x11, 'hird sectio') is None |
41 | 48 | # The search can be a regexp
|
42 |
| - assert find_private_section(ds, 0x11, re.compile(r'third\Wsectio[nN]')) == 0x1200 |
| 49 | + assert fps(ds, 0x11, re.compile(r'third\Wsectio[nN]')) == 0x1200 |
43 | 50 | # No match -> None
|
44 |
| - assert find_private_section(ds, 0x11, re.compile(r'not third\Wsectio[nN]')) is None |
| 51 | + assert fps(ds, 0x11, re.compile(r'not third\Wsectio[nN]')) is None |
45 | 52 | # If there are gaps in the sequence before the one we want, that is OK
|
46 | 53 | ds.add_new((0x11, 0x13), 'LO', b'near section')
|
47 |
| - assert find_private_section(ds, 0x11, 'near section') == 0x1300 |
| 54 | + assert fps(ds, 0x11, 'near section') == 0x1300 |
48 | 55 | ds.add_new((0x11, 0x15), 'LO', b'far section')
|
49 |
| - assert find_private_section(ds, 0x11, 'far section') == 0x1500 |
| 56 | + assert fps(ds, 0x11, 'far section') == 0x1500 |
| 57 | + # More than one match - find the first. |
| 58 | + assert fps(ds, 0x11, re.compile('(another|third) section')) == 0x1100 |
| 59 | + # The signalling element number must be <= 0xFF |
| 60 | + ds = pydicom.dataset.Dataset({}) |
| 61 | + ds.add_new((0x11, 0xFF), 'LO', b'some section') |
| 62 | + assert fps(ds, 0x11, 'some section') == 0xFF00 |
| 63 | + ds = pydicom.dataset.Dataset({}) |
| 64 | + ds.add_new((0x11, 0x100), 'LO', b'some section') |
| 65 | + assert fps(ds, 0x11, 'some section') is None |
0 commit comments