code: def test_op_raises_error_when_weight_is_not_valid(self) -> None:
      pipeline1 = read_sequence([1, 2]).and_return()
      pipeline2 = read_sequence([3, 4]).and_return()
      pipeline3 = read_sequence([5, 6]).and_return()
  
      with pytest.raises(
          ValueError,
          match=r"^The `weights` must be greater than 0\.0, but the weight at index 2 is -0\.2 instead\.$",
      ):
          DataPipeline.sample(
              [pipeline1, pipeline2, pipeline3], [0.5, 0.3, -0.2]
          ).and_return()
  
      with pytest.raises(
          ValueError,
          match=r"^The `weights` must be greater than 0\.0, but the weight at index 1 is 0 instead\.$",
      ):
          DataPipeline.sample(
              [pipeline1, pipeline2, pipeline3], [0.5, 0.0, 0.2]
          ).and_return()
  
      with pytest.raises(
          ValueError,
          match=r"^The `weights` must be finite, but the weight at index 0 is infinite or NaN instead\.$",
      ):
          DataPipeline.sample(
              [pipeline1, pipeline2, pipeline3], [math.inf, 0.3, 0.2]
          ).and_return()
  
file_path: fairseq2/tests/unit/data/data_pipeline/test_sample.py
imports: import math
  import pytest
  import torch
  from fairseq2.data import DataPipeline, DataPipelineError, read_sequence
  from fairseq2.data.text import read_text
  from fairseq2.typing import CPU
  from tests.common import tmp_rng_seed
label_desc: Use image node_id 7 for calling the TestSampleOp obj's underlying member method code with example usage: obj.test_op_raises_error_when_weight_is_not_valid() without return types