def from_file(cls, config_path=None, *args, **kwargs): """Create a Cihai instance from a JSON or YAML config. :param config_path: path to custom config file :type config_path: str :rtype: :class:`Cihai` """ config_reader = kaptan.Kaptan() config = {} if config_path: if not os.path.exists(config_path): raise exc.CihaiException( '{0} does not exist.'.format(os.path.abspath(config_path))) if not any( config_path.endswith(ext) for ext in ('json', 'yml', 'yaml', 'ini') ): raise exc.CihaiException( '{0} does not have a yaml,yml,json,ini extension.' .format(os.path.abspath(config_path)) ) else: custom_config = config_reader.import_config(config_path).get() config = merge_dict(config, custom_config) return cls(config)
def test_base_exception(): with pytest.raises( exc.CihaiException, message="Make sure no one removes or renames base CihaiException"): raise exc.CihaiException() with pytest.raises(Exception, message="Extends python base exception"): raise exc.CihaiException()
def test_base_exception(): with pytest.raises(exc.CihaiException): raise exc.CihaiException() # Make sure its base of CihaiException with pytest.raises(Exception): raise exc.CihaiException() # Extends python base exception