<commit_before>from unittest.mock import patch

import pytest

from rcfc import server, button


def do_nothing():
    pass


def do_nothing_arg(token_argument):
    pass


@patch("bottle.Bottle.route")
def test_simple_button_registration(mock_route):
    server.clear_buttons()
    button.simple("this is a button")(do_nothing)
    expected = {"text": "this is a button",
                "type": "button.simple",
                "getter": server.getter_placeholder,
                "id": 0}
    assert server.get_buttons_registered() == {"buttons": [expected]}

    mock_route.assert_called_once_with("/buttons/0",
                                       ["POST", "OPTIONS"],
                                       do_nothing)


@patch("bottle.Bottle.route")
def test_simple_button_registration_fails_when_arguments(mock_route):
    server.clear_buttons()
    with pytest.raises(server.InvalidArgumentsException):
        button.simple("this is a button")(do_nothing_arg)
    assert server.get_buttons_registered() == {'buttons': []}
    mock_route.assert_not_called()


@patch("bottle.Bottle.route")
def test_slider_button_registration(mock_route):
    server.clear_buttons()
    button.toggle("Toggle Button", do_nothing)(do_nothing_arg)
    expected = {"text": "Toggle Button",
                "type": "button.toggle",
                "getter": do_nothing,
                "id": 0}
    assert server.get_buttons_registered() == {"buttons": [expected]}

    mock_route.assert_called_once_with("/buttons/0",
                                       ["POST", "OPTIONS"],
                                       do_nothing_arg)<commit_msg>Adding test for toggle invalid arguments<commit_after>from unittest.mock import patch

import pytest

from rcfc import server, button


def do_nothing():
    pass


def do_nothing_arg(token_argument):
    pass


@patch("bottle.Bottle.route")
def test_simple_button_registration(mock_route):
    server.clear_buttons()
    button.simple("this is a button")(do_nothing)
    expected = {"text": "this is a button",
                "type": "button.simple",
                "getter": server.getter_placeholder,
                "id": 0}
    assert server.get_buttons_registered() == {"buttons": [expected]}

    mock_route.assert_called_once_with("/buttons/0",
                                       ["POST", "OPTIONS"],
                                       do_nothing)


@patch("bottle.Bottle.route")
def test_simple_button_registration_fails_when_arguments(mock_route):
    server.clear_buttons()
    with pytest.raises(server.InvalidArgumentsException):
        button.simple("this is a button")(do_nothing_arg)
    assert server.get_buttons_registered() == {'buttons': []}
    mock_route.assert_not_called()


@patch("bottle.Bottle.route")
def test_toggle_button_registration(mock_route):
    server.clear_buttons()
    button.toggle("Toggle Button", do_nothing)(do_nothing_arg)
    expected = {"text": "Toggle Button",
                "type": "button.toggle",
                "getter": do_nothing,
                "id": 0}
    assert server.get_buttons_registered() == {"buttons": [expected]}

    mock_route.assert_called_once_with("/buttons/0",
                                       ["POST", "OPTIONS"],
                                       do_nothing_arg)


@patch("bottle.Bottle.route")
def test_toggle_button_registration_with_invalid_args(mock_route):
    server.clear_buttons()
    with pytest.raises(server.InvalidArgumentsException):
        button.toggle("Toggle Button", do_nothing)(do_nothing)
    assert server.get_buttons_registered() == {'buttons': []}
    mock_route.assert_not_called()
{'fraction_non_alphanumeric': 0.11837407305685252, 'fraction_numerical': 0.0021971985718209283, 'mean_word_length': 2.774093264248705, 'pattern_counts': {'":': 20, '<': 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': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1031004', 'n_tokens_mistral': 1102, 'n_tokens_neox': 1033, 'n_words': 185}