|
26 | 26 | DATA_PATH = pjoin(dirname(__file__), 'data') |
27 | 27 |
|
28 | 28 |
|
29 | | -def test_analyze_detection(): |
30 | | - # Test detection of Analyze, Nifti1 and Nifti2 |
31 | | - # Algorithm is as described in loadsave:which_analyze_type |
32 | | - def wat(hdr): |
33 | | - all_analyze_header_klasses = [Nifti1Header, Nifti2Header, |
34 | | - AnalyzeHeader] |
35 | | - for klass in all_analyze_header_klasses: |
36 | | - try: |
37 | | - if klass.may_contain_header(hdr.binaryblock): |
38 | | - return klass |
39 | | - else: |
40 | | - print('checked completed, but failed.') |
41 | | - except ValueError as ve: |
42 | | - print(ve) |
43 | | - continue |
44 | | - return None |
45 | | - # return nils.which_analyze_type(hdr.binaryblock) |
46 | | - |
47 | | - n1_hdr = Nifti1Header(b'\0' * 348, check=False) |
48 | | - n2_hdr = Nifti2Header(b'\0' * 540, check=False) |
49 | | - assert_equal(wat(n1_hdr), None) |
50 | | - |
51 | | - n1_hdr['sizeof_hdr'] = 540 |
52 | | - n2_hdr['sizeof_hdr'] = 540 |
53 | | - assert_equal(wat(n1_hdr), None) |
54 | | - assert_equal(wat(n1_hdr.as_byteswapped()), None) |
55 | | - assert_equal(wat(n2_hdr), Nifti2Header) |
56 | | - assert_equal(wat(n2_hdr.as_byteswapped()), Nifti2Header) |
57 | | - |
58 | | - n1_hdr['sizeof_hdr'] = 348 |
59 | | - assert_equal(wat(n1_hdr), AnalyzeHeader) |
60 | | - assert_equal(wat(n1_hdr.as_byteswapped()), AnalyzeHeader) |
61 | | - |
62 | | - n1_hdr['magic'] = b'n+1' |
63 | | - assert_equal(wat(n1_hdr), Nifti1Header) |
64 | | - assert_equal(wat(n1_hdr.as_byteswapped()), Nifti1Header) |
65 | | - |
66 | | - n1_hdr['magic'] = b'ni1' |
67 | | - assert_equal(wat(n1_hdr), Nifti1Header) |
68 | | - assert_equal(wat(n1_hdr.as_byteswapped()), Nifti1Header) |
69 | | - |
70 | | - # Doesn't matter what magic is if it's not a nifti1 magic |
71 | | - n1_hdr['magic'] = b'ni2' |
72 | | - assert_equal(wat(n1_hdr), AnalyzeHeader) |
73 | | - |
74 | | - n1_hdr['sizeof_hdr'] = 0 |
75 | | - n1_hdr['magic'] = b'' |
76 | | - assert_equal(wat(n1_hdr), None) |
77 | | - |
78 | | - n1_hdr['magic'] = 'n+1' |
79 | | - assert_equal(wat(n1_hdr), Nifti1Header) |
80 | | - |
81 | | - n1_hdr['magic'] = 'ni1' |
82 | | - assert_equal(wat(n1_hdr), Nifti1Header) |
83 | | - |
84 | | - |
85 | 29 | def test_sniff_and_guessed_image_type(img_klasses=all_image_classes): |
86 | | - """ |
87 | | - Loop over all test cases: |
88 | | - * whether a sniff is provided or not |
89 | | - * randomizing the order of image classes |
90 | | - * over all known image types |
91 | | -
|
92 | | - For each, we expect: |
93 | | - * When the file matches the expected class, things should |
94 | | - either work, or fail if we're doing bad stuff. |
95 | | - * When the file is a mismatch, the functions should not throw. |
96 | | - """ |
97 | | - |
| 30 | + # Loop over all test cases: |
| 31 | + # * whether a sniff is provided or not |
| 32 | + # * randomizing the order of image classes |
| 33 | + # * over all known image types |
| 34 | + |
| 35 | + # For each, we expect: |
| 36 | + # * When the file matches the expected class, things should |
| 37 | + # either work, or fail if we're doing bad stuff. |
| 38 | + # * When the file is a mismatch, the functions should not throw. |
98 | 39 | def test_image_class(img_path, expected_img_klass): |
99 | 40 | """ Compare an image of one image class to all others. |
100 | 41 |
|
|
0 commit comments