def test_default_config(self): """Test the default config (exit if it exists)""" if os.path.isfile(package_utils.get_venv_basedir() + '/conf/compose.ini'): return c = Config() with self.assertRaisesRegex(IOError, "Config file .*compose.ini does not exist"): c.read()
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 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 _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 test_valid_config_no_project(self): """Test an existing and valid configuration file""" c = Config(base_dir + '/static/config_valid_network.yml') config = c.read() self.assertIs(dict, type(config)) self.assertTrue('services' in config) self.assertTrue('project_name' in config) self.assertEqual('testnet', config['project_name'])
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.display_errors() sys.exit(1) return config, config_reader.config_file
def test_valid_config(self): """Test an existing and valid configuration file""" c = Config(base_dir + '/static/stakkr.yml') config = c.read() self.assertIs(dict, type(config)) self.assertTrue('services' in config) self.assertTrue('php' in config['services']) self.assertTrue('version' in config['services']['php']) self.assertTrue('enabled' in config['services']['php']) self.assertEqual(7.2, config['services']['php']['version']) self.assertTrue(config['services']['php']['enabled']) self.assertTrue('apache' not in config['services']) self.assertTrue('project_name' in config) self.assertEqual('static', config['project_name'])
def test_valid_config(self): """Test an existing and valid configuration file""" from configobj import ConfigObj c = Config(base_dir + '/static/config_valid.ini') config = c.read() self.assertIs(ConfigObj, type(config)) self.assertTrue('main' in config) self.assertTrue('services' in config['main']) self.assertTrue('php' in config['main']['services']) self.assertFalse('apache' in config['main']['services']) self.assertTrue('project_name' in config['main']) self.assertEqual('test', config['main']['project_name']) self.assertTrue('php.version' in config['main']) self.assertEqual('7.2', config['main']['php.version'])
def test_valid_config(self): """Test an existing and valid configuration file""" from configobj import ConfigObj c = Config(base_dir + '/static/config_valid.ini') config = c.read() self.assertIs(ConfigObj, type(config)) self.assertTrue('main' in config) self.assertTrue('services' in config['main']) self.assertTrue('php' in config['main']['services']) self.assertFalse('apache' in config['main']['services']) self.assertTrue('project_name' in config['main']) self.assertEqual('test', config['main']['project_name']) self.assertTrue('php.version' in config['main']) self.assertEqual('7.0', config['main']['php.version'])
def test_bad_config(self): """Test a non existing configuration file""" c = Config('/does/not/exists') with self.assertRaisesRegex(IOError, "Config file /does/not/exists does not exist"): c.read()
def test_bad_config(self): """Test a non existing configuration file""" c = Config('/does/not/exists.yml') with self.assertRaisesRegex(IOError, "No such file or directory: '/does/not/exists.yml'"): c.read()
def test_bad_config(self): """Test a non existing configuration file""" c = Config('/does/not/exists') with self.assertRaisesRegex( IOError, "Config file /does/not/exists does not exist"): c.read()