def test_pass_extra_variables(instantiate_func: Any) -> None: cfg = OmegaConf.create({ "_target_": "tests.instantiate.AClass", "a": 10, "b": 20 }) assert instantiate_func(cfg, c=30) == AClass(a=10, b=20, c=30)
def test_class_instantiate_omegaconf_node(instantiate_func: Any, config: Any) -> Any: obj = instantiate_func(config, a=10, d=AnotherClass(99)) assert obj == AClass(a=10, b=200, c={ "x": 10, "y": 200 }, d=AnotherClass(99)) assert OmegaConf.is_config(obj.c)
"recursive", [param(False, id="not_recursive"), param(True, id="recursive")]) @mark.parametrize( "src, passthrough, expected", [ param( { "_target_": "tests.instantiate.AClass", "a": 10, "b": 20, "c": 30, "d": 40, }, {}, AClass(10, 20, 30, 40), id="class", ), param( { "_target_": "tests.instantiate.AClass", "b": 20, "c": 30 }, { "a": 10, "d": 40 }, AClass(10, 20, 30, 40), id="class+override", ),