Ejemplo n.º 1
0
def main():
    """
    Do initial checks, clear the console and print the assistant logo.

    STEP 1: Clear log file in each assistant fresh start
    STEP 2: Checks for internet connectivity
    STEP 3: Configuare MongoDB, load skills and settings
    STEP 4: Clear console
    """

    # STEP 1
    with open(ROOT_LOG_CONF['handlers']['file']['filename'], 'r+') as f:
        f.truncate(0)

    logging.info('Startup checks..')

    # STEP 2
    if not internet_connectivity_check():
        logging.warning('Skills with internet connection will not work :-(')
        time.sleep(3)

    # STEP 3
    configure_MongoDB(db, settings)

    # STEP 4
    console_manager = ConsoleManager()
    logging.info('Application started')
    console_manager.console_output()

    processor = Processor(settings, db)

    while True:
        processor.run()
Ejemplo n.º 2
0
def main():

    processor = Processor(settings)
    start_up()

    while True:
        processor.run()
Ejemplo n.º 3
0
class E2ETests(unittest.TestCase):

    @patch('jarvis.core.processor.Processor._execute_skill', side_effect=print_argument)
    @patch('jarvis.core.processor.engines.TTTEngine')
    def test_run(self, mocked_ttt_engine, mocked_execute_skill):
        input_transcripts = ['hi', 'time', 'date', 'about']
        self.processor = Processor(test_settings)
        for transcipt in input_transcripts:
            mocked_ttt_engine.return_value.recognize_input.return_value = transcipt
            self.processor.run()
Ejemplo n.º 4
0
def main():
    """
    Do initial checks, clear the console and print the assistant logo.
    """

    console_manager = ConsoleManager()
    console_manager.console_output(
        info_log='Wait a second for startup checks..')
    internet_connectivity_check()
    console_manager.console_output(info_log='Application started')
    console_manager.console_output(info_log="I'm ready! Say something :-)")
    processor = Processor(console_manager=console_manager, settings_=settings)

    while True:
        processor.run()
    def test_all_skill_matches(self, mocked_ttt_engine, mocked_execute_skill):
        """
        In this test we examine the matches or  ALL skill tags with the functions
        If all skills matched right then the test passes otherwise not.

        At the end we print a report with all the not matched cases.

        """

        verifications_errors = []

        self.processor = Processor(settings, db)
        mocked_ttt_engine.return_value.recognize_input.return_value = 'hi'
        self.processor.run()

        for basic_skill in BASIC_SKILLS:
            print(
                '--------------------------------------------------------------------------------------'
            )
            print('Examine skill: {0}'.format(basic_skill.get('name')))
            for tag in basic_skill.get('tags', ).split(','):
                # If the skill has matching tags
                if tag:
                    mocked_ttt_engine.return_value.recognize_input.return_value = tag
                    self.processor.run()
                    expected_skill = basic_skill.get('name')
                    actual_skill = get_skill_name_from_call_args(
                        mocked_execute_skill.call_args)
                    try:
                        self.assertEqual(expected_skill, actual_skill)
                    except AssertionError as e:
                        verifications_errors.append({'tag': tag, 'error': e})

        print(
            '-------------------------------------- SKILLS MATCHING REPORT --------------------------------------'
        )
        if verifications_errors:
            for increment, e in enumerate(verifications_errors):
                print('{0})'.format(increment))
                print('Not correct match with tag: {0}'.format(e.get('tag')))
                print('Assertion values (expected != actual): {0}'.format(
                    e.get('error')))
            raise AssertionError
        else:
            print('All skills matched correctly!')
Ejemplo n.º 6
0
 def test_run(self, mocked_ttt_engine, mocked_execute_skill):
     input_transcripts = ['hi', 'time', 'date', 'about']
     self.processor = Processor(test_settings)
     for transcipt in input_transcripts:
         mocked_ttt_engine.return_value.recognize_input.return_value = transcipt
         self.processor.run()
Ejemplo n.º 7
0
def main():
    processor = Processor()
    processor.run()
