Beispiel #1
0
    def test_it_should_load_additional_skills_too(self):
        # Will import both skills
        agt1 = create_skill_agent(get_skill_folder('alpha'))
        agt2 = create_skill_agent(get_skill_folder('bravo'))

        agt = create_skill_agent(get_skill_folder('alpha'),
                                 additional_skills=['bravo'])

        expect(agt._handlers).to.have.length_of(2)
        expect(agt._handlers).to.contain('alpha')
        expect(agt._handlers).to.contain('bravo')

        expect(agt._interpreter.intents).to.have.length_of(2)
        expect(agt._interpreter.intents).to.contain('alpha')
        expect(agt._interpreter.intents).to.contain('bravo')
Beispiel #2
0
    def test_it_should_instantiate_an_agent_for_the_targeted_skill_only(self):
        agt = create_skill_agent(get_skill_folder('alpha'))

        expect(agt).to.be.an(Agent)
        expect(agt._handlers).to.have.length_of(1)
        expect(agt._handlers).to.contain('alpha')
        expect(agt._interpreter.intents).to.have.length_of(1)
        expect(agt._interpreter.intents).to.contain('alpha')

        agt = create_skill_agent(get_skill_folder('bravo'))

        expect(agt._handlers).to.have.length_of(1)
        expect(agt._handlers).to.contain('bravo')
        expect(agt._interpreter.intents).to.have.length_of(1)
        expect(agt._interpreter.intents).to.contain('bravo')
 def test_get_time(self):
     agent = create_skill_agent(os.path.dirname(__file__), lang='en')
     agent.parse('what time is it')
     current_time = datetime.now().time()
     current_formated_time = format_time(current_time, locale='en')
     call = agent.model.on_answer.get_call()
     expect(call.text).to.equal('It\'s {}'.format(current_formated_time))
Beispiel #4
0
 def test_it_should_failed_to_find_stories_folder(self):
   test_game_saves_folder_path = os.path.join(os.path.dirname(__file__),'test')
   agent = create_skill_agent(os.path.dirname(__file__), lang='en')
   agent.settings.reset()
   agent.settings.set('game_saves_folder',test_game_saves_folder_path,section='interactive_fiction')
   agent.parse("play interactive fiction named Test.zblorb")
   call = agent.model.on_ask.get_call()
   expect(call.text).to.equal('Stories folder has not been set. Stories will be load from the current folder "{0}".\nDo you want continue?'.format(os.getcwd()))
Beispiel #5
0
 def test_it_should_launch_the_storie(self):
   test_game_saves_folder_path = os.path.join(os.path.dirname(__file__),'test')
   test_stories_folder_path = os.path.join(os.path.dirname(__file__),'test/test.materials/Release')
   agent = create_skill_agent(os.path.dirname(__file__), lang='en')
   agent.settings.reset()
   agent.settings.set('game_saves_folder',test_game_saves_folder_path,section='interactive_fiction')
   agent.settings.set('stories_folder',test_stories_folder_path,section='interactive_fiction')
   agent.parse("play interactive fiction named Test.zblorb")
   call = agent.model.on_answer.get_call()
   expect(call.text).to.equal(test_response.strip())
Beispiel #6
0
 def test_it_should_failed_to_find_story(self):
   test_game_saves_folder_path = os.path.join(os.path.dirname(__file__),'test')
   test_stories_folder_path = os.path.join(os.path.dirname(__file__),'test/test.materials/Release')
   agent = create_skill_agent(os.path.dirname(__file__), lang='en')
   agent.settings.reset()
   agent.settings.set('game_saves_folder',test_game_saves_folder_path,section='interactive_fiction')
   agent.settings.set('stories_folder',test_stories_folder_path,section='interactive_fiction')
   agent.parse("play interactive fiction named invalid.zblorb")
   call = agent.model.on_answer.get_call()
   expect(call.text).to.equal('Sorry, no story named {0} has been found in {1}.'.format('invalid.zblorb', test_stories_folder_path))
Beispiel #7
0
    def test_it_should_contain_an_agent_model_mock(self):
        agt = create_skill_agent(get_skill_folder('alpha'))

        agt.parse('trigger alpha')

        expect(agt.model).to.be.an(AgentModelMock)

        call = agt.model.on_answer.get_call()

        expect(call.text).to.equal('Hello from alpha!')
Beispiel #8
0
 def test_it_should_display_hello_world(self):
   test_game_saves_folder_path = os.path.join(os.path.dirname(__file__),'test')
   test_stories_folder_path = os.path.join(os.path.dirname(__file__),'test/test.materials/Release')
   agent = create_skill_agent(os.path.dirname(__file__), lang='en')
   agent.settings.reset()
   agent.settings.set('game_saves_folder',test_game_saves_folder_path,section='interactive_fiction')
   agent.settings.set('stories_folder',test_stories_folder_path,section='interactive_fiction')
   agent.parse("play interactive fiction named Test.zblorb")
   agent.parse('read the Poster')
   call = agent.model.on_answer.get_call()
   expect(call.text).to.equal("read the Poster\nHello world!")
Beispiel #9
0
 def test_it_should_failed_to_find_zvm(self):
   test_zvm_path = os.path.join(os.path.dirname(__file__),'invalid_zvm')
   test_game_saves_folder_path = os.path.join(os.path.dirname(__file__),'test')
   test_stories_folder_path = os.path.join(os.path.dirname(__file__),'test/test.materials/Release')
   agent = create_skill_agent(os.path.dirname(__file__), lang='en')
   agent.settings.reset()
   agent.settings.set('zvm_path',test_zvm_path,section='interactive_fiction')
   agent.settings.set('game_saves_folder',test_game_saves_folder_path,section='interactive_fiction')
   agent.settings.set('stories_folder',test_stories_folder_path,section='interactive_fiction')
   agent.parse("play interactive fiction named Test.zblorb")
   call = agent.model.on_answer.get_call()
   expect(call.text).to.equal('Unable to start {0}'.format(test_zvm_path))
