<commit_before>
import os
import sys
import re
import pytest
import json
import signal
from unittest.mock import Mock, MagicMock

from cement import App, Controller, ex
from cement.core.handler import Handler
from cement.core.exc import CaughtSignal, FrameworkError
from cement.core.foundation import TestApp
from cement.core.foundation import add_handler_override_options
from cement.core.foundation import handler_override
from cement.core.foundation import cement_signal_handler
from cement.utils.misc import minimal_logger, init_defaults
from cement.utils import test, fs, misc


def pre_render_hook(app, data):
    return data


def test_add_handler_override_options():
    class MyApp(TestApp):
        class Meta:
            extensions = ['json', 'yaml', 'mustache', 'tabulate']

    with MyApp() as app:
        # coverage for explicitly disabling handler_override_options
        app._meta.handler_override_options = None
        add_handler_override_options(app)

        # coverage for case where the interface doesn't exist
        app._meta.handler_override_options = {
            'bogus': (['--bogus'], {'help': 'bogus handler'}),
        }
        add_handler_override_options(app)

    # coverage for case where there is an output handler, but it's not
    # overridable (so no options to display in --help)
    class MyApp2(TestApp):
        class Meta:
            extensions = ['mustache']

    with MyApp2() as app:
        app.run()


def test_handler_override():
    class MyApp(TestApp):
        class Meta:
            argv = ['-o', 'json']
            extensions = ['json', 'yaml', 'mustache', 'tabulate']

    with MyApp() as app:
        app.run()

    # coverage
    app._meta.handler_override_options = None
    handler_override(app)


def test_cement_signal_handler():
    # coverage
    with pytest.raises(CaughtSignal):
        mframe = Mock()
        mframe.f_globals.values = MagicMock(return_value=[TestApp()])
        cement_signal_handler(1, mframe)
        mframe.f_globals.values.assert_called()
<commit_msg>Add assertions<commit_after>
import os
import sys
import re
import pytest
import json
import signal
from unittest.mock import Mock, MagicMock, patch

from cement import App, Controller, ex
from cement.core.handler import Handler
from cement.core.exc import CaughtSignal, FrameworkError
from cement.core.foundation import TestApp
from cement.core.foundation import add_handler_override_options
from cement.core.foundation import handler_override
from cement.core.foundation import cement_signal_handler
from cement.core.foundation import LOG
from cement.utils.misc import minimal_logger, init_defaults
from cement.utils import test, fs, misc


def pre_render_hook(app, data):
    return data


log_stub = Mock()

@patch('cement.core.foundation.LOG.debug', log_stub)
def test_add_handler_override_options():
    class MyApp(TestApp):
        class Meta:
            extensions = ['json', 'yaml', 'mustache', 'tabulate']

    with MyApp() as app:
        app.args.add_argument = Mock()
        # coverage for explicitly disabling handler_override_options
        app._meta.handler_override_options = None
        add_handler_override_options(app)
        assert not app.args.add_argument.called

        # coverage for case where the interface doesn't exist
        app._meta.handler_override_options = {
            'bogus': (['--bogus'], {'help': 'bogus handler'}),
        }
        add_handler_override_options(app)
        log_stub.assert_any_call("interface 'bogus' is not defined, " +
                                 "can not override handlers")


# def test_add_handler_override_options_cannot_override():
#     """Coverage for case where there is an output handler, but it's not
#     overridable (so no options to display in --help)"""
#     class MyApp(TestApp):
#         class Meta:
#             extension = ['mustache']

#     with MyApp() as app:
#         app.run()


def test_handler_override():
    class MyApp(TestApp):
        class Meta:
            argv = ['-o', 'json']
            extensions = ['json', 'yaml', 'mustache', 'tabulate']

    with MyApp() as app:
        app.run()

    # coverage
    app._meta.handler_override_options = None
    handler_override(app)


def test_cement_signal_handler():
    # coverage
    with pytest.raises(CaughtSignal):
        mframe = Mock()
        mframe.f_globals.values = MagicMock(return_value=[TestApp()])
        cement_signal_handler(1, mframe)
        mframe.f_globals.values.assert_called()

{'fraction_non_alphanumeric': 0.09221902017291066, 'fraction_numerical': 0.0008867213478164486, 'mean_word_length': 3.2247191011235956, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6486358', 'n_tokens_mistral': 1312, 'n_tokens_neox': 1283, 'n_words': 364}