code: def test_register(self):
      # Case 1: We try to register a config that was already registered, it should not register anything.
      register_for_onnx = TasksManager.create_register("onnx")
  
      @register_for_onnx("bert", "text-classification")
      class BadBertOnnxConfig(BertOnnxConfig):
          pass
  
      bert_config_constructor = (
          TasksManager.get_exporter_config_constructor(
              "onnx",
              model_type="bert",
              task="text-classification",
          )
      )
      bert_onnx_config = bert_config_constructor(BertConfig())
  
      self.assertNotEqual(
          bert_onnx_config.__class__,
          BadBertOnnxConfig,
          "Registering an already existing config constructor should not do anything unless overwrite_existing=True.",
      )
  
      # Case 2: We try to register a config that was already registered, but authorize overwriting, it should register
      # the new config.
      register_for_onnx = TasksManager.create_register(
          "onnx", overwrite_existing=True
      )
  
      @register_for_onnx("bert", "text-classification")
      class BadBertOnnxConfig2(BertOnnxConfig):
          pass
  
      bert_config_constructor = (
          TasksManager.get_exporter_config_constructor(
              "onnx",
              model_type="bert",
              task="text-classification",
          )
      )
      bert_onnx_config = bert_config_constructor(BertConfig())
  
      self.assertEqual(
          bert_onnx_config.__class__,
          BadBertOnnxConfig2,
          (
              "Registering an already existing config constructor with overwrite_existing=True should overwrite the "
              "old config constructor."
          ),
      )
  
      # Case 3: Registering an unknown task.
      with self.assertRaisesRegex(
          ValueError, "The TasksManager does not know the task called"
      ):
  
          @register_for_onnx("bert", "this is a wrong name for a task")
          class UnknownTask(BertOnnxConfig):
              pass
  
      # Case 4: Registering for a new backend.
      register_for_new_backend = TasksManager.create_register(
          "new-backend"
      )
  
      @register_for_new_backend("bert", "text-classification")
      class BertNewBackendConfig(BertOnnxConfig):
          pass
  
      bert_config_constructor = (
          TasksManager.get_exporter_config_constructor(
              "new-backend",
              model_type="bert",
              task="text-classification",
          )
      )
      bert_onnx_config = bert_config_constructor(BertConfig())
  
      self.assertEqual(
          bert_onnx_config.__class__,
          BertNewBackendConfig,
          "Wrong config class compared to the registered one.",
      )
  
      # Case 5: Registering a new task for a already existing backend.
      @register_for_new_backend("bert", "token-classification")
      class BertNewBackendConfigTaskSpecific(BertOnnxConfig):
          pass
  
      bert_config_constructor = (
          TasksManager.get_exporter_config_constructor(
              "new-backend",
              model_type="bert",
              task="token-classification",
          )
      )
      bert_onnx_config = bert_config_constructor(BertConfig())
  
      self.assertEqual(
          bert_onnx_config.__class__,
          BertNewBackendConfigTaskSpecific,
          "Wrong config class compared to the registered one.",
      )
  
file_path: optimum/tests/exporters/common/test_tasks_manager.py
imports: import importlib
  import inspect
  from typing import Optional, Set
  from unittest import TestCase
  import pytest
  from transformers import BertConfig, Pix2StructForConditionalGeneration, VisualBertForQuestionAnswering
  from transformers.testing_utils import slow
  from optimum.exporters import TasksManager
  from optimum.exporters.onnx.model_configs import BertOnnxConfig
label_desc: Use image node_id 4 for calling the TasksManagerTestCase obj's underlying member method code with example usage: obj.test_register() without return types