class AppConfig: dashboard_config_loader: Config def load(self, path_like: str): path = Path(path_like).expanduser().absolute() if not path.parent.is_dir(): path.parent.mkdir(parents=True) self._location = Location(path.parent) self.dashboard_config_loader = Config(path.name, transport=Transport( [self._location])) return self.dashboard_config_loader.load() def save(self): self.dashboard_config_loader.dump(self._location) def init_logger(self, debug: bool): logging.basicConfig( level=logging.DEBUG if debug else logging.INFO, format= '%(asctime)s - %(levelname)s - %(filename)s:%(lineno)s: %(message)s', )
def test_load_simple_found_cwd(): cfg = Config(_data_filename) assert cfg.load() is True assert cfg.data == {"a": 42}
def load() -> PabuConfig: config_loader = Config('pabu.yaml') if not config_loader.load(): return None return tree.load(config_loader.data)
def test_load_simple_climber(): cfg = Config(_data_filename, transport=Transport([ClimberLocation()])) assert cfg.load() is True assert cfg.data == {"a": 84} assert cfg.path == '/home/douglas/teve/' + _data_filename
def test_load_simple_found_etc(): cfg = Config(_data_filename) assert cfg.load() is True assert cfg.data == {"a": 42} assert cfg.path == '/etc/' + _data_filename
def test_not_loaded_single_config_dump(): cfg = Config(_data_filename) cfg.data = {"a": 42} cfg.dump(Location('/etc')) assert os.path.exists('/etc/test1.json')
def load() -> AppConfig: config_loader = Config('scrat.yaml') if not config_loader.load(): raise Exception("config not loaded") app_config: AppConfig = tree.load(config_loader.data) logging.config.dictConfig(app_config.logger) logger.debug("config loaded from %s", config_loader.path) return app_config
def load(self, path_like: str): path = Path(path_like).expanduser().absolute() if not path.parent.is_dir(): path.parent.mkdir(parents=True) self._location = Location(path.parent) self.dashboard_config_loader = Config(path.name, transport=Transport( [self._location])) return self.dashboard_config_loader.load()
def test_loaded_single_config_dump(): cfg = Config(_data_filename) assert cfg.load() cfg.data['a'] = 43 cfg.dump() with open('/etc/' + _data_filename) as f: content = f.read() assert content == '{"a": 43}'
from configpp.soil import Config cfg = Config('app.json') cfg.load() print(cfg.data)
def test_load_simple_not_found(): cfg = Config(_data_filename) assert cfg.load() is False
def test_load_simple_location_order(): cfg = Config(_data_filename) assert cfg.load() is True assert cfg.data == {"a": 84}
def test_guessing_in_ctors(filename, transform): assert isinstance(Config(filename).transform, transform) assert isinstance(GroupMember(filename).transform, transform)