code: def test_webdataset_suffixes(ray_start_2_cpus, tmp_path):
      path = os.path.join(tmp_path, "bar_000000.tar")
      with TarWriter(path) as tf:
          for i in range(100):
              tf.write(f"{i}.txt", str(i).encode("utf-8"))
              tf.write(f"{i}.test.txt", str(i**2).encode("utf-8"))
              tf.write(f"{i}.cls", str(i**2).encode("utf-8"))
              tf.write(f"{i}.test.cls2", str(i**2).encode("utf-8"))
      assert os.path.exists(path)
      assert len(glob.glob(f"{tmp_path}/*.tar")) == 1
  
      # test simple suffixes
      ds = ray.data.read_webdataset(
          paths=[str(tmp_path)], parallelism=1, suffixes=["txt", "cls"]
      )
      samples = ds.take(100)
      assert len(samples) == 100
      for i, sample in enumerate(samples):
          assert set(sample.keys()) == {
              "__url__",
              "__key__",
              "txt",
              "cls",
          }
  
      # test fnmatch patterns for suffixes
      ds = ray.data.read_webdataset(
          paths=[str(tmp_path)],
          parallelism=1,
          suffixes=["*.txt", "*.cls"],
      )
      samples = ds.take(100)
      assert len(samples) == 100
      for i, sample in enumerate(samples):
          assert set(sample.keys()) == {
              "__url__",
              "__key__",
              "txt",
              "cls",
              "test.txt",
          }
  
      # test selection function
      def select(name):
          return name.endswith("txt")
  
      ds = ray.data.read_webdataset(
          paths=[str(tmp_path)], parallelism=1, suffixes=select
      )
      samples = ds.take(100)
      assert len(samples) == 100
      for i, sample in enumerate(samples):
          assert set(sample.keys()) == {
              "__url__",
              "__key__",
              "txt",
              "test.txt",
          }
  
      # test filerename
      def renamer(name):
          result = name.replace("txt", "text")
          print("***", name, result)
          return result
  
      ds = ray.data.read_webdataset(
          paths=[str(tmp_path)], parallelism=1, filerename=renamer
      )
      samples = ds.take(100)
      assert len(samples) == 100
      for i, sample in enumerate(samples):
          assert set(sample.keys()) == {
              "__url__",
              "__key__",
              "text",
              "cls",
              "test.text",
              "test.cls2",
          }
  
file_path: ray/python/ray/data/tests/test_webdataset.py
imports: import glob
  import io
  import os
  import tarfile
  import pytest
  import ray
  from ray.tests.conftest import *
label_desc: Use image node_id 2 for calling a global function with example usage: test_webdataset_suffixes(ray_start_2_cpus, tmp_path) and returns: name, result