code: def test_check_fail(path, arr):
      """Check that compression fails if we change one byte in the original file before finishing
      the write() method."""
      out = path.parent / "data.cbin"
      outmeta = path.parent / "data.ch"
  
      # Write the array into a raw data binary file.
      _write_arr(path, arr)
  
      def before_check(writer):
          # Change one byte in the original file.
          # First, we need to close the original memmapped file before we can write to it.
          writer.close()
          # Then, we change one byte in it.
          f_size = op.getsize(path)
          # WARNING: must open in r+b mode in order to modify bytes in-place in the middle of
          # the file.
          with open(str(path), "r+b") as f:
              f.seek(f_size // 2)
              # Also, it's better to change multiple bytes at the same time to be sure that
              # the underlying number (e.g. float64) is fully modified.
              f.write(os.urandom(8))
          assert not np.allclose(
              np.fromfile(str(path), dtype=arr.dtype), arr.ravel()
          )
          # The file size should be the same, although one byte has been changed.
          assert op.getsize(path) == f_size
          # Finally, we open it again before the check.
          writer.open(
              path,
              sample_rate=sample_rate,
              n_channels=arr.shape[1],
              dtype=arr.dtype,
          )
  
      # Compress the file.
      with raises(RuntimeError):
          w = Writer(before_check=before_check)
          w.open(
              path,
              sample_rate=sample_rate,
              n_channels=arr.shape[1],
              dtype=arr.dtype,
          )
          w.write(out, outmeta)
          w.close()
  
imports: from contextlib import redirect_stdout
  import io
  from itertools import product
  import json
  import hashlib
  import logging
  import os
  import os.path
  from pathlib import Path
  import re
  import numpy
  from pytest import fixture, raises, mark
  import mtscomp
  from mtscomp import add_default_handler, Writer, Reader, load_raw_data, diff_along_axis, cumsum_along_axis, mtscomp_parser, mtsdecomp_parser, _args_to_config, read_config, compress, decompress, mtsdesc, mtscomp, mtsdecomp, mtschop, CHECK_ATOL
label_desc: Use image node_id 24 for calling a global function with example usage: test_check_fail(path, arr) without return types