def test_getConfigValue_asType_notCallable(self, mock_validateconfig): # given as_type = 'a' # when # noinspection PyBroadException try: git.get_config_value('key', as_type=as_type) self.fail('expected exception but found none') # pragma: no cover except Exception as e: # then self.assertEqual(str(e), '{} is not callable'.format(as_type)) mock_validateconfig.assert_called_once()
def test_getConfigValue_asType_throwsException(self, mock_error, mock_stdout, mock_validateconfig): # given key = 'the key' value = 'the value' as_type = TestGit mock_stdout.return_value = value + os.linesep # when try: git.get_config_value(key, as_type=as_type) self.fail('expected to exit but did not') # pragma: no cover except SystemExit: pass # then mock_validateconfig.assert_called_once() mock_stdout.assert_called_with(('git', 'config', key)) mock_error.assert_called_once_with( 'Cannot parse value {0!r} for key {1!r} using format {2!r}'.format( value, key, as_type.__name__))
def test_getConfigValue_withConfig(self, mock_stdout, mock_validateconfig): # given key = 'the key' value = 'the value' mock_stdout.return_value = value + os.linesep # when actual_value = git.get_config_value(key, config='global') # then self.assertEqual(actual_value, value) mock_validateconfig.assert_called_once() mock_stdout.assert_called_with(('git', 'config', '--global', key))
def test_getConfigValue_asType_hasCall(self, mock_stdout, mock_validateconfig): # given key = 'the key' value = 'the value' mock_stdout.return_value = value + os.linesep # when actual_value = git.get_config_value(key, as_type=str) # then self.assertEqual(actual_value, value) mock_validateconfig.assert_called_once() mock_stdout.assert_called_with(('git', 'config', key))
def test_getConfigValue_withDefault_hasValueSoIgnoreDefault( self, mock_stdout, mock_validateconfig): # given key = 'the key' value = 'the value' mock_stdout.return_value = value + os.linesep # when actual_value = git.get_config_value(key, default='the default') # then self.assertEqual(actual_value, value) mock_validateconfig.assert_called_once() mock_stdout.assert_called_with(('git', 'config', key))
def test_getConfigValue_asType_hasBases(self, mock_stdout, mock_validateconfig): # given key = 'the key' value = 'the value' as_type = collections.namedtuple('AsType', ['v']) mock_stdout.return_value = value + os.linesep # when actual_value = git.get_config_value(key, as_type=as_type) # then self.assertIsInstance(actual_value, as_type) self.assertEqual(actual_value.v, value) mock_validateconfig.assert_called_once() mock_stdout.assert_called_with(('git', 'config', key))
def test_getConfigValue_withFile(self, mock_stdout, mock_validateconfig): # given key = 'the key' value = 'the value' file_path = '/path/to/config' mock_stdout.return_value = value + os.linesep # when actual_value = git.get_config_value(key, config='file', file_=file_path) # then self.assertEqual(actual_value, value) mock_validateconfig.assert_called_once() mock_stdout.assert_called_with( ('git', 'config', '--file', file_path, key))