code: def test_encode_response():
      encoder = TestEncoder()
  
      def test_encode_response(
          h, response, expected_processed=None, allow_truncate=False
      ):
          response_encoder = tasks.ResponseEncoder(h, encoder)
          processed = response_encoder.encode_response(
              response, allow_truncate=allow_truncate
          )
          if expected_processed is not None:
              assert_eq(expected_processed, processed)
  
      test_encode_response(
          tasks.TaskResponseHParams(length=10, truncate_token=None),
          "123456789a",
          encoder.encode("123456789a"),
      )
  
      test_encode_response(
          tasks.TaskResponseHParams(length=10, truncate_token=None),
          "123456789",
          encoder.encode("123456789") + [PADDING_TOKEN],
      )
  
      with pytest.raises(AssertionError):
          test_encode_response(
              tasks.TaskResponseHParams(length=10, truncate_token=None),
              "123456789ab",
              encoder.encode("123456789a"),
          )
  
      test_encode_response(
          tasks.TaskResponseHParams(length=10, truncate_token=None),
          "123456789ab",
          encoder.encode("123456789a"),
          allow_truncate=True,
      )
  
      test_encode_response(
          tasks.TaskResponseHParams(length=10, truncate_token=ord("5")),
          "1234",
          encoder.encode("12345") + [PADDING_TOKEN] * 5,
      )
  
      with pytest.raises(AssertionError):
          test_encode_response(
              tasks.TaskResponseHParams(
                  length=10, truncate_token=ord("b")
              ),
              "123456789a",
              encoder.encode("12345") + [PADDING_TOKEN] * 5,
          )
  
      test_encode_response(
          tasks.TaskResponseHParams(length=10, truncate_token=ord("b")),
          "123456789a",
          encoder.encode("123456789b"),
          allow_truncate=True,
      )
  
      test_encode_response(
          tasks.TaskResponseHParams(length=10, truncate_token=ord("b")),
          "123456789aaaab",
          encoder.encode("123456789b"),
          allow_truncate=True,
      )
  
file_path: summarize-from-feedback/summarize_from_feedback/test_tasks.py
imports: import pytest
  import torch
  from summarize_from_feedback import tasks
  from summarize_from_feedback.query_response_model import PADDING_TOKEN
  from summarize_from_feedback.utils.assertions import assert_eq
label_desc: Use image node_id 3 for calling a global function with example usage: test_encode_response() without return types