code: def ensure_test_data():
      # update S3ROOT in __init__.py to get a fresh set of data
      print("Ensuring that test data exists at %s" % S3ROOT)
      mark = urlparse(os.path.join(S3ROOT, "ALL_OK"))
      try:
          # Check if the data exists and has been modified in the last
          # 29 days (this should be lower than the TTL for your bucket to ensure
          # the data is available for the test)
          import datetime
  
          today = datetime.date.today()
          delta = datetime.timedelta(days=29)
          s3client.head_object(
              Bucket=mark.netloc,
              Key=mark.path.lstrip("/"),
              IfModifiedSince=str(today - delta),
          )
          print("All data ok.")
      except:
          print("Uploading test data")
  
          def _do_upload(prefix, filespecs, meta=None):
              for fname, size in filespecs.items():
                  if size is not None:
                      f = RandomFile(prefix, fname, size)
                      url = urlparse(f.url)
                      # For metadata, we don't actually touch RandomFile
                      # (since it is the same) but we modify the path to post-pend
                      # the name
                      print(
                          "Test data case %s: upload to %s started"
                          % (prefix, f.url)
                      )
                      s3client.upload_fileobj(
                          f.fileobj(), url.netloc, url.path.lstrip("/")
                      )
                      print(
                          "Test data case %s: uploaded to %s"
                          % (prefix, f.url)
                      )
                      if meta is not None:
                          for metaname, metainfo in meta.items():
                              new_url = "%s_%s" % (f.url, metaname)
                              url = urlparse(new_url)
                              print(
                                  "Test data case %s: upload to %s started"
                                  % (prefix, new_url)
                              )
                              extra = {}
                              content_type, user_meta = metainfo
                              if content_type:
                                  extra["ContentType"] = content_type
                              if user_meta:
                                  new_meta = {
                                      "metaflow-user-attributes": json.dumps(
                                          user_meta
                                      )
                                  }
                                  extra["Metadata"] = new_meta
                              s3client.upload_fileobj(
                                  f.fileobj(),
                                  url.netloc,
                                  url.path.lstrip("/"),
                                  ExtraArgs=extra,
                              )
                              print(
                                  "Test data case %s: uploaded to %s"
                                  % (prefix, new_url)
                              )
  
          for prefix, filespecs in BIG_DATA + FAKE_RUN_DATA:
              _do_upload(prefix, filespecs)
          for prefix, filespecs in BASIC_DATA:
              _do_upload(prefix, filespecs, meta=BASIC_METADATA)
  
          s3client.upload_fileobj(
              to_fileobj("ok"),
              Bucket=mark.netloc,
              Key=mark.path.lstrip("/"),
          )
          print("Test data uploaded ok")
  
imports: import os
  import sys
  import zlib
  import json
  from uuid import uuid4
  from hashlib import sha1
  from collections import namedtuple
  from metaflow.plugins.datatools.s3 import S3PutObject
  from metaflow.util import to_fileobj, to_bytes, url_quote
  import numpy
  from ..None import s3client, S3ROOT
label_desc: Use image node_id 12 for calling a global function with example usage: ensure_test_data() without return types