Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2020
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.29 KB | None | 0 0
  1.  
  2. def test_overlapping_schemas(restore_singletons: Any) -> None:  # noqa: F811
  3.     @dataclass
  4.     class Plugin:
  5.         name: str = MISSING
  6.         params: Dict[str, Any] = MISSING
  7.  
  8.     @dataclass
  9.     class ConcretePlugin:
  10.         name: str = "foobar_plugin"
  11.  
  12.         @dataclass
  13.         class FoobarParams:
  14.             foo: int = 10
  15.  
  16.         params: FoobarParams = FoobarParams()
  17.  
  18.     @dataclass
  19.     class Config:
  20.         plugin: Plugin = Plugin()
  21.  
  22.     cs = ConfigStore.instance()
  23.     cs.store(name="config", node=Config)
  24.     cs.store(group="plugin", name="concrete", node=ConcretePlugin, path="plugin")
  25.  
  26.     config_loader = ConfigLoaderImpl(config_search_path=create_config_search_path(None))
  27.     cfg = config_loader.load_configuration(config_name="config", overrides=[])
  28.     del cfg["hydra"]
  29.     assert cfg == {"plugin": {"name": "???", "params": "???"}}
  30.     assert cfg.plugin._type == Plugin
  31.  
  32.     cfg = config_loader.load_configuration(
  33.         config_name="config", overrides=["plugin=concrete"]
  34.     )
  35.     del cfg["hydra"]
  36.     assert cfg == {"plugin": {"name": "foobar_plugin", "params": {"foo": 10}}}
  37.     assert cfg.plugin._type == ConcretePlugin
  38.     assert cfg.plugin.params._type == ConcretePlugin.FoobarParams
  39.     with pytest.raises(ValidationError):
  40.         cfg.plugin = 10
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement