Beispiel #1
0
def test_dialog_uses():
    class HighCostToCreate:
        pass

    class OnlyForFooDS:
        pass

    class FooFialog(DialogService):
        pass

    # run once when create bot
    hctc = HighCostToCreate()
    offds = OnlyForFooDS()

    # create bot
    bot = Minette()

    # set dependencies to dialogs
    bot.dialog_uses(
        {
            FooFialog: {"api": offds}
        },
        highcost=hctc
    )

    assert bot.dialog_router.dependencies.highcost == hctc
    assert hasattr(bot.dialog_router.dependencies, "api") is False
    assert bot.dialog_router.dependency_rules[FooFialog]["api"] == offds

    # create bot and not set dialog dependencies
    bot_no_dd = Minette()
    assert bot_no_dd.dialog_router.dependencies is None
    bot_no_dd.dialog_uses()
    assert isinstance(bot_no_dd.dialog_router.dependencies, DependencyContainer)
Beispiel #2
0
def test_chat_parse_morph_manually():
    bot = Minette(
        default_dialog_service=TaggerManuallyParseDialog,
        tagger=JanomeTagger, tagger_max_length=0)
    bot.dialog_uses(tagger=bot.tagger)
    res = bot.chat("今日はいい天気です。")
    assert res.messages[0].text == "今日はいい天気です。"
    words = res.messages[0].payloads[0].content
    assert words[0].surface == "今日"
    assert words[1].surface == "は"
    assert words[2].surface == "いい"
    assert words[3].surface == "天気"
    assert words[4].surface == "です"
Beispiel #3
0
def test_chat_parse_morph_manually_generator():
    bot = Minette(
        default_dialog_service=TaggerManuallyParseGeneratorDialog,
        tagger=JanomeTagger, tagger_max_length=0)
    bot.dialog_uses(tagger=bot.tagger)
    res = bot.chat("今日はいい天気です。")
    assert res.messages[0].text == "今日はいい天気です。"
    assert isinstance(res.messages[0].payloads[0].content, GeneratorType)
    words = [w for w in res.messages[0].payloads[0].content]
    assert words[0].surface == "今日"
    assert words[1].surface == "は"
    assert words[2].surface == "いい"
    assert words[3].surface == "天気"
    assert words[4].surface == "です"