def testSerializedString(self): """Test that we can create configs from strings""" serialized = { "yaml": """ testing: hello formatters: calexp: 3""", "json": '{"testing": "hello", "formatters": {"calexp": 3}}' } for format, string in serialized.items(): c = Config.fromString(string, format=format) self.assertEqual(c["formatters", "calexp"], 3) self.assertEqual(c["testing"], "hello") with self.assertRaises(ValueError): Config.fromString("", format="unknown") with self.assertRaises(ValueError): Config.fromString(serialized["yaml"], format="json") # This JSON can be parsed by YAML parser j = Config.fromString(serialized["json"]) y = Config.fromString(serialized["yaml"]) self.assertEqual(j["formatters", "calexp"], 3) self.assertEqual(j.toDict(), y.toDict()) # Round trip JSON -> Config -> YAML -> Config -> JSON -> Config c1 = Config.fromString(serialized["json"], format="json") yaml = c1.dump(format="yaml") c2 = Config.fromString(yaml, format="yaml") json = c2.dump(format="json") c3 = Config.fromString(json, format="json") self.assertEqual(c3.toDict(), c1.toDict())
def read_server_config() -> Mapping: """Return the butler configuration that the client should use.""" config_str = f""" datastore: root: {BUTLER_ROOT} registry: cls: lsst.daf.butler.registries.remote.RemoteRegistry db: <butlerRoot> """ config = Config.fromString(config_str, format="yaml") return config