Skip to content

Commit b04644d

Browse files
djareckaeffigies
authored andcommitted
fixing test_wrapstruct: removing setUpClass and adding self.header_class check to all of the test methods: couldnt find better way for suppressing tests from abstract classes and allowing for testing from all child classes
1 parent dc34860 commit b04644d

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

nibabel/tests/test_wrapstruct.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,9 @@ def get_bad_bb(self):
118118
# means do not check
119119
return None
120120

121-
@classmethod
122-
def setUpClass(cls):
123-
if cls.header_class is None:
124-
raise SkipTest("no testing methods from the abstract class")
125-
126-
127121
def test_general_init(self):
122+
if not self.header_class:
123+
pytest.skip()
128124
hdr = self.header_class()
129125
# binaryblock has length given by header data dtype
130126
binblock = hdr.binaryblock
@@ -144,6 +140,8 @@ def _set_something_into_hdr(self, hdr):
144140

145141
def test__eq__(self):
146142
# Test equal and not equal
143+
if not self.header_class:
144+
pytest.skip()
147145
hdr1 = self.header_class()
148146
hdr2 = self.header_class()
149147
assert hdr1 == hdr2
@@ -160,6 +158,8 @@ def test__eq__(self):
160158

161159
def test_to_from_fileobj(self):
162160
# Successful write using write_to
161+
if not self.header_class:
162+
pytest.skip()
163163
hdr = self.header_class()
164164
str_io = BytesIO()
165165
hdr.write_to(str_io)
@@ -169,6 +169,8 @@ def test_to_from_fileobj(self):
169169
assert hdr2.binaryblock == hdr.binaryblock
170170

171171
def test_mappingness(self):
172+
if not self.header_class:
173+
pytest.skip()
172174
hdr = self.header_class()
173175
with pytest.raises(ValueError):
174176
hdr.__setitem__('nonexistent key', 0.1)
@@ -205,12 +207,16 @@ def test_endianness_ro(self):
205207
endianness on initialization (or occasionally byteswapping the
206208
data) - but this is done via via the as_byteswapped method
207209
'''
210+
if not self.header_class:
211+
pytest.skip()
208212
hdr = self.header_class()
209213
with pytest.raises(AttributeError):
210214
hdr.__setattr__('endianness', '<')
211215

212216
def test_endian_guess(self):
213217
# Check guesses of endian
218+
if not self.header_class:
219+
pytest.skip()
214220
eh = self.header_class()
215221
assert eh.endianness == native_code
216222
hdr_data = eh.structarr.copy()
@@ -225,13 +231,17 @@ def test_binblock_is_file(self):
225231
# strings following. More generally, there may be other perhaps
226232
# optional data after the binary block, in which case you will need to
227233
# override this test
234+
if not self.header_class:
235+
pytest.skip()
228236
hdr = self.header_class()
229237
str_io = BytesIO()
230238
hdr.write_to(str_io)
231239
assert str_io.getvalue() == hdr.binaryblock
232240

233241
def test_structarr(self):
234242
# structarr attribute also read only
243+
if not self.header_class:
244+
pytest.skip()
235245
hdr = self.header_class()
236246
# Just check we can get structarr
237247
hdr.structarr
@@ -250,6 +260,8 @@ def assert_no_log_err(self, hdr):
250260

251261
def test_bytes(self):
252262
# Test get of bytes
263+
if not self.header_class:
264+
pytest.skip()
253265
hdr1 = self.header_class()
254266
bb = hdr1.binaryblock
255267
hdr2 = self.header_class(hdr1.binaryblock)
@@ -280,6 +292,8 @@ def test_bytes(self):
280292

281293
def test_as_byteswapped(self):
282294
# Check byte swapping
295+
if not self.header_class:
296+
pytest.skip()
283297
hdr = self.header_class()
284298
assert hdr.endianness == native_code
285299
# same code just returns a copy
@@ -304,6 +318,8 @@ def check_fix(self, *args, **kwargs):
304318

305319
def test_empty_check(self):
306320
# Empty header should be error free
321+
if not self.header_class:
322+
pytest.skip()
307323
hdr = self.header_class()
308324
hdr.check_fix(error_level=0)
309325

@@ -313,6 +329,8 @@ def _dxer(self, hdr):
313329
return self.header_class.diagnose_binaryblock(binblock)
314330

315331
def test_str(self):
332+
if not self.header_class:
333+
pytest.skip()
316334
hdr = self.header_class()
317335
# Check something returns from str
318336
s1 = str(hdr)
@@ -326,6 +344,8 @@ class _TestLabeledWrapStruct(_TestWrapStructBase):
326344
def test_get_value_label(self):
327345
# Test get value label method
328346
# Make a new class to avoid overwriting recoders of original
347+
if not self.header_class:
348+
pytest.skip()
329349
class MyHdr(self.header_class):
330350
_field_recoders = {}
331351
hdr = MyHdr()

0 commit comments

Comments
 (0)