class_docstr: Class implements base tests for binary headers
  
  It serves as a base class for other binary header tests
class_docstr_tok: ["Class","implements","base","tests","for","binary","headers","It","serves","as","a","base","class","for","other","binary","header","tests"]
code: def test_as_byteswapped(self):
      # Check byte swapping
      hdr = self.header_class()
      assert hdr.endianness == native_code
      # same code just returns a copy
      hdr2 = hdr.as_byteswapped(native_code)
      assert not hdr is hdr2
      # Different code gives byteswapped copy
      hdr_bs = hdr.as_byteswapped(swapped_code)
      assert hdr_bs.endianness == swapped_code
      assert hdr.binaryblock != hdr_bs.binaryblock
      # Note that contents is not rechecked on swap / copy
  
      class DC(self.header_class):
          def check_fix(self, *args, **kwargs):
              raise Exception
  
      # Assumes check=True default
      with pytest.raises(Exception):
          DC(hdr.binaryblock)
      hdr = DC(hdr.binaryblock, check=False)
      hdr2 = hdr.as_byteswapped(native_code)
      hdr_bs = hdr.as_byteswapped(swapped_code)
  
imports: import logging
  from io import BytesIO, StringIO
  import numpy
  import pytest
  from numpy.testing import assert_array_equal
  from ..None import imageglobals
  from ..batteryrunners import Report
  from ..casting import sctypes
  from ..spatialimages import HeaderDataError
  from ..volumeutils import Recoder, native_code, swapped_code
  from ..wrapstruct import LabeledWrapStruct, WrapStruct, WrapStructError
label_desc: Use image node_id 14 for calling the _TestWrapStructBase obj's underlying member method code with example usage: obj.test_as_byteswapped() without return types