def test_parser_conf_dict_type_is_not_dict(): with pytest.raises(ConfParserException): ConfParser(conf_dict=1) with pytest.raises(ConfParserException): ConfParser(conf_dict='test') with pytest.raises(ConfParserException): ConfParser(conf_dict=()) with pytest.raises(ConfParserException): ConfParser(conf_dict=[])
def setUp(self): conf = open('testdata/test.txts.conf') try: self.confparser = ConfParser(conf.readlines()) finally: conf.close() self.expected_styles = []
def test_parser_with_conf_dict(): config = ConfParser(conf_dict={ 'debug': True, 'server': { 'dev': { 'debug': True, 'port': 8000, }, 'prod': { 'debug': False, 'port': 80, } } }, ).to_obj() assert isinstance(config, ConfParserDict) assert config == { 'debug': True, 'server': { 'dev': { 'debug': True, 'port': 8000 }, 'prod': { 'debug': False, 'port': 80 } } } assert config.debug is True assert isinstance(config.server, ConfParserDict) assert config.server == { 'dev': { 'debug': True, 'port': 8000 }, 'prod': { 'debug': False, 'port': 80 } } assert isinstance(config.server.dev, ConfParserDict) assert config.server.dev == {'debug': True, 'port': 8000} assert isinstance(config.server.prod, ConfParserDict) assert config.server.prod == {'debug': False, 'port': 80} assert config.server.dev.debug is True assert config.server.dev.port == 8000 assert config.server.prod.debug is False assert config.server.prod.port == 80
def __init__(self, kerberosPath, confPath=None, rulesPath=None, hfilePath=None): self.parser = ConfParser(kerberosPath) if confPath is not None: content = self._readConfigFile(confPath) rulesPath = content['RulesPath'] hfilePath = content['HfilePath'] if rulesPath is not None and hfilePath is not None: self.rules = self._loadRules(rulesPath) self.validKeys = SupportedKeys(hfilePath).validKeys.union( self.rules['Attributes']) else: raise ValueError( 'Invalid arguments for validator: no path to rules and definition files' ) self._attribute_pattern = re.compile(r'^\w+$') self._lowercase_pattern = re.compile(r'[a-z]')
def test_parser_with_do_not_exist_path(): with pytest.raises(ConfParserException): ConfParser(path='unknown')
def test_parser_with_path_and_conf_dict(): with pytest.raises(ConfParserException): ConfParser(path='./config.yml', conf_dict={'debug': True})
def test_parser_with_none_path_and_none_conf_dict(): with pytest.raises(ConfParserException): ConfParser()
def _load_conf(self): return ConfParser(self.server_name)