code: def test_get_metadata_from_bids(tmp_path):
      """Ensure that metadata is correctly extracted from BIDS JSON files.
  
      Throw a warning when the field is not found.
      Throw a warning when there is no JSON file.
      """
      json_file = tmp_path / "sub-01_task-main_bold.json"
      json_files = [json_file]
  
      with open(json_file, "w") as f:
          json.dump({"RepetitionTime": 2.0}, f)
      value = _get_metadata_from_bids(
          field="RepetitionTime", json_files=json_files
      )
      assert value == 2.0
  
      with open(json_file, "w") as f:
          json.dump({"foo": 2.0}, f)
      with pytest.warns(
          UserWarning, match="'RepetitionTime' not found"
      ):
          value = _get_metadata_from_bids(
              field="RepetitionTime", json_files=json_files
          )
  
      json_files = []
      with pytest.warns(UserWarning, match="No .*json found in BIDS"):
          value = _get_metadata_from_bids(
              field="RepetitionTime", json_files=json_files
          )
          assert value is None
  
imports: import json
  import os
  import numpy
  import pandas
  import pytest
  from nilearn._utils.data_gen import add_metadata_to_bids_dataset, create_fake_bids_dataset, generate_fake_fmri_data_and_design
  from nilearn.glm.first_level import FirstLevelModel
  from nilearn.glm.second_level import SecondLevelModel
  from nilearn.interfaces.bids import get_bids_files, parse_bids_filename, save_glm_to_bids
  from nilearn.interfaces.bids.query import _get_metadata_from_bids, infer_repetition_time_from_dataset, infer_slice_timing_start_time_from_dataset
  from nilearn.maskers import NiftiMasker
label_desc: Use image node_id 1 for calling a global function with example usage: test_get_metadata_from_bids(tmp_path) without return types