def test_permissive_read_with_wrong_machine_stamp(self): data = np.arange(12, dtype=np.int16).reshape(3, 4) with self.newmrc(self.temp_mrc_name, mode='w+') as mrc: mrc.set_data(data) wrong_byte_order = mrc.header.mode.newbyteorder().dtype.byteorder mrc.header.machst = utils.machine_stamp_from_byte_order(wrong_byte_order) with self.assertRaisesRegex(ValueError, "Unrecognised mode"): self.newmrc(self.temp_mrc_name) with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") with self.newmrc(self.temp_mrc_name, permissive=True) as mrc: np.testing.assert_array_equal(mrc.data, data) assert len(w) == 1 assert "Machine stamp" in str(w[0].message) assert "byte order" in str(w[0].message)
def test_pretty_machine_stamp(self): machst = utils.machine_stamp_from_byte_order('<') assert utils.pretty_machine_stamp(machst) == "0x44 0x44 0x00 0x00"
def test_unknown_byte_order_raises_exception(self): with self.assertRaisesRegex(ValueError, "Unrecognised byte order indicator"): utils.machine_stamp_from_byte_order('|')
def test_native_machine_stamp(self): machst = utils.machine_stamp_from_byte_order() if sys.byteorder == 'little': assert machst == utils.machine_stamp_from_byte_order('<') else: assert machst == utils.machine_stamp_from_byte_order('>')
def test_big_endian_machine_stamp(self): machst = utils.machine_stamp_from_byte_order('>') assert machst == bytearray((0x11, 0x11, 0x00, 0x00))
def test_little_endian_machine_stamp(self): machst = utils.machine_stamp_from_byte_order('<') assert machst == bytearray((0x44, 0x44, 0x00, 0x00))