def load_defaults(cls) -> 'Config': '''Load the default configuration and return the object.''' cwd = path.abspath(path.dirname(__file__)) defaults_path = path.join(cwd, 'defaults.yaml') with open(defaults_path) as fd: contents = yaml.safe_load(fd) return Config.load(contents)
def test_load_types(self): self.assertIsInstance(safe_load('1'), int) self.assertIsInstance(safe_load('1.0'), float) self.assertIsInstance(safe_load('true'), bool) self.assertIsInstance(safe_load('"foo"'), basestring) self.assertIsInstance(safe_load('[]'), list) self.assertIsInstance(safe_load('{}'), Ent) self.assertIs(safe_load('null'), None)
def load_from_file(cls, file_path) -> 'Config': '''Given a path to a local configuration file, read the config file and merge its contents onto the default configuration.''' defaults = cls.load_defaults() with open(file_path) as fd: contents = yaml.safe_load(fd) overrides = Config.load(contents) return Config.merge(defaults, overrides)