code: def test_source_image_pad(self):
      # test image size equals to target size
      trans = SourceImagePad(target_scale=(30, 15))
      target_polygon = self.data_info["gt_polygons"][0]
      target_bbox = self.data_info["gt_bboxes"]
      results = trans(self.data_info.copy())
      self.assertEqual(results["img"].shape, (15, 30, 3))
      self.assertEqual(results["img_shape"], (15, 30))
      self.assertEqual(results["pad_shape"], (15, 30, 3))
      self.assertEqual(results["pad_fixed_size"], (30, 15))
      self.assertTrue(
          np.allclose(results["gt_polygons"][0], target_polygon)
      )
      self.assertTrue(np.allclose(results["gt_bboxes"][0], target_bbox))
  
      # test pad to square
      trans = SourceImagePad(target_scale=30)
      target_polygon = np.array(
          [10.0, 5.0, 20.0, 5.0, 20.0, 10.0, 10.0, 10.0]
      )
      target_bbox = np.array([[10.0, 5.0, 20.0, 10.0]])
      results = trans(self.data_info.copy())
      self.assertEqual(results["img"].shape, (30, 30, 3))
      self.assertEqual(results["img_shape"], (30, 30))
      self.assertEqual(results["pad_shape"], (30, 30, 3))
      self.assertEqual(results["pad_fixed_size"], (30, 30))
      self.assertTrue(
          np.allclose(results["gt_polygons"][0], target_polygon)
      )
      self.assertTrue(np.allclose(results["gt_bboxes"][0], target_bbox))
  
      # test pad to different shape
      trans = SourceImagePad(target_scale=(40, 60))
      target_polygon = np.array(
          [10.0, 5.0, 20.0, 5.0, 20.0, 10.0, 10.0, 10.0]
      )
      target_bbox = np.array([[10.0, 5.0, 20.0, 10.0]])
      results = trans(self.data_info.copy())
      self.assertEqual(results["img"].shape, (60, 40, 3))
      self.assertEqual(results["img_shape"], (60, 40))
      self.assertEqual(results["pad_shape"], (60, 40, 3))
      self.assertEqual(results["pad_fixed_size"], (40, 60))
      self.assertTrue(
          np.allclose(results["gt_polygons"][0], target_polygon)
      )
      self.assertTrue(np.allclose(results["gt_bboxes"][0], target_bbox))
  
      # test pad with different crop_ratio
      trans = SourceImagePad(target_scale=30, crop_ratio=1.0)
      target_polygon = np.array(
          [10.0, 5.0, 20.0, 5.0, 20.0, 10.0, 10.0, 10.0]
      )
      target_bbox = np.array([[10.0, 5.0, 20.0, 10.0]])
      results = trans(self.data_info.copy())
      self.assertEqual(results["img"].shape, (30, 30, 3))
      self.assertEqual(results["img_shape"], (30, 30))
      self.assertEqual(results["pad_shape"], (30, 30, 3))
      self.assertEqual(results["pad_fixed_size"], (30, 30))
      self.assertTrue(
          np.allclose(results["gt_polygons"][0], target_polygon)
      )
      self.assertTrue(np.allclose(results["gt_bboxes"][0], target_bbox))
  
imports: import copy
  import unittest
  import unittest.mock
  import numpy
  from mmcv.transforms import Pad, RandomResize
  from mmocr.datasets.transforms import BoundedScaleAspectJitter, RandomCrop, RandomFlip, Resize, ShortScaleAspectJitter, SourceImagePad, TextDetRandomCrop, TextDetRandomCropFlip
  from mmocr.utils import bbox2poly, poly2shapely
label_desc: Use image node_id 2 for calling the TestSourceImagePad obj's underlying member method code with example usage: obj.test_source_image_pad() without return types