

def test_config(self):
    "\n        Test setting, getting, and unsetting config values\n\n        WARNING: This test will modify and completely remove a config section\n        'foo', both in the repo created in setUp() and in the user's global\n        .gitconfig.\n        "

    def _clear_config():
        cmds = (['git', 'config', '--remove-section', 'foo'], ['git', 'config', '--global', '--remove-section', 'foo'])
        for cmd in cmds:
            with open(os.devnull, 'w') as devnull:
                try:
                    subprocess.check_call(cmd, stderr=devnull)
                except subprocess.CalledProcessError:
                    pass
    cfg_local = {
        'foo.single': ['foo'],
        'foo.multi': ['foo', 'bar', 'baz'],
    }
    cfg_global = {
        'foo.single': ['abc'],
        'foo.multi': ['abc', 'def', 'ghi'],
    }
    _clear_config()
    try:
        log.debug('Try to specify both single and multivar (should raise error)')
        self.assertTrue(("Only one of 'value' and 'multivar' is permitted" in self.run_function('git.config_set', ['foo.single'], value=cfg_local['foo.single'][0], multivar=cfg_local['foo.multi'], cwd=self.repo)))
        log.debug('Try to set single local value without cwd (should raise error)')
        self.assertTrue(("'cwd' argument required unless global=True" in self.run_function('git.config_set', ['foo.single'], value=cfg_local['foo.single'][0])))
        log.debug('Set single local value')
        self.assertEqual(self.run_function('git.config_set', ['foo.single'], value=cfg_local['foo.single'][0], cwd=self.repo), cfg_local['foo.single'])
        log.debug('Set single global value')
        self.assertEqual(self.run_function('git.config_set', ['foo.single'], value=cfg_global['foo.single'][0], **{
            'global': True,
        }), cfg_global['foo.single'])
        log.debug('Set local multivar')
        self.assertEqual(self.run_function('git.config_set', ['foo.multi'], multivar=cfg_local['foo.multi'], cwd=self.repo), cfg_local['foo.multi'])
        log.debug('Set global multivar')
        self.assertEqual(self.run_function('git.config_set', ['foo.multi'], multivar=cfg_global['foo.multi'], **{
            'global': True,
        }), cfg_global['foo.multi'])
        log.debug('Get single local value')
        self.assertEqual(self.run_function('git.config_get', ['foo.single'], cwd=self.repo), cfg_local['foo.single'][0])
        log.debug('Get single value from local multivar')
        self.assertEqual(self.run_function('git.config_get', ['foo.multi'], cwd=self.repo), cfg_local['foo.multi'][(- 1)])
        log.debug('Get all values from multivar (includes globals)')
        self.assertEqual(self.run_function('git.config_get', ['foo.multi'], cwd=self.repo, **{
            'all': True,
        }), cfg_local['foo.multi'])
        log.debug('Get single global value')
        self.assertEqual(self.run_function('git.config_get', ['foo.single'], **{
            'global': True,
        }), cfg_global['foo.single'][0])
        log.debug('Get single value from global multivar')
        self.assertEqual(self.run_function('git.config_get', ['foo.multi'], **{
            'global': True,
        }), cfg_global['foo.multi'][(- 1)])
        log.debug('Get all values from global multivar')
        self.assertEqual(self.run_function('git.config_get', ['foo.multi'], **{
            'all': True,
            'global': True,
        }), cfg_global['foo.multi'])
        log.debug('Get all local keys/values using regex')
        self.assertEqual(self.run_function('git.config_get_regexp', ['foo.(single|multi)'], cwd=self.repo), cfg_local)
        log.debug('Get all global keys/values using regex')
        self.assertEqual(self.run_function('git.config_get_regexp', ['foo.(single|multi)'], cwd=self.repo, **{
            'global': True,
        }), cfg_global)
        log.debug("Get just the local foo.multi values containing 'a'")
        self.assertEqual(self.run_function('git.config_get_regexp', ['foo.multi'], value_regex='a', cwd=self.repo), {
            'foo.multi': [x for x in cfg_local['foo.multi'] if ('a' in x)],
        })
        log.debug("Get just the global foo.multi values containing 'a'")
        self.assertEqual(self.run_function('git.config_get_regexp', ['foo.multi'], value_regex='a', cwd=self.repo, **{
            'global': True,
        }), {
            'foo.multi': [x for x in cfg_global['foo.multi'] if ('a' in x)],
        })
        log.debug('Unset a single local value')
        self.assertTrue(self.run_function('git.config_unset', ['foo.single'], cwd=self.repo))
        log.debug('Unset an entire local multivar')
        self.assertTrue(self.run_function('git.config_unset', ['foo.multi'], cwd=self.repo, **{
            'all': True,
        }))
        log.debug('Unset a single global value')
        self.assertTrue(self.run_function('git.config_unset', ['foo.single'], **{
            'global': True,
        }))
        log.debug('Unset an entire local multivar')
        self.assertTrue(self.run_function('git.config_unset', ['foo.multi'], **{
            'all': True,
            'global': True,
        }))
    except Exception:
        raise
    finally:
        _clear_config()

dataset/ETHPy150Open saltstack/salt/tests/integration/modules/git.py GitModuleTest.test_config/original