Beispiel #10
0
 def test_it_should_failed_to_restore_saved_game(self):
   test_game_saves_folder_path = os.path.join(os.path.dirname(__file__),'test')
   test_stories_folder_path = os.path.join(os.path.dirname(__file__),'test/test.materials/Release')
   game_save_name = 'invalid_test_save'
   game_save_filename = '{0}.{1}'.format(game_save_name, 'glksave')
   game_save_path = os.path.join(test_game_saves_folder_path, game_save_filename) 
   if os.path.isfile(game_save_path):
     os.remove(game_save_path)      
   agent = create_skill_agent(os.path.dirname(__file__), lang='en')
   agent.settings.reset()
   agent.settings.set('game_saves_folder',test_game_saves_folder_path,section='interactive_fiction')
   agent.settings.set('stories_folder',test_stories_folder_path,section='interactive_fiction')
   agent.parse("play interactive fiction named Test.zblorb")
   agent.parse("restore the game {0}".format(game_save_name))
   call = agent.model.on_answer.get_call()
   expect(call.text).to.equal("restore\n\nPlease enter a file name (without an extension): Restore failed.")
Beispiel #11
0
    def test_it_should_returns_loaded_skills_correctly(self):
        skills = [
            Meta(name='alpha',
                 description='An alpha skill',
                 author='Julien LEICHER'),
            Meta(name='bravo', description='A bravo skill', author='John Doe'),
        ]

        with patch('pytlas.supporting.SkillsManager.get', return_value=skills):
            agent = create_skill_agent(os.path.dirname(__file__), lang='en')
            agent.parse('how can you help')

            call = agent.model.on_answer.get_call()

            expect(call.text).to.equal('Here what I know so far')
            expect(call.cards).to.have.length_of(2)

            expect(call.cards[0].header).to.equal('alpha')
            expect(call.cards[0].text).to.equal('An alpha skill')
            expect(call.cards[0].subhead).to.equal('Julien LEICHER')

            expect(call.cards[1].header).to.equal('bravo')
            expect(call.cards[1].text).to.equal('A bravo skill')
            expect(call.cards[1].subhead).to.equal('John Doe')
Beispiel #12
0
 def test_it_should_ask_for_game_saves_folder(self):
   agent = create_skill_agent(os.path.dirname(__file__), lang='en')
   agent.settings.reset()
   agent.parse("play interactive fiction named Test.zblorb")
   call = agent.model.on_ask.get_call()
   expect(call.text).to.equal('Game saves folder has not been set. Your game saves will be writen in the current folder "{0}".\nDo you want continue?'.format(os.getcwd()))
Beispiel #13
0
 def setup(self):
     self.agent = create_skill_agent(os.path.dirname(__file__))
     self.agent.model.reset()
Beispiel #14
0
from sure import expect
from pytlas.testing import create_skill_agent
import os

agent = create_skill_agent(os.path.dirname(__file__))

class TestLights:

  def setup(self):
    agent.model.reset()

  def test_it_should_turn_lights_on(self):
    agent.parse('Turn the lights on in kitchen please')

    call = agent.model.on_answer.get_call(0)

    expect(call.text).to.equal('Turning lights on in kitchen')

  def test_it_should_turn_lights_on_and_ask_for_rooms(self):
    agent.parse('Turn the lights on')

    call = agent.model.on_ask.get_call()

    expect(call.slot).to.equal('room')
    expect(call.text).to.be.within(['For which rooms?', 'Which rooms Sir?', 'Please specify some rooms'])
    expect(call.choices).to.be.none

    agent.parse('In the kitchen please')

    call = agent.model.on_answer.get_call()
 def test_blackjack_launch(self):
   agent = create_skill_agent(os.path.dirname(__file__), lang='en')
   agent.parse('play blackjack')
   call = agent.model.on_answer.get_call()
   expect(call.text).to.equal('Bet to play')
Beispiel #16
0
import os
from sure import expect
from pytlas.testing import create_skill_agent

# Testing a pytlas skill is easy.
# Start by instantiating an agent trained only for this skill.

agent = create_skill_agent(os.path.dirname(__file__), lang='en')


class TestHooverSkill:
    def setup(self):
        # Between each tests, resets the model mock so calls are dismissed and we
        # start on a fresh state.
        # This will be usefull when you have more than one test method :)
        agent.model.reset()

    def test_it_should_start_vacuuming(self):
        # Now, try to trigger our skill
        agent.parse('start vacuum cleaner')

        # And make assertions about how the model (the part between pytlas and the end user)
        # as answered: https://pytlas.readthedocs.io/en/latest/writing_skills/testing.html#writing-tests
        call = agent.model.on_answer.get_call()
        expect(call.text).to.equal('Vacuuming started')
        expect(call.skill).to.equal('vacuum')
        expect(call.action).to.equal('start')

    def test_it_should_stop_vacuuming(self):
        # Now, try to trigger our skill
        agent.parse('stop vacuum cleaner')
Beispiel #17
0
def setup_module(module):
  global agent
  remove_test_tmp_folder()
  test_tmp_folder_path = get_test_tmp_folder_path()
  CONFIG.set('path',test_tmp_folder_path,section='pytlas_list')
  agent = create_skill_agent(os.path.dirname(__file__), lang='en')