code: def test_sample_offset(self, mock_randint, mock_sample):
      # test target size is bigger than image size
      mock_sample.side_effect = [1]
      trans = TextDetRandomCrop(target_size=(6, 6))
      offset = trans._sample_offset(
          self.data_info["gt_polygons"], self.data_info["img"].shape[:2]
      )
      self.assertEqual(offset, (0, 0))
  
      # test the first bracnh in sample_offset
      mock_sample.side_effect = [0.1]
      mock_randint.side_effect = [0, 2]
      trans = TextDetRandomCrop(target_size=(3, 3))
      offset = trans._sample_offset(
          self.data_info["gt_polygons"], self.data_info["img"].shape[:2]
      )
      self.assertEqual(offset, (0, 2))
  
      # test the second branch in sample_offset
      mock_sample.side_effect = [1]
      mock_randint.side_effect = [1, 2]
      trans = TextDetRandomCrop(target_size=(3, 3))
      offset = trans._sample_offset(
          self.data_info["gt_polygons"], self.data_info["img"].shape[:2]
      )
      self.assertEqual(offset, (1, 2))
  
      mock_sample.side_effect = [1]
      mock_randint.side_effect = [1, 2]
      trans = TextDetRandomCrop(target_size=(5, 5))
      offset = trans._sample_offset(
          self.data_info["gt_polygons"], self.data_info["img"].shape[:2]
      )
      self.assertEqual(offset, (0, 0))
  
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 TestTextDetRandomCrop obj's underlying member method code with example usage: obj.test_sample_offset(mock_randint, mock_sample) without return types