Esempio n. 1
0
def test_form():
    dm = CheckableFormFiller('tests/test_managers/form.yaml',
                             default_message=DEFAULT_MESSAGE)
    resp = dm.respond(make_context(new_session=True))
    assert resp.text == DEFAULT_MESSAGE

    for q, a in [
        ('start the test', 'Please tell me your name'),
        ('Bob',
         'Now tell me the year of your birth. Four digits, nothing more.'),
        ('not', 'Please try again. Your answer should be 4 digits.'),
        ('0', 'Please try again. Your answer should be 4 digits.'),
        ('1999',
         'Wonderful! Now choose the month of your birth (the first 3 letters).'
         ),
        ('lol',
         'The answer should be one of the suggested options - the first 3 letters of a month.'
         ),
        ('jan',
         'That\'s great! Finally, tell me the date of your birth - one or two digits'
         ),
        ('40',
         'Please try again. Your answer should be a whole number - the day of your birth.'
         ),
        ('02',
         'Thank you, Bob! Now we know: you are 20 years old and you are probably The Goat. Lucky you!'
         ), ('Okay, what\'s next?', DEFAULT_MESSAGE),
        ('But really', DEFAULT_MESSAGE)
    ]:
        resp = dm.respond(make_context(text=q, prev_response=resp))
        assert resp.text == a, 'expected "{}" to be responded by "{}", got "{}" instead'.format(
            q, a, resp.text)
Esempio n. 2
0
def test_default_transition(example_fsa):
    fsa: AutomatonDialogManager = example_fsa

    ctx0 = make_context(text='hi', new_session=True)
    resp0 = fsa.try_to_respond(ctx0)

    ctx1 = make_context('let\'s introduce ourselves', prev_response=resp0)
    resp1 = fsa.try_to_respond(ctx1)

    ctx2 = make_context('Stasy', prev_response=resp1)
    resp2 = fsa.try_to_respond(ctx2)
    assert resp2.text == 'Nice to meet you'
Esempio n. 3
0
def test_search(mock_dm: SearcherDialogManager):
    # expect serp
    resp = mock_dm.respond(make_context('найди навык про воду'))
    assert 'Время выпить воды' in resp.text
    assert '1' in resp.suggests

    # expect skill card
    ctx1 = make_context('расскажи подробнее про первый навык',
                        prev_response=resp)
    resp1 = mock_dm.respond(ctx1)
    assert 'Время выпить воды' in resp1.text
    assert 'вести учет выпитой воды' in resp1.text
    assert 'к списку' in resp1.suggests
    assert len(resp1.links) == 1
Esempio n. 4
0
def test_minimal_fsa():
    cfg = {'states': {'first': {'a': 'hello'}}}
    fsa = AutomatonDialogManager(config=cfg, matcher='exact')
    assert len(fsa.states
               ) == 2  # 'universal' state is always added but it never reached

    ctx = make_context(text='hi', new_session=True)
    resp = fsa.try_to_respond(ctx)
    assert resp.text == 'hello'
Esempio n. 5
0
def test_basic():
    dm = WatchDM()
    ctx = make_context('старт')
    resp = dm.respond(ctx)
    assert 'пошёл' in resp.text

    resp = dm.respond(make_context('время', prev_response=resp))
    assert '0 секунд' in resp.text

    time.sleep(2)
    resp = dm.respond(make_context('время', prev_response=resp))
    assert '2 секунды' in resp.text

    resp = dm.respond(make_context('стоп', prev_response=resp))
    assert '2 секунды' in resp.text
    assert 'остановила' in resp.text.lower()

    resp = dm.respond(make_context('время', prev_response=resp))
    assert 'не поставлен' in resp.text
Esempio n. 6
0
def test_faq():
    dm = tgalice.dialog_manager.FAQDialogManager(
        'tests/test_managers/faq.yaml',
        matcher='cosine',
        default_message=DEFAULT_MESSAGE)
    r1 = dm.respond(make_context(new_session=True))
    assert r1.text == DEFAULT_MESSAGE
    first_responses = {
        dm.respond(make_context(text='hi there', prev_response=r1)).text
        for i in range(30)
    }
    assert first_responses == {
        'Hello!', 'Nice to meet you!', 'Have a good time, human.'
    }

    r2 = dm.respond(make_context(text='hi there', prev_response=r1))
    assert set(r2.suggests) == {'How are you?', 'What can you do?'}

    r3 = dm.respond(make_context(text='how are you', prev_response=r2))
    assert r3.text == "I'm fine, thanks"

    r4 = dm.respond(make_context(text='What can you do?', prev_response=r3))
    assert r4.text == DEFAULT_MESSAGE
Esempio n. 7
0
def test_basic_transition(example_fsa):
    fsa: AutomatonDialogManager = example_fsa

    # initialize
    ctx0 = make_context(text='hi', new_session=True)
    resp0 = fsa.try_to_respond(ctx0)
    assert resp0.text == 'hello'

    # successful transition
    ctx1 = make_context(text='can you tell me the time please',
                        prev_response=resp0)
    resp1 = fsa.try_to_respond(ctx1)
    assert resp1.text == '8 pm'

    # the same transition from another state is not allowed
    ctx2 = make_context(text='can you tell me the time please',
                        prev_response=resp1)
    resp2 = fsa.try_to_respond(ctx2)
    assert not resp2

    # failed transition: text was not matched
    ctx1 = make_context(text='you will not understand me', prev_response=resp0)
    resp1 = fsa.try_to_respond(ctx1)
    assert not resp1

    # transition from the universal state
    ctx1 = make_context(text='help', prev_response=resp0)
    resp1 = fsa.try_to_respond(ctx1)
    assert resp1.text == 'I am always here to help'

    # new session
    ctx2 = make_context(new_session=True, prev_response=resp1)
    resp2 = fsa.try_to_respond(ctx2)
    assert resp2.text == 'hello again'

    # after transient state, context is restored and previous transition is possible
    ctx3 = make_context(prev_response=resp2, text='thanks')
    resp3 = fsa.try_to_respond(ctx3)
    assert resp3.text == 'thank you'
    ctx4 = make_context(prev_response=resp3, text='tell me time now')
    resp4 = fsa.try_to_respond(ctx4)
    assert resp4.text == '8 pm'
Esempio n. 8
0
def test_hello_world(mock_dm: RzdDialogManager):
    ctx = make_context(new_session=True)
    resp = mock_dm.respond(ctx)
    assert 'РЖД' in resp.text
Esempio n. 9
0
def test_hello_world():
    dm = RzdDialogManager()
    ctx = make_context(new_session=True)
    resp = dm.respond(ctx)
    assert 'РЖД' in resp.text
Esempio n. 10
0
def test_single_pass(mock_dm: SearcherDialogManager):
    # expect serp
    resp = mock_dm.respond(
        make_context('найди навык про воду', new_session=True))
    assert 'Время выпить воды' in resp.text
    assert '1' in resp.suggests
Esempio n. 11
0
def test_greetings(mock_dm: SearcherDialogManager):
    resp = mock_dm.respond(make_context('', new_session=True))
    assert resp.text.startswith(
        'Привет! Это навык "Искатель навыков" для поиска других навыков.')
Esempio n. 12
0
def test_hello():
    dm = StretchDM()
    resp = dm.respond(make_context(text='Привет', new_session=True))
    assert '30' in resp.text