code: def test_data_pipeline():
      from speechbrain.utils.data_pipeline import DataPipeline
  
      pipeline = DataPipeline(
          ["text"],
          dynamic_items=[
              {
                  "func": lambda x: x.lower(),
                  "takes": ["text"],
                  "provides": "foo",
              },
              {
                  "func": lambda x: x[::-1],
                  "takes": "foo",
                  "provides": ["bar"],
              },
          ],
          output_keys=["text", "foo", "bar"],
      )
      result = pipeline({"text": "Test"})
      print(result)
      assert result["bar"] == "tset"
      pipeline = DataPipeline(["foo", "bar"])
      pipeline.add_dynamic_item(
          func=lambda x, y: x + y,
          takes=["foo", "bar"],
          provides="foobar",
      )
      pipeline.set_output_keys(["bar", "foobar"])
      result = pipeline({"foo": 1, "bar": 2})
      assert result["foobar"] == 3
      pipeline = DataPipeline(["foo", "bar"])
      from unittest.mock import MagicMock, Mock
  
      watcher = Mock()
      pipeline.add_dynamic_item(
          provides="foobar", func=watcher, takes=["foo", "bar"]
      )
      result = pipeline({"foo": 1, "bar": 2})
      assert not watcher.called
      pipeline = DataPipeline(["foo", "bar"])
      watcher = MagicMock(return_value=3)
      pipeline.add_dynamic_item(watcher, ["foo", "bar"], "foobar")
      pipeline.add_dynamic_item(lambda x: x, ["foobar"], ["truebar"])
      pipeline.set_output_keys(("truebar",))
      result = pipeline({"foo": 1, "bar": 2})
      assert watcher.called
      assert result["truebar"] == 3
      pipeline = DataPipeline(["foo", "bar"])
      watcher = MagicMock(return_value=3)
      pipeline.add_dynamic_item(
          func=watcher, takes=["foo", "bar"], provides="foobar"
      )
      pipeline.add_dynamic_item(
          func=lambda x: x, takes=["foo"], provides="truebar"
      )
      pipeline.set_output_keys(("truebar",))
      result = pipeline({"foo": 1, "bar": 2})
      assert not watcher.called
      assert result["truebar"] == 1
  
      pipeline = DataPipeline(["foo", "bar"])
      watcher = MagicMock(return_value=3)
      pipeline.add_dynamic_item(
          func=watcher, takes=["foo", "bar"], provides="foobar"
      )
      pipeline.set_output_keys(("foobar", "foo"))
      result = pipeline({"foo": 1, "bar": 2})
      assert watcher.called
      assert "foo" in result
      assert "foobar" in result
      assert "bar" not in result
      # Can change the outputs (continues previous tests)
      watcher.reset_mock()
      pipeline.set_output_keys(["bar"])
      result = pipeline({"foo": 1, "bar": 2})
      assert not watcher.called
      assert "foo" not in result
      assert "foobar" not in result
      assert "bar" in result
      # Finally, can also still request any specific key:
      computed = pipeline.compute_specific(
          ["foobar"], {"foo": 1, "bar": 2}
      )
      assert watcher.called
      assert computed["foobar"] == 3
  
      # Output can be a mapping:
      # (Key appears outside, value is internal)
      pipeline.set_output_keys({"signal": "foobar"})
      result = pipeline({"foo": 1, "bar": 2})
      assert result["signal"] == 3
  
imports: import pytest
label_desc: Use image node_id 1 for calling a global function with example usage: test_data_pipeline() without return types