def test_invalid_config(self): """Test an existing configuration file but invalid""" c = Config(base_dir + '/static/config_invalid.yml') self.assertFalse(c.read()) self.assertGreater(len(c.error), 0) self.assertRegex(c.error, '.*Additional properties are not allowed.*') # The rest doesn't work, for an unknown reason pytest.skip('Error trying to capture stderr') return # Don't go further with python < 3.5 try: from contextlib import redirect_stderr except Exception: return f = io.StringIO() with redirect_stderr(f): c.display_errors() err = f.getvalue() regex = re.compile('.*config_invalid.yml.*', re.MULTILINE) self.assertRegex(err, regex) regex = re.compile('.*Failed validating main config or plugin configs.*', re.MULTILINE) self.assertRegex(err, regex) regex = re.compile('Additional properties are not allowed.*', re.MULTILINE) self.assertRegex(err, regex)
def test_invalid_config(self): """Test an existing configuration file but invalid""" c = Config(base_dir + '/static/config_invalid.ini') self.assertFalse(c.read()) self.assertGreater(len(c.errors), 0) self.assertTrue('project_name' in c.errors) self.assertEqual('Missing', c.errors['project_name']) self.assertTrue('php.version' in c.errors) self.assertEqual('the value "8.0" is unacceptable.', c.errors['php.version']) # Don't go further with python < 3.5 try: from contextlib import redirect_stderr except Exception: return f = io.StringIO() with redirect_stderr(f): c.display_errors() res = f.getvalue() regex = re.compile('Failed validating .*config_invalid.ini', re.MULTILINE) self.assertRegex(res, regex) regex = re.compile('the value ".*8.0.*" is unacceptable', re.MULTILINE) self.assertRegex(res, regex)
def _get_config(self): config = Config(self.config_file) main_config = config.read() if main_config is False: config.display_errors() sys.exit(1) return main_config
def get_config(self): """Read and validate config from config file""" config = Config(self.context['CONFIG']) main_config = config.read() if main_config is False: config.display_errors() sys.exit(1) return main_config
def _get_config(config_file: str): """Read main stakkr.yml file.""" config_reader = Config(config_file) config = config_reader.read() if config is False: config_reader.display_errors() sys.exit(1) return config, config_reader.config_file