code: def test_seek_tell():
      # Test seek tell routine
      bio = BytesIO()
      in_files = [bio, "test.bin", "test.gz", "test.bz2"]
      if HAVE_ZSTD:
          in_files += ["test.zst"]
      start = 10
      end = 100
      diff = end - start
      tail = 7
      with InTemporaryDirectory():
          for in_file, write0 in itertools.product(
              in_files, (False, True)
          ):
              st = functools.partial(seek_tell, write0=write0)
              bio.seek(0)
              # First write the file
              with ImageOpener(in_file, "wb") as fobj:
                  assert fobj.tell() == 0
                  # already at position - OK
                  st(fobj, 0)
                  assert fobj.tell() == 0
                  # Move position by writing
                  fobj.write(b"\x01" * start)
                  assert fobj.tell() == start
                  # Files other than BZ2Files can seek forward on write, leaving
                  # zeros in their wake.  BZ2Files can't seek when writing,
                  # unless we enable the write0 flag to seek_tell
                  # ZstdFiles also does not support seek forward on write
                  if not write0 and in_file in ("test.bz2", "test.zst"):
                      # write the zeros by hand for the read test below
                      fobj.write(b"\x00" * diff)
                  else:
                      st(fobj, end)
                      assert fobj.tell() == end
                  # Write tail
                  fobj.write(b"\x02" * tail)
              bio.seek(0)
              # Now read back the file testing seek_tell in reading mode
              with ImageOpener(in_file, "rb") as fobj:
                  assert fobj.tell() == 0
                  st(fobj, 0)
                  assert fobj.tell() == 0
                  st(fobj, start)
                  assert fobj.tell() == start
                  st(fobj, end)
                  assert fobj.tell() == end
                  # Seek anywhere works in read mode for all files
                  st(fobj, 0)
              bio.seek(0)
              # Check we have the expected written output
              with ImageOpener(in_file, "rb") as fobj:
                  assert (
                      fobj.read()
                      == b"\x01" * start
                      + b"\x00" * diff
                      + b"\x02" * tail
                  )
          input_files = ["test2.gz", "test2.bz2"]
          if HAVE_ZSTD:
              input_files += ["test2.zst"]
          for in_file in input_files:
              # Check failure of write seek backwards
              with ImageOpener(in_file, "wb") as fobj:
                  fobj.write(b"g" * 10)
                  assert fobj.tell() == 10
                  seek_tell(fobj, 10)
                  assert fobj.tell() == 10
                  with pytest.raises(OSError):
                      seek_tell(fobj, 5)
              # Make sure read seeks don't affect file
              with ImageOpener(in_file, "rb") as fobj:
                  seek_tell(fobj, 10)
                  seek_tell(fobj, 0)
              with ImageOpener(in_file, "rb") as fobj:
                  assert fobj.read() == b"g" * 10
  
imports: import bz2
  import functools
  import gzip
  import itertools
  import os
  import tempfile
  import threading
  import time
  import warnings
  from io import BytesIO
  from os.path import exists
  import numpy
  import pytest
  from numpy.testing import assert_array_almost_equal, assert_array_equal
  from packaging.version import Version
  from nibabel.testing import assert_allclose_safely, assert_dt_equal, error_warnings, suppress_warnings
  from ..casting import OK_FLOATS, floor_log2, sctypes, shared_range, type_info
  from ..openers import BZ2File, ImageOpener, Opener
  from ..optpkg import optional_package
  from ..tmpdirs import InTemporaryDirectory
  from ..volumeutils import _dt_min_max, _ftype4scaled_finite, _is_compressed_fobj, _write_data, apply_read_scaling, array_from_file, array_to_file, best_write_scale_ftype, better_float_of, fname_ext_ul_case, int_scinter_ftype, make_dt_codes, native_code, rec2dict, seek_tell, shape_zoom_affine, working_type, write_zeros
label_desc: Use image node_id 34 for calling a global function with example usage: test_seek_tell() without return types