Ejemplo n.º 8
0
def main():
    processor = Processor()

    while True:
        processor.run()
class TestSkillMatching(unittest.TestCase):
    def setUp(self):

        all_skills = {
            MongoCollections.CONTROL_SKILLS.value: CONTROL_SKILLS,
            MongoCollections.ENABLED_BASIC_SKILLS.value: ENABLED_BASIC_SKILLS,
        }
        for collection, documents in all_skills.items():
            db.update_collection(collection, documents)

        default_assistant_name = settings.DEFAULT_GENERAL_SETTINGS[
            'assistant_name']
        default_enabled_period = settings.DEFAULT_GENERAL_SETTINGS[
            'enabled_period']
        default_input_mode = settings.DEFAULT_GENERAL_SETTINGS['input_mode']
        default_response_in_speech = settings.DEFAULT_GENERAL_SETTINGS[
            'response_in_speech']

        default_settings = {
            'assistant_name': default_assistant_name,
            'enabled_period': default_enabled_period,
            'input_mode': default_input_mode,
            'response_in_speech': default_response_in_speech,
        }

        db.update_collection(
            collection=MongoCollections.GENERAL_SETTINGS.value,
            documents=[default_settings])

        # Add assistant name in  skill 'enable_assistant' + 'assistant_check' tags
        assistant_name = db.get_documents(
            collection=MongoCollections.GENERAL_SETTINGS.value
        )[0]['assistant_name']

        # Update enable_assistant skill
        existing_enable_assistant_tags = db.get_documents(
            collection=MongoCollections.CONTROL_SKILLS.value,
            key={'name': 'enable_assistant'})[0]['tags']
        new_enable_assistant_tags = {
            'tags': existing_enable_assistant_tags + ' ' + assistant_name
        }
        db.update_document(collection=MongoCollections.CONTROL_SKILLS.value,
                           query={'name': 'enable_assistant'},
                           new_value=new_enable_assistant_tags)

        # Update assistant_check
        existing_assistant_check_tags = db.get_documents(
            collection=MongoCollections.ENABLED_BASIC_SKILLS.value,
            key={'name': 'assistant_check'})[0]['tags']
        new_assistant_check_tags = {
            'tags': existing_assistant_check_tags + ' ' + assistant_name
        }
        db.update_document(
            collection=MongoCollections.ENABLED_BASIC_SKILLS.value,
            query={'name': 'assistant_check'},
            new_value=new_assistant_check_tags)

    def test_all_skill_matches(self, mocked_ttt_engine, mocked_execute_skill):
        """
        In this test we examine the matches or  ALL skill tags with the functions
        If all skills matched right then the test passes otherwise not.

        At the end we print a report with all the not matched cases.

        """

        verifications_errors = []

        self.processor = Processor(settings, db)
        mocked_ttt_engine.return_value.recognize_input.return_value = 'hi'
        self.processor.run()

        for basic_skill in BASIC_SKILLS:
            print(
                '--------------------------------------------------------------------------------------'
            )
            print('Examine skill: {0}'.format(basic_skill.get('name')))
            for tag in basic_skill.get('tags', ).split(','):
                # If the skill has matching tags
                if tag:
                    mocked_ttt_engine.return_value.recognize_input.return_value = tag
                    self.processor.run()
                    expected_skill = basic_skill.get('name')
                    actual_skill = get_skill_name_from_call_args(
                        mocked_execute_skill.call_args)
                    try:
                        self.assertEqual(expected_skill, actual_skill)
                    except AssertionError as e:
                        verifications_errors.append({'tag': tag, 'error': e})

        print(
            '-------------------------------------- SKILLS MATCHING REPORT --------------------------------------'
        )
        if verifications_errors:
            for increment, e in enumerate(verifications_errors):
                print('{0})'.format(increment))
                print('Not correct match with tag: {0}'.format(e.get('tag')))
                print('Assertion values (expected != actual): {0}'.format(
                    e.get('error')))
            raise AssertionError
        else:
            print('All skills matched correctly!')