Exemplo n.º 1
0
    def test_should_not_pass_debug_to_command_when_debug_option_is_given(
            self, mock_configuration_class, mock_execute_command, mock_exit, mock_logger):

        mock_configuration = Mock()
        mock_configuration.execute_before = '/bin/true'
        mock_configuration_class.return_value = mock_configuration
        mock_command = Mock()

        ScriptCommand(mock_command)(['/usr/local/bin/commit', 'Committing spree ...', '--debug'])

        mock_command.assert_called_with(['/usr/local/bin/commit', 'Committing spree ...'], mock_configuration)
Exemplo n.º 2
0
    def test_should_execute_motivation_command_when_activated(
            self, mock_load_configuration, mock_execute_motivation_command, mock_execute_command, mock_commit,
            mock_exists, mock_exit):

        mock_configuration = Mock()
        mock_configuration.execute_before = False
        mock_configuration.execute_before_commit = False
        mock_configuration.motivate_me = True
        mock_load_configuration.return_value = mock_configuration

        commit_changes(['/usr/local/bin/commit'])

        mock_execute_motivation_command.assert_called_with(mock_configuration)
Exemplo n.º 3
0
    def test_should_not_execute_motivation_command_when_not_activated(
            self, mock_load_configuration, mock_execute_motivation_command, mock_execute_command, mock_commit,
            mock_exists, mock_exit):

        mock_configuration = Mock()
        mock_configuration.execute_before = False
        mock_configuration.execute_before_commit = False
        mock_configuration.motivate_me = False
        mock_load_configuration.return_value = mock_configuration

        commit_changes(['/usr/local/bin/commit'])

        self.assertEqual([], mock_execute_motivation_command.call_args_list)
Exemplo n.º 4
0
    def test_should_execute_given_command_function(
            self, mock_configuration_class, mock_execute_command, mock_exit, mock_logger):

        mock_configuration = Mock()
        mock_configuration.execute_before = '/bin/true'
        mock_configuration_class.return_value = mock_configuration
        mock_command = Mock()
        arguments = ['/usr/local/bin/commit']

        ScriptCommand(mock_command)(arguments)

        mock_command.assert_called_with(arguments, mock_configuration)
        mock_exit.assert_called_with(0)
Exemplo n.º 5
0
    def test_should_not_execute_command_before_when_displaying_help_since_help_exits(self, mock_execute_command, mock_exit, mock_logger):
        mock_command = Mock()
        mock_configuration = Mock()
        mock_configuration.execute_before = '/usr/bin/true'
        mock_script_command = Mock(ScriptCommand)
        mock_script_command.function = mock_command
        mock_script_command._read_configuration_file.return_value = mock_configuration
        mock_script_command._filter_unused_argument_dash_m.return_value = ['/usr/local/bin/commit', '--version']
        mock_script_command._handle_help_argument.side_effect = SystemExit(123)

        try:
            ScriptCommand.__call__(mock_script_command, ['/usr/local/bin/commit', '--version'])
        except SystemExit as system_exit:
            self.assertEqual(system_exit.code, 123)

        self.assertEqual(0, mock_execute_command.call_count)