code: def test_as_byteswapped(self):
      # Check byte swapping
      hdr = self.header_class()
      assert hdr.endianness == ">"
      # same code just returns a copy
      for endianness in BIG_CODES:
          hdr2 = hdr.as_byteswapped(endianness)
          assert hdr2 is not hdr
          assert hdr2 == hdr
  
      # Different code raises error
      for endianness in (None,) + LITTLE_CODES:
          with pytest.raises(ValueError):
              hdr.as_byteswapped(endianness)
  
      # 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(">")
  
imports: import io
  import os
  import pathlib
  import numpy
  import pytest
  from numpy.testing import assert_almost_equal, assert_array_almost_equal, assert_array_equal
  from ...None import imageglobals
  from ...fileholders import FileHolder
  from ...openers import ImageOpener
  from ...spatialimages import HeaderDataError
  from ...testing import data_path
  from ...tests import test_spatialimages
  from ...tests import test_wrapstruct
  from ...tmpdirs import InTemporaryDirectory
  from ...volumeutils import sys_is_le
  from ...wrapstruct import WrapStructError
  from ..None import load, save
  from ..mghformat import MGHError, MGHHeader, MGHImage
label_desc: Use image node_id 8 for calling the TestMGHHeader obj's underlying member method code with example usage: obj.test_as_byteswapped() without return types