示例#1
0
文件: config.py 项目: jreese/edi
    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)
示例#2
0
文件: yaml.py 项目: jreese/ent
    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)
示例#3
0
文件: config.py 项目: jreese/edi
    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)