@@ -73,46 +73,12 @@ def setup():
7373 DATA ['data_per_point' ])
7474
7575
76- def test_is_supported ():
77- # Emtpy file/string
76+ def test_is_supported_detect_format ():
77+ # Test is_supported and detect_format functions
78+ # Empty file/string
7879 f = BytesIO ()
7980 assert_false (nib .streamlines .is_supported (f ))
8081 assert_false (nib .streamlines .is_supported ("" ))
81-
82- # Valid file without extension
83- for tfile_cls in nib .streamlines .FORMATS .values ():
84- f = BytesIO ()
85- f .write (tfile_cls .get_magic_number ())
86- f .seek (0 , os .SEEK_SET )
87- assert_true (nib .streamlines .is_supported (f ))
88-
89- # Wrong extension but right magic number
90- for tfile_cls in nib .streamlines .FORMATS .values ():
91- with tempfile .TemporaryFile (mode = "w+b" , suffix = ".txt" ) as f :
92- f .write (tfile_cls .get_magic_number ())
93- f .seek (0 , os .SEEK_SET )
94- assert_true (nib .streamlines .is_supported (f ))
95-
96- # Good extension but wrong magic number
97- for ext , tfile_cls in nib .streamlines .FORMATS .items ():
98- with tempfile .TemporaryFile (mode = "w+b" , suffix = ext ) as f :
99- f .write (b"pass" )
100- f .seek (0 , os .SEEK_SET )
101- assert_false (nib .streamlines .is_supported (f ))
102-
103- # Wrong extension, string only
104- f = "my_tractogram.asd"
105- assert_false (nib .streamlines .is_supported (f ))
106-
107- # Good extension, string only
108- for ext , tfile_cls in nib .streamlines .FORMATS .items ():
109- f = "my_tractogram" + ext
110- assert_true (nib .streamlines .is_supported (f ))
111-
112-
113- def test_detect_format ():
114- # Emtpy file/string
115- f = BytesIO ()
11682 assert_true (nib .streamlines .detect_format (f ) is None )
11783 assert_true (nib .streamlines .detect_format ("" ) is None )
11884
@@ -121,29 +87,34 @@ def test_detect_format():
12187 f = BytesIO ()
12288 f .write (tfile_cls .get_magic_number ())
12389 f .seek (0 , os .SEEK_SET )
90+ assert_true (nib .streamlines .is_supported (f ))
12491 assert_true (nib .streamlines .detect_format (f ) is tfile_cls )
12592
12693 # Wrong extension but right magic number
12794 for tfile_cls in nib .streamlines .FORMATS .values ():
12895 with tempfile .TemporaryFile (mode = "w+b" , suffix = ".txt" ) as f :
12996 f .write (tfile_cls .get_magic_number ())
13097 f .seek (0 , os .SEEK_SET )
98+ assert_true (nib .streamlines .is_supported (f ))
13199 assert_true (nib .streamlines .detect_format (f ) is tfile_cls )
132100
133101 # Good extension but wrong magic number
134102 for ext , tfile_cls in nib .streamlines .FORMATS .items ():
135103 with tempfile .TemporaryFile (mode = "w+b" , suffix = ext ) as f :
136104 f .write (b"pass" )
137105 f .seek (0 , os .SEEK_SET )
106+ assert_false (nib .streamlines .is_supported (f ))
138107 assert_true (nib .streamlines .detect_format (f ) is None )
139108
140109 # Wrong extension, string only
141110 f = "my_tractogram.asd"
111+ assert_false (nib .streamlines .is_supported (f ))
142112 assert_true (nib .streamlines .detect_format (f ) is None )
143113
144114 # Good extension, string only
145115 for ext , tfile_cls in nib .streamlines .FORMATS .items ():
146116 f = "my_tractogram" + ext
117+ assert_true (nib .streamlines .is_supported (f ))
147118 assert_equal (nib .streamlines .detect_format (f ), tfile_cls )
148119
149120 # Extension should not be case-sensitive.
0 commit comments