def get_source(self, name): """Get a cr_cache.cache.Cache configured for the source called name. Results are cached in self._sources, and returned from there if present. """ if name in self._sources: return self._sources[name] path = self._source_dirs.get(name) if name == 'local' and path is None: config = {} source_type = find_source_type('local') else: path = os.path.join(path, 'source.conf') with open(path, 'rt') as f: config = yaml.safe_load(f) source_type = find_source_type(config['type']) source = source_type(config, self.get_source) kwargs = {} if 'reserve' in config: reserve = int(config['reserve']) kwargs['reserve'] = reserve result = cache.Cache(name, self._store, source, **kwargs) self._sources[name] = result return result
def test_find_source_type_missing(self): self.assertThat(lambda: find_source_type('foo'), raises(ImportError))
def test_find_source_type(self): self.assertEqual(model.Source, find_source_type('model'))