code: def test_ClipperDataclassField():
      # Test default case:
      default_clipper_field = lso.GradientClippingDataclassField(
          description="", default={}
      )
      assert default_clipper_field.default_factory is not None
      assert (
          get_marshmallow_from_dataclass_field(
              default_clipper_field
          ).allow_none
          is True
      )
      assert (
          default_clipper_field.default_factory()
          == lso.GradientClippingConfig()
      )
  
      # Test normal cases:
      clipper_field = lso.GradientClippingDataclassField(
          description="", default={"clipglobalnorm": 0.1}
      )
      assert clipper_field.default_factory is not None
      assert (
          get_marshmallow_from_dataclass_field(clipper_field).allow_none
          is True
      )
      assert (
          clipper_field.default_factory()
          == lso.GradientClippingConfig(clipglobalnorm=0.1)
      )
  
      clipper_field = lso.GradientClippingDataclassField(
          description="", default={"clipglobalnorm": None}
      )
      assert clipper_field.default_factory is not None
      assert (
          get_marshmallow_from_dataclass_field(clipper_field).allow_none
          is True
      )
      assert (
          clipper_field.default_factory()
          == lso.GradientClippingConfig(clipglobalnorm=None)
      )
  
      # Test invalid default case:
      with pytest.raises(MarshmallowValidationError):
          lso.GradientClippingDataclassField(
              description="", default="test"
          )
      with pytest.raises(MarshmallowValidationError):
          lso.GradientClippingDataclassField(
              description="", default=None
          )
      with pytest.raises(MarshmallowValidationError):
          lso.GradientClippingDataclassField(description="", default=1)
  
      # Test creating a schema with set default:
      @dataclass
      class CustomTestSchema(schema_utils.BaseMarshmallowConfig):
          foo: Optional[
              lso.GradientClippingConfig
          ] = lso.GradientClippingDataclassField(
              description="", default={"clipglobalnorm": 0.1}
          )
  
      with pytest.raises(MarshmallowValidationError):
          CustomTestSchema.Schema().load({"foo": "test"})
      with pytest.raises(MarshmallowValidationError):
          CustomTestSchema.Schema().load(
              {"foo": {"clipglobalnorm": "invalid"}}
          )
  
      assert CustomTestSchema.Schema().load(
          {}
      ).foo == lso.GradientClippingConfig(clipglobalnorm=0.1)
      assert CustomTestSchema.Schema().load(
          {"foo": {"clipglobalnorm": 1}}
      ).foo == lso.GradientClippingConfig(clipglobalnorm=1)
      assert CustomTestSchema.Schema().load(
          {"foo": {"clipglobalnorm": 1, "extra_key": 1}}
      ).foo == lso.GradientClippingConfig(clipglobalnorm=1)
  
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 4 for calling a global function with example usage: test_ClipperDataclassField() without return types