def __getattribute__(self, name): # attempt to use any attributes first value = object.__getattribute__(self, name) if value: LOG.debug("Retrieved '{}' setting from cache".format(name)) return value # fallback to reading from git config otherwise value = utils.git_config('pw.{}'.format(name)) if value: LOG.debug("Retrieved '{}' setting from git-config".format(name)) setattr(self, name, value) return value
def __getattribute__(self, name): # attempt to use any attributes first try: value = super(Config, self).__getattribute__(name) except AttributeError: value = None if value: LOG.debug("Retrieved '{}' setting from cache".format(name)) return value # fallback to reading from git config otherwise value = utils.git_config('pw.{}'.format(name)) if value: LOG.debug("Retrieved '{}' setting from git-config".format(name)) setattr(self, name, value) return value
def test_git_config_error(mock_subprocess): value = utils.git_config('foo') assert value == ''
def test_git_config_unicode(mock_subprocess): value = utils.git_config('foo') assert value == u'\U0001f937' mock_subprocess.assert_called_once_with(['git', 'config', 'foo'])
def test_git_config(mock_subprocess): value = utils.git_config('foo') assert value == 'bar' mock_subprocess.assert_called_once_with(['git', 'config', 'foo'])