code: def test_fetch_neurovault_ids(tmp_path):
      collections, images = _get_neurovault_data()
      collections = collections.sort_values(
          by="true_number_of_images", ascending=False
      )
      other_col_id, *col_ids = collections["id"].values[:3]
      img_ids = images[images["collection_id"] == other_col_id][
          "id"
      ].values[:3]
      img_from_cols_ids = images[images["collection_id"].isin(col_ids)][
          "id"
      ].values
  
      with pytest.raises(ValueError):
          neurovault.fetch_neurovault_ids(mode="bad")
  
      data = neurovault.fetch_neurovault_ids(
          image_ids=img_ids, collection_ids=col_ids, data_dir=tmp_path
      )
  
      expected_images = list(img_ids) + list(img_from_cols_ids)
  
      assert len(data.images) == len(expected_images)
      assert {img["id"] for img in data["images_meta"]} == set(
          expected_images
      )
      assert (
          os.path.dirname(data["images"][0])
          == data["collections_meta"][0]["absolute_path"]
      )
  
      # check image can be loaded again from disk
      data = neurovault.fetch_neurovault_ids(
          image_ids=[img_ids[0]], data_dir=tmp_path, mode="offline"
      )
  
      assert len(data.images) == 1
  
      # check that download_new mode forces overwrite
      modified_meta = data["images_meta"][0]
  
      assert modified_meta["some_key"] == "some_value"
  
      modified_meta["some_key"] = "some_other_value"
      # mess it up on disk
      meta_path = os.path.join(
          os.path.dirname(modified_meta["absolute_path"]),
          f"image_{img_ids[0]}_metadata.json",
      )
      with open(meta_path, "wb") as meta_f:
          meta_f.write(json.dumps(modified_meta).encode("UTF-8"))
  
      # fresh download
      data = neurovault.fetch_neurovault_ids(
          image_ids=[img_ids[0]], data_dir=tmp_path, mode="download_new"
      )
      data = neurovault.fetch_neurovault_ids(
          image_ids=[img_ids[0]], data_dir=tmp_path, mode="offline"
      )
  
      # should not have changed
      assert data["images_meta"][0]["some_key"] == "some_other_value"
  
      data = neurovault.fetch_neurovault_ids(
          image_ids=[img_ids[0]], data_dir=tmp_path, mode="overwrite"
      )
      data = neurovault.fetch_neurovault_ids(
          image_ids=[img_ids[0]], data_dir=tmp_path, mode="offline"
      )
  
      # should be back to the original version
      assert data["images_meta"][0]["some_key"] == "some_value"
  
imports: import hashlib
  import json
  import os
  import re
  import stat
  from urllib import parse
  import numpy
  import pandas
  import pytest
  import requests
  from nilearn._utils.data_gen import generate_fake_fmri
  from nilearn.conftest import _rng
  from nilearn.datasets import neurovault
  from nilearn.image import load_img
label_desc: Use image node_id 42 for calling a global function with example usage: test_fetch_neurovault_ids(tmp_path) without return types