예제 #1
0
def test_marten_cli():
    """Test the output of marten cli command"""
    d = {'TEST': 1}

    with print_patch as mock:
        with patch('marten.config', Configuration(d)):
            marten_cli()

        mock.assert_called_once_with('{\n    "TEST": 1\n}')
예제 #2
0
def get_config_from_env():
    """
	Attempt to build and return a Configuration instance based on the files found in the .marten directory matching the
	MARTEN_ENV environment variable
	"""
    marten_dir = os.path.join(os.getcwd(), '.marten')

    if os.path.isdir(marten_dir):
        config = parse_directory(marten_dir, os.environ['MARTEN_ENV'])
    else:
        config = Configuration({})

    return config
예제 #3
0
def parse_directory(path, name):
    """
	Parse path for all supported config file types beginning with name

	Merges multiple configs with the same name into a single Configuration instance, overriding duplicate attributes in
	order files were loaded

	Ignores files with unsupported extensions
	"""
    merged_raw_configs = {}

    supported_extensions = get_supported_extensions()

    for filename in os.listdir(path):
        if filename.startswith(name):
            ext = filename.split(name, 1)[1]
            if ext in supported_extensions:
                config = supported_extensions[ext](os.path.join(
                    path, filename))
                merged_raw_configs.update(config.raw_config)

    return Configuration(merged_raw_configs)
 def get_configuration(self):
     return Configuration(self.sample_source_dict)