<commit_before>from rasa.core import run

CREDENTIALS_FILE = "examples/moodbot/credentials.yml"


def test_create_http_input_channels():
    channels = run.create_http_input_channels(None, CREDENTIALS_FILE)
    assert len(channels) == 7

    # ensure correct order
    assert {c.name() for c in channels} == {
        "twilio",
        "slack",
        "telegram",
        "mattermost",
        "facebook",
        "webexteams",
        "rocketchat",
    }


def test_create_single_input_channels():
    channels = run.create_http_input_channels("facebook", CREDENTIALS_FILE)
    assert len(channels) == 1
    assert channels[0].name() == "facebook"


def test_create_single_input_channels_by_class():
    channels = run.create_http_input_channels(
        "rasa.core.channels.channel.RestInput", CREDENTIALS_FILE
    )
    assert len(channels) == 1
    assert channels[0].name() == "rest"


def test_create_single_input_channels_by_class_wo_credentials():
    channels = run.create_http_input_channels(
        "rasa.core.channels.channel.RestInput", credentials_file=None
    )

    assert len(channels) == 1
    assert channels[0].name() == "rest"
<commit_msg>add unit tests for load_agent_on_start<commit_after>import pytest
from rasa.core import run, interpreter, policies, domain
from rasa.core.utils import AvailableEndpoints

CREDENTIALS_FILE = "examples/moodbot/credentials.yml"


def test_create_http_input_channels():
    channels = run.create_http_input_channels(None, CREDENTIALS_FILE)
    assert len(channels) == 7

    # ensure correct order
    assert {c.name() for c in channels} == {
        "twilio",
        "slack",
        "telegram",
        "mattermost",
        "facebook",
        "webexteams",
        "rocketchat",
    }


def test_create_single_input_channels():
    channels = run.create_http_input_channels("facebook", CREDENTIALS_FILE)
    assert len(channels) == 1
    assert channels[0].name() == "facebook"


def test_create_single_input_channels_by_class():
    channels = run.create_http_input_channels(
        "rasa.core.channels.channel.RestInput", CREDENTIALS_FILE
    )
    assert len(channels) == 1
    assert channels[0].name() == "rest"


def test_create_single_input_channels_by_class_wo_credentials():
    channels = run.create_http_input_channels(
        "rasa.core.channels.channel.RestInput", credentials_file=None
    )

    assert len(channels) == 1
    assert channels[0].name() == "rest"


async def test_load_agent_on_start_with_good_model_file(
    trained_rasa_model, rasa_server, loop,
):
    agent = await run.load_agent_on_start(
        trained_rasa_model, AvailableEndpoints(), None, rasa_server, loop,
    )

    assert isinstance(agent.interpreter, interpreter.RasaNLUInterpreter)
    assert isinstance(agent.policy_ensemble, policies.PolicyEnsemble)
    assert isinstance(agent.domain, domain.Domain)


async def test_load_agent_on_start_with_bad_model_file(
    tmpdir, rasa_server, loop,
):
    from pathlib import Path

    fake_model = Path(tmpdir) / "fake_model.tar.gz"
    fake_model.touch()
    fake_model_path = str(fake_model)

    with pytest.warns(UserWarning) as warnings:
        agent = await run.load_agent_on_start(
            fake_model_path, AvailableEndpoints(), None, rasa_server, loop,
        )
        assert any(
            "fake_model.tar.gz' could not be loaded" in str(w.message) for w in warnings
        )
    
    # Fallback agent was loaded even if model was unusable
    assert isinstance(agent.interpreter, interpreter.RegexInterpreter)
    assert agent.policy_ensemble is None
    assert isinstance(agent.domain, domain.Domain)

{'fraction_non_alphanumeric': 0.09807162534435261, 'fraction_numerical': 0.003856749311294766, 'mean_word_length': 3.7094682230869003, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4771595', 'n_tokens_mistral': 1162, 'n_tokens_neox': 1133, 'n_words': 226}