def _create_api(self, opts, args): """Create an API, as requested by the command.""" options = {} options['documentroot'] = opts.docroot options['configfile'] = opts.cfgfile options['logfile'] = opts.logfile options = init_options(options) init_logger(options) init_codecs(options) api = API() if 'options' in self.require_api: api.options = options if 'logger' in self.require_api: api.logger = logging.getLogger('draco2.site') if 'config' in self.require_api: api.config = Config._create(api) if 'loader' in self.require_api: api.loader = Loader._create(api) if 'events' in self.require_api: api.events = EventManager._create(api) if 'database' in self.require_api: api.database = DatabaseManager._create(api) if opts.dsn: api.database._set_dsn(dsn) if 'models' in self.require_api: api.models = ModelManager._create(api) return api
def setup_method(cls, method): tempdir = tempfile.gettempdir() subdir = 'dracotest_%d' % os.getpid() docroot = os.path.join(tempdir, subdir) os.mkdir(docroot) cls.docroot = docroot cls.files = [] cls.directories = [docroot] options = { 'documentroot': docroot } options = init_options(options) config = Config(options) config.add_file(os.environ['TESTCONFIG']) cls.config = config loader = Loader() loader.add_scope('__docroot__', docroot) cls.loader = loader
def create_config(self, text): fname = self.config_file(text) cfg = Config() cfg.add_file(fname) return cfg
def test_reload(self): fname = self.config_file(self.cfgold) cfg = Config() cfg.add_file(fname) ns = cfg.ns('section1') assert ns['key1'] == 'value11' ns = cfg.ns('section2') assert ns['key2'] == 'value12' ns = cfg.ns('section3') assert not ns.has_key('key3') fname = self.config_file(self.cfgnew, fname=fname) api = API() cfg._change_callback(api) ns = cfg.ns('section1') assert ns['key1'] == 'value21' ns = cfg.ns('section2') assert not ns.has_key('key2') ns = cfg.ns('section3') assert ns['key3'] == 'value23'
def test_shadow(self): fname = self.config_file(self.cfgtext1) cfg = Config() cfg.add_file(fname) ns = cfg.ns('section1') assert ns['key1'] == 'value11' ns = cfg.ns('section2') assert ns['key2'] == 'value12' ns = cfg.ns('section3') assert not ns.has_key('key3') fname = self.config_file(self.cfgtext2) cfg.add_file(fname) ns = cfg.ns('section1') assert ns['key1'] == 'value21' ns = cfg.ns('section2') assert ns['key2'] == 'value12' ns = cfg.ns('section3') assert ns['key3'] == 'value23'