def test_10_find_by_file(self): ini_cf = "/a/b/c.ini" jsn_cf = "/a/b/c.jsn" yml_cf = "/a/b/c.yml" unknown_cf = "/a/b/c.xyz" def instchk(cf, cls): isinstance(T.find_by_file(cf), cls) self.assertTrue(ini_cf, T.BINI.IniConfigParser) self.assertTrue(jsn_cf, T.BJSON.JsonConfigParser) self.assertTrue(yml_cf, T.BYAML.YamlConfigParser) self.assertTrue(T.find_by_file(unknown_cf) is None)
def test_10_find_by_file(self): ini_cf = "/a/b/c.ini" unknown_cf = "/a/b/c.xyz" jsn_cfs = ["/a/b/c.jsn", "/a/b/c.json", "/a/b/c.js"] yml_cfs = ["/a/b/c.yml", "/a/b/c.yaml"] self.assertTrue(ini_cf, T.BINI.IniConfigParser) self.assertTrue(T.find_by_file(unknown_cf) is None) for f in jsn_cfs: self.assertTrue(f, T.BJSON.JsonConfigParser) for f in yml_cfs: self.assertTrue(f, T.BYAML.YamlConfigParser)
def find_loader(config_path, forced_type=None): """ :param config_path: Configuration file path :param forced_type: Forced configuration parser type :return: ConfigParser-inherited class object """ if forced_type is not None: cparser = Backends.find_by_type(forced_type) if not cparser: logging.error("No parser found for given type: " + forced_type) return None else: cparser = Backends.find_by_file(config_path) if not cparser: logging.error("No parser found for given file: " + config_path) return None logging.debug("Using config parser of type: " + cparser.type()) return cparser
def find_loader(config_path, forced_type=None): """ :param config_path: Configuration file path :param forced_type: Forced configuration parser type """ if forced_type is not None: cparser = Backends.find_by_type(forced_type) if not cparser: logging.error( "No parser found for given type: " + forced_type ) return None else: cparser = Backends.find_by_file(config_path) if not cparser: logging.error( "No parser found for given file: " + config_path ) return None logging.debug("Using config parser: " + str(cparser)) return cparser
def instchk(cf, cls): isinstance(T.find_by_file(cf), cls)