code: def test_OptimizerDataclassField():
      # Test default case:
      default_optimizer_field = lso.OptimizerDataclassField()
      assert default_optimizer_field.default_factory is not None
      assert (
          get_marshmallow_from_dataclass_field(
              default_optimizer_field
          ).allow_none
          is False
      )
      assert (
          default_optimizer_field.default_factory()
          == lso.AdamOptimizerConfig()
      )
  
      # Test normal cases:
      optimizer_field = lso.OptimizerDataclassField("adamax")
      assert optimizer_field.default_factory is not None
      assert (
          get_marshmallow_from_dataclass_field(
              optimizer_field
          ).allow_none
          is False
      )
      assert (
          optimizer_field.default_factory()
          == lso.AdamaxOptimizerConfig()
      )
  
      # Test invalid default case:
      with pytest.raises(AttributeError):
          lso.OptimizerDataclassField({})
      with pytest.raises(KeyError):
          lso.OptimizerDataclassField("test")
      with pytest.raises(AttributeError):
          lso.OptimizerDataclassField(1)
  
      # Test creating a schema with default options:
      @dataclass
      class CustomTestSchema(schema_utils.BaseMarshmallowConfig):
          foo: Optional[
              lso.BaseOptimizerConfig
          ] = lso.OptimizerDataclassField()
  
      with pytest.raises(MarshmallowValidationError):
          CustomTestSchema.Schema().load({"foo": "test"})
  
      assert (
          CustomTestSchema.Schema().load({}).foo
          == lso.AdamOptimizerConfig()
      )
  
      # Test creating a schema with set default:
      @dataclass
      class CustomTestSchema(schema_utils.BaseMarshmallowConfig):
          foo: Optional[
              lso.BaseOptimizerConfig
          ] = lso.OptimizerDataclassField("adamax")
  
      with pytest.raises(MarshmallowValidationError):
          CustomTestSchema.Schema().load({"foo": None})
      with pytest.raises(MarshmallowValidationError):
          CustomTestSchema.Schema().load({"foo": "test"})
      with pytest.raises(MarshmallowValidationError):
          CustomTestSchema.Schema().load(
              {"foo": {"type": "invalid", "betas": (0.2, 0.2)}}
          )
  
      assert CustomTestSchema.Schema().load(
          {"foo": {"type": "adamax", "betas": (0.2, 0.2)}}
      ).foo == lso.AdamaxOptimizerConfig(betas=(0.2, 0.2))
      assert CustomTestSchema.Schema().load(
          {
              "foo": {
                  "type": "adamax",
                  "betas": (0.2, 0.2),
                  "extra_key": 1,
              }
          }
      ).foo == lso.AdamaxOptimizerConfig(betas=(0.2, 0.2))
  
file_path: ludwig/tests/ludwig/marshmallow/test_fields_optimization.py
imports: from typing import Optional
  import pytest
  from marshmallow.exceptions import ValidationError
  from marshmallow_dataclass import dataclass
  import ludwig.schema.optimizers
  from ludwig.schema import utils
label_desc: Use image node_id 3 for calling a global function with example usage: test_OptimizerDataclassField() without return types