def test_flatten_dict():
    """Validate flatten_dict can handle nested dictionaries and argparse Namespace."""
    # Test basic dict flattening with custom delimiter
    params = {"a": {"b": "c"}}
    params = _flatten_dict(params, "--")

    assert "a" not in params
    assert params["a--b"] == "c"

    # Test complex nested dict flattening
    params = {"a": {5: {"foo": "bar"}}, "b": 6, "c": {7: [1, 2, 3, 4], 8: "foo", 9: {10: "bar"}}}
    params = _flatten_dict(params)

    assert "a" not in params
    assert params["a/5/foo"] == "bar"
    assert params["b"] == 6
    assert params["c/7"] == [1, 2, 3, 4]
    assert params["c/8"] == "foo"
    assert params["c/9/10"] == "bar"

    # Test list of nested dicts flattening
    params = {"dl": [{"a": 1, "c": 3}, {"b": 2, "d": 5}], "l": [1, 2, 3, 4]}
    params = _flatten_dict(params)

    assert params == {"dl/0/a": 1, "dl/0/c": 3, "dl/1/b": 2, "dl/1/d": 5, "l": [1, 2, 3, 4]}

    # Test flattening of argparse Namespace
    params = Namespace(a=1, b=2)
    wrapping_dict = {"params": params}
    params = _flatten_dict(wrapping_dict)

    params_type = type(params)  # way around needed for Ruff's `isinstance` suggestion
    assert params_type is dict
    assert params["params/a"] == 1
    assert params["params/b"] == 2
    assert "a" not in params
    assert "b" not in params

    # Test flattening of dataclass objects
    @dataclass
    class A:
        c: int
        d: int

    @dataclass
    class B:
        a: A
        b: int

    params = {"params": B(a=A(c=1, d=2), b=3), "param": 4}
    params = _flatten_dict(params)
    assert params == {"param": 4, "params/b": 3, "params/a/c": 1, "params/a/d": 2}
Validate flatten_dict can handle nested dictionaries and argparse Namespace.
tests/tests_fabric/utilities/test_logger.py