code: def test_sequence_adder(
      self,
      sequence_length: int,
      period: int,
      first,
      steps,
      expected_sequences,
      end_behavior: adders.EndBehavior,
      repeat_episode_times: int = 1,
  ):
      env_spec, extras_spec = test_utils.get_specs(steps[0])
      step_spec = structured.create_step_spec(env_spec, extras_spec)
  
      should_pad_trajectory = (
          end_behavior == adders.EndBehavior.ZERO_PAD
      )
  
      def _maybe_zero_pad(flat_trajectory):
          trajectory = tree.unflatten_as(step_spec, flat_trajectory)
  
          if not should_pad_trajectory:
              return trajectory
  
          padding_length = sequence_length - flat_trajectory[0].shape[0]
          if padding_length == 0:
              return trajectory
  
          padding = tree.map_structure(
              lambda x: np.zeros(
                  [padding_length, *x.shape[1:]], x.dtype
              ),
              trajectory,
          )
  
          return tree.map_structure(
              lambda *x: np.concatenate(x), trajectory, padding
          )
  
      # The StructuredAdder does not support adding padding steps as we assume
      # that the padding will be added on the learner side.
      if end_behavior == adders.EndBehavior.ZERO_PAD:
          end_behavior = adders.EndBehavior.TRUNCATE
  
      configs = structured.create_sequence_config(
          step_spec=step_spec,
          sequence_length=sequence_length,
          period=period,
          end_of_episode_behavior=end_behavior,
      )
      adder = structured.StructuredAdder(
          client=self.client,
          max_in_flight_items=0,
          configs=configs,
          step_spec=step_spec,
      )
  
      super().run_test_adder(
          adder=adder,
          first=first,
          steps=steps,
          expected_items=expected_sequences,
          repeat_episode_times=repeat_episode_times,
          end_behavior=end_behavior,
          item_transform=_maybe_zero_pad,
          signature=sw.infer_signature(configs, step_spec),
      )
  
file_path: acme/acme/adders/reverb/structured_test.py
imports: from typing import Sequence
  from acme import types
  from acme.adders.reverb import sequence
  from acme.adders.reverb import structured
  from acme.adders.reverb import test_cases
  from acme.adders.reverb import test_utils
  import dm_env
  import numpy
  from reverb import structured_writer
  import tree
  from absl.testing import absltest
  from absl.testing import parameterized
label_desc: Use image node_id 1 for calling the StructuredAdderTest obj's underlying member method code with example usage: obj.test_sequence_adder(sequence_length, period, first, steps, expected_sequences, end_behavior, repeat_episode_times) and returns: tree, trajectory, trajectory