code: def test_init(self):
      tmp_dir = tempfile.TemporaryDirectory()
      dict_file = osp.join(tmp_dir.name, "fake_chars.txt")
      create_dummy_dict_file(dict_file)
      # test diction cfg
      dict_cfg = dict(
          type="Dictionary",
          dict_file=dict_file,
          with_start=True,
          with_end=True,
          same_start_end=False,
          with_padding=True,
          with_unknown=True,
      )
      base_recog_loss = BaseTextRecogModuleLoss(dict_cfg)
      self.assertIsInstance(base_recog_loss.dictionary, Dictionary)
      # test case mode
      with self.assertRaises(AssertionError):
          base_recog_loss = BaseTextRecogModuleLoss(
              dict_cfg, letter_case="no"
          )
      # test invalid pad_with
      with self.assertRaises(AssertionError):
          base_recog_loss = BaseTextRecogModuleLoss(
              dict_cfg, pad_with="test"
          )
      # test invalid combination of dictionary and pad_with
      dict_cfg = dict(
          type="Dictionary", dict_file=dict_file, with_end=False
      )
      for pad_with in ["end", "padding"]:
          with self.assertRaisesRegex(
              ValueError,
              f'pad_with="{pad_with}", but'
              f" dictionary.{pad_with}_idx is None",
          ):
              base_recog_loss = BaseTextRecogModuleLoss(
                  dict_cfg, pad_with=pad_with
              )
      with self.assertRaisesRegex(
          ValueError,
          'pad_with="auto", but'
          " dictionary.end_idx and dictionary.padding_idx are both"
          " None",
      ):
          base_recog_loss = BaseTextRecogModuleLoss(
              dict_cfg, pad_with="auto"
          )
  
      # test dictionary is invalid type
      dict_cfg = ["tmp"]
      with self.assertRaisesRegex(
          TypeError,
          (
              "The type of dictionary should be `Dictionary`"
              " or dict, "
              f"but got {type(dict_cfg)}"
          ),
      ):
          base_recog_loss = BaseTextRecogModuleLoss(dict_cfg)
  
      tmp_dir.cleanup()
  
file_path: mmocr/tests/test_models/test_textrecog/test_module_losses/test_base_recog_module_loss.py
imports: import os.path
  import tempfile
  from unittest import TestCase
  import numpy
  import torch
  from mmengine.structures import LabelData
  from mmocr.models.common.dictionary import Dictionary
  from mmocr.models.textrecog.module_losses import BaseTextRecogModuleLoss
  from mmocr.structures import TextRecogDataSample
  from mmocr.testing import create_dummy_dict_file
label_desc: Use image node_id 2 for calling the TestBaseRecogModuleLoss obj's underlying member method code with example usage: obj.test_init() without return types