예제 #1
0
    def test_load_from_text_single_files(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        configuration = yaml.load_from_text("""
            brain:

                files:
                    aiml:
                        files: $BOT_ROOT/test-aiml
                        extension: .test-aiml
                        directories: true
                        errors: /tmp/y-bot_errors.txt
                        duplicates: /tmp/y-bot_duplicates.txt
                        conversation: /tmp/y-bot_conversation.txt
                    sets:
                        files: $BOT_ROOT/test-sets
                        extension: .test-txt
                        directories: true
                    maps:
                        files: $BOT_ROOT/test-maps
                        extension: .test-txt
                        directories: true
            """, ConsoleConfiguration(), ".")

        self.assertIsNotNone(configuration)

        self.assertTrue(configuration.client_configuration.brain_config[0].brain_config[0].files.aiml_files.has_multiple_files())
        self.assertFalse(configuration.client_configuration.brain_config[0].brain_config[0].files.aiml_files.has_single_file())

        self.assertEqual(configuration.client_configuration.brain_config[0].brain_config[0].files.aiml_files.files, ["./test-aiml"])
        self.assertEqual(configuration.client_configuration.brain_config[0].brain_config[0].files.set_files.files, ["./test-sets"])
        self.assertEqual(configuration.client_configuration.brain_config[0].brain_config[0].files.map_files.files, ["./test-maps"])
예제 #2
0
    def test_with_data(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text(
            """
        bot:
            spelling:
              classname: programr.spelling.norvig.NorvigSpellingChecker
              corpus: $BOT_ROOT/corpus.txt
              alphabet: abcdefghijklmnopqrstuvwxyz
              check_before: true
              check_and_retry: true
        """, ConsoleConfiguration(), ".")

        bot_config = yaml.get_section("bot")

        spelling_config = BotSpellingConfiguration()
        spelling_config.load_config_section(yaml, bot_config, ".")

        self.assertEquals("programr.spelling.norvig.NorvigSpellingChecker",
                          spelling_config.classname)
        self.assertEquals("./corpus.txt", spelling_config.corpus)
        self.assertEquals("abcdefghijklmnopqrstuvwxyz",
                          spelling_config.alphabet)
        self.assertTrue(spelling_config.check_before)
        self.assertTrue(spelling_config.check_and_retry)
예제 #3
0
    def test_to_yaml_without_defaults(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text(
            """
        console:
          bot: bot
          default_userid: console
          prompt: $
          license_keys: ./config/license.keys
          bot_selector: programr.clients.client.DefaultBotSelector
          renderer: programr.clients.render.text.TextRenderer
        """, ConsoleConfiguration(), ".")

        config = ConsoleConfiguration()
        config.load_configuration(yaml, ".")

        data = {}
        config.to_yaml(data, False)

        self.assertEquals('console', data['default_userid'])
        self.assertEquals('$', data['prompt'])

        self.assertEquals(data['bot'], 'bot')
        self.assertEquals(data['license_keys'], "./config/license.keys")
        self.assertEquals(data['bot_selector'],
                          "programr.clients.client.DefaultBotSelector")
        self.assertEquals(data['renderer'],
                          "programr.clients.render.text.TextRenderer")
예제 #4
0
    def test_init(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text(
            """
            twitter:
              polling_interval: 59
              rate_limit_sleep: 900
              use_status: true
              use_direct_message: true
              auto_follow: true
              storage: file
              storage_location: ./storage/twitter.data
              welcome_message: Thanks for following me
        """, ConsoleConfiguration(), ".")

        twitter_config = TwitterConfiguration()
        twitter_config.load_configuration(yaml, ".")

        self.assertEqual(59, twitter_config.polling_interval)
        self.assertEqual(900, twitter_config.rate_limit_sleep)
        self.assertTrue(twitter_config.use_status)
        self.assertTrue(twitter_config.use_direct_message)
        self.assertTrue(twitter_config.auto_follow)
        self.assertEquals("file", twitter_config.storage)
        self.assertEquals("./storage/twitter.data",
                          twitter_config.storage_location)
        self.assertEquals("Thanks for following me",
                          twitter_config.welcome_message)
예제 #5
0
    def test_init(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text(
            """
        kik:
          bot_name: testbot
          webhook: https://localhost:5000
          host: 127.0.0.1
          port: 5000
          debug: false
          unknown_command: Sorry, that is not a command I have been taught yet!
          unknown_command_srai: YKIK_UNKNOWN_COMMAND
        """, ConsoleConfiguration(), ".")

        kik_config = KikConfiguration()
        kik_config.load_configuration(yaml, ".")

        self.assertEqual("testbot", kik_config.bot_name)
        self.assertEqual("https://localhost:5000", kik_config.webhook)
        self.assertEqual("127.0.0.1", kik_config.host)
        self.assertEqual(5000, kik_config.port)
        self.assertEqual(False, kik_config.debug)
        self.assertEquals(
            kik_config.unknown_command,
            "Sorry, that is not a command I have been taught yet!")
        self.assertEquals(kik_config.unknown_command_srai,
                          "YKIK_UNKNOWN_COMMAND")
예제 #6
0
    def test_with_data(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text("""
        brain:
            services:
                REST:
                    classname: programr.services.rest.GenericRESTService
                    method: GET
                    host: 0.0.0.0
                Pannous:
                    classname: programr.services.pannous.PannousService
                    url: http://weannie.pannous.com/api
                Pandora:
                    classname: programr.services.pandora.PandoraService
                    url: http://www.pandorabots.com/pandora/talk-xml
                Wikipedia:
                    classname: programr.services.wikipediaservice.WikipediaService
        """, ConsoleConfiguration(), ".")

        brain_config = yaml.get_section("brain")

        services_config = BrainServicesConfiguration()
        services_config.load_config_section(yaml, brain_config, ".")

        self.assertTrue(services_config.exists("REST"))
        self.assertTrue(services_config.exists("Pannous"))
        self.assertTrue(services_config.exists("Pandora"))
        self.assertTrue(services_config.exists("Wikipedia"))
        self.assertFalse(services_config.exists("Other"))
예제 #7
0
    def test_with_data(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text(
            """
        bot:
            conversations:
              max_histories: 666
              initial_topic: topic1
              restore_last_topic: true
              type: file
              config_name: file_storage
        
            file_storage:
              dir: $BOT_ROOT/conversations
        """, ConsoleConfiguration(), ".")

        bot_config = yaml.get_section("bot")

        convo_config = BotConversationsConfiguration()
        convo_config.load_config_section(yaml, bot_config, ".")

        self.assertEquals(convo_config.section_name, "conversations")

        self.assertEquals(666, convo_config.max_histories)
        self.assertEquals("topic1", convo_config.initial_topic)
        self.assertTrue(convo_config.restore_last_topic)

        self.assertEquals(convo_config.type, "file")
        self.assertIsNotNone(convo_config.storage)
예제 #8
0
    def test_load_from_configuration_no_data(self):
        collection = DynamicsCollection()
        self.assertIsNotNone(collection)

        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text(
            """
        brain:
            dynamic:
        """, ConsoleConfiguration(), ".")

        brain_config = yaml.get_section("brain")

        dynamics_config = BrainDynamicsConfiguration()
        dynamics_config.load_config_section(yaml, brain_config, ".")

        collection.load_from_configuration(dynamics_config)

        self.assertIsNotNone(collection.dynamic_sets)
        self.assertTrue(collection.is_dynamic_set("NUMBER"))

        self.assertIsNotNone(collection.dynamic_maps)
        self.assertTrue(collection.is_dynamic_map("PLURAL"))
        self.assertTrue(collection.is_dynamic_map("SINGULAR"))
        self.assertTrue(collection.is_dynamic_map("PREDECESSOR"))
        self.assertTrue(collection.is_dynamic_map("SUCCESSOR"))

        self.assertIsNotNone(collection.dynamic_vars)
예제 #9
0
    def test_with_data(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text("""
        console:
          scheduler:
            name: Scheduler1
            debug_level: 0
            add_listeners: True
            remove_all_jobs: True
            
            jobstore:
                name:   mongo
                
                mongo:
                    collection: example_jobs
    
                redis:
                    jobs_key: example.jobs
                    run_times_key: example.run_times
    
                sqlalchemy:
                    url: sqlite:///jobs.sqlite
    
            threadpool:
                max_workers: 20
        
            processpool:
                max_workers: 5   
        
            job_defaults:
                coalesce: False
                max_instances: 3
          
        """, ConsoleConfiguration(), ".")

        bot_config = yaml.get_section("console")

        scheduler_config = SchedulerConfiguration()
        scheduler_config.load_config_section(yaml, bot_config, ".")

        self.assertEquals("Scheduler1", scheduler_config.name)
        self.assertEquals(0, scheduler_config.debug_level)
        self.assertTrue(scheduler_config.add_listeners)
        self.assertTrue(scheduler_config.remove_all_jobs)

        self.assertIsNotNone(scheduler_config.jobstore)
        self.assertIsNotNone(scheduler_config.jobstore.jobstore)
        self.assertEquals("example_jobs", scheduler_config.jobstore.jobstore.collection)

        self.assertIsNotNone(scheduler_config.threadpool)
        self.assertEquals(20, scheduler_config.threadpool.max_workers)

        self.assertIsNotNone(scheduler_config.processpool)
        self.assertEquals(5, scheduler_config.processpool.max_workers)

        self.assertIsNotNone(scheduler_config.job_defaults)
        self.assertEquals(False, scheduler_config.job_defaults.coalesce)
        self.assertEquals(3, scheduler_config.job_defaults.max_instances)
예제 #10
0
    def test_with_data(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text("""
        bot:
            prompt: ">>>"
            initial_question: Hi, how can I help you today?
            initial_question_srai: YINITIALQUESTION
            default_response: Sorry, I don't have an answer for that!
            default_response_srai: YDEFAULTRESPONSE
            empty_string: YEMPTY
            exit_response: So long, and thanks for the fish!
            exit_response_srai: YEXITRESPONSE
            override_properties: true
            max_question_recursion: 1000
            max_question_timeout: 60
            max_search_depth: 100
            max_search_timeout: 60
            
            spelling:
              classname: programr.spelling.norvig.NorvigSpellingChecker
              alphabet: 'abcdefghijklmnopqrstuvwxyz'
              corpus: $BOT_ROOT/corpus.txt
              check_before: true
              check_and_retry: true
              
            conversations:
              type: file
              config_name: file_storage
        
            file_storage:
              dir: $BOT_ROOT/conversations

        """, ConsoleConfiguration(), ".")

        bot_config = BotConfiguration()
        bot_config.load_configuration(yaml, ".")

        self.assertEqual("Hi, how can I help you today?", bot_config.initial_question)
        self.assertEqual("YINITIALQUESTION", bot_config.initial_question_srai)
        self.assertEqual("Sorry, I don't have an answer for that!", bot_config.default_response)
        self.assertEqual("YDEFAULTRESPONSE", bot_config.default_response_srai)
        self.assertEqual("So long, and thanks for the fish!", bot_config.exit_response)
        self.assertEqual("YEXITRESPONSE", bot_config.exit_response_srai)
        self.assertEqual("YEMPTY", bot_config.empty_string)
        self.assertEqual(bot_config.max_question_recursion, 1000)
        self.assertEqual(bot_config.max_question_timeout, 60)
        self.assertEqual(bot_config.max_search_depth, 100)
        self.assertEqual(bot_config.max_search_timeout, 60)
        self.assertTrue(bot_config.override_properties)

        self.assertIsNotNone(bot_config.spelling)
        self.assertEqual("programr.spelling.norvig.NorvigSpellingChecker", bot_config.spelling.classname)

        self.assertIsNotNone(bot_config.conversations)
        self.assertEquals(bot_config.conversations.type, "file")
        self.assertIsNotNone(bot_config.conversations.storage)
        self.assertEquals(bot_config.conversations.storage.dir, "./conversations")
예제 #11
0
    def test_load_from_text_multis_one_value(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        configuration = yaml.load_from_text("""
            bot:
                brain:  bot1
        """, ConsoleConfiguration(), ".")
        self.assertIsNotNone(configuration)

        self.assertEquals(1, len(configuration.client_configuration.brain_config[0].brain_config))
예제 #12
0
    def test_with_no_data(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text("""
        brain:
        """, ConsoleConfiguration(), ".")

        brain_config = yaml.get_section("brain")

        dynamic_config = BrainDynamicsConfiguration()
        dynamic_config.load_config_section(yaml, brain_config, ".")
예제 #13
0
    def test_init_no_values(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text("""
        console:
        """, ConsoleConfiguration(), ".")

        config = ConsoleConfiguration()
        config.load_configuration(yaml, ".")

        self.assertIsNotNone(config.configurations)
        self.assertEquals(1, len(config.configurations))
예제 #14
0
    def test_init_no_values(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text("""
        twilio:
        """, ConsoleConfiguration(), ".")

        twilio_config = TwilioConfiguration()
        twilio_config.load_configuration(yaml, ".")

        self.assertEqual("0.0.0.0", twilio_config.host)
        self.assertEqual(80, twilio_config.port)
        self.assertEqual(False, twilio_config.debug)
예제 #15
0
    def test_without_data(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text(
            """
        brain:
            tokenizer:
        """, ConsoleConfiguration(), ".")

        brain_config = yaml.get_section("brain")

        tokenizer_config = BrainTokenizerConfiguration()
        tokenizer_config.load_config_section(yaml, brain_config, ".")
예제 #16
0
    def test_init_no_values(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text("""
        facebook:
        """, ConsoleConfiguration(), ".")

        facebook_config = FacebookConfiguration()
        facebook_config.load_configuration(yaml, ".")

        self.assertEqual("0.0.0.0", facebook_config.host)
        self.assertEqual(80, facebook_config.port)
        self.assertEqual(False, facebook_config.debug)
예제 #17
0
    def test_init(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text(
            """
            slack:
              polling_interval: 1
        """, ConsoleConfiguration(), ".")

        slack_config = SlackConfiguration()
        slack_config.load_configuration(yaml, ".")

        self.assertEqual(1, slack_config.polling_interval)
예제 #18
0
    def test_init_no_values(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text("""
        line:
        """, ConsoleConfiguration(), ".")

        line_config = LineConfiguration()
        line_config.load_configuration(yaml, ".")

        self.assertEqual("0.0.0.0", line_config.host)
        self.assertEqual(80, line_config.port)
        self.assertEqual(False, line_config.debug)
예제 #19
0
    def test_with_no_data(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text("""
        bot:
        """, ConsoleConfiguration(), ".")

        bot_config = yaml.get_section("bot")

        redis_config = BotConversationsRedisStorageConfiguration("redis")
        redis_config.load_config_section(yaml, bot_config, ".")

        self.assertEquals("localhost", redis_config.host)
        self.assertEquals(6379, redis_config.port)
예제 #20
0
    def test_with_no_data(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text("""
        brain:
        """, ConsoleConfiguration(), ".")

        brain_config = yaml.get_section("brain")

        braintree_config = BrainBraintreeConfiguration()
        braintree_config.load_config_section(yaml, brain_config, ".")

        self.assertIsNone(braintree_config.file)
        self.assertIsNone(braintree_config.content)
예제 #21
0
    def test_with_no_data(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text("""
        brain:
        """, ConsoleConfiguration(), ".")

        brain_config = yaml.get_section("brain")

        nodes_config = BrainNodesConfiguration()
        nodes_config.load_config_section(yaml, brain_config, ".")

        self.assertIsNone(nodes_config.pattern_nodes)
        self.assertIsNone(nodes_config.template_nodes)
예제 #22
0
    def test_init_no_values(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text("""
        rest:
        """, ConsoleConfiguration(), ".")

        rest_config = RestConfiguration("rest")
        rest_config.load_configuration(yaml, ".")

        self.assertEqual("0.0.0.0", rest_config.host)
        self.assertEqual(80, rest_config.port)
        self.assertEqual(False, rest_config.debug)
        self.assertEqual(False, rest_config.use_api_keys)
예제 #23
0
    def test_without_data(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text("""
        bot:
        """, ConsoleConfiguration(), ".")

        bot_config = yaml.get_section("bot")

        convo_config = BotConversationsFileStorageConfiguration(
            config_name="file_storage")
        convo_config.load_config_section(yaml, bot_config, ".")

        self.assertIsNone(convo_config.dir)
예제 #24
0
    def test_with_no_data(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text("""
        brain:
        """, ConsoleConfiguration(), ".")

        brain_config = yaml.get_section("brain")

        overrides_config = BrainOverridesConfiguration()
        overrides_config.load_config_section(yaml, brain_config, ".")

        self.assertFalse(overrides_config.allow_system_aiml)
        self.assertFalse(overrides_config.allow_learn_aiml)
        self.assertFalse(overrides_config.allow_learnf_aiml)
예제 #25
0
    def test_init_no_values(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text("""
        kik:
        """, ConsoleConfiguration(), ".")

        kik_config = KikConfiguration()
        kik_config.load_configuration(yaml, ".")

        self.assertEqual("program-y", kik_config.bot_name)
        self.assertEqual("https://localhost:5000", kik_config.webhook)
        self.assertEqual("0.0.0.0", kik_config.host)
        self.assertEqual(80, kik_config.port)
        self.assertEqual(False, kik_config.debug)
예제 #26
0
    def test_with_no_data(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text("""
        brain:
        """, ConsoleConfiguration(), ".")

        brain_config = yaml.get_section("brain")

        oobs_config = BrainOOBSConfiguration()
        oobs_config.load_config_section(yaml, brain_config, ".")

        self.assertFalse(oobs_config.exists("default"))
        self.assertFalse(oobs_config.exists("dial"))
        self.assertFalse(oobs_config.exists("email"))
        self.assertFalse(oobs_config.exists("Other"))
예제 #27
0
    def test_init_no_values(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text("""
        viber:
        """, ConsoleConfiguration(), ".")

        viber_config = ViberConfiguration()
        viber_config.load_configuration(yaml, ".")

        self.assertEqual("0.0.0.0", viber_config.host)
        self.assertEqual(80, viber_config.port)
        self.assertEqual(False, viber_config.debug)
        self.assertIsNone(viber_config.name)
        self.assertIsNone(viber_config.avatar)
        self.assertIsNone(viber_config.webhook)
예제 #28
0
    def test_with_no_data(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text("""
        brain:
        """, ConsoleConfiguration(), ".")

        brain_config = yaml.get_section("brain")

        binaries_config = BrainBinariesConfiguration()
        binaries_config.load_config_section(yaml, brain_config, ".")

        self.assertFalse(binaries_config.save_binary)
        self.assertFalse(binaries_config.load_binary)
        self.assertIsNone(binaries_config.binary_filename)
        self.assertFalse(binaries_config.load_aiml_on_binary_fail)
예제 #29
0
    def test_brain_init_with_secure_config(self):

        yaml = YamlConfigurationFile()
        self.load_os_specific_configuration(yaml, "test_secure_brain.yaml",
                                            "test_secure_brain.windows.yaml")

        brain_config = BrainConfiguration()
        brain_config.load_configuration(yaml, os.path.dirname(__file__))

        brain = Brain(None, brain_config)
        self.assertIsNotNone(brain)

        self.assertIsNotNone(brain.aiml_parser)
        self.assertIsNotNone(brain.denormals)
        self.assertIsNotNone(brain.normals)
        self.assertIsNotNone(brain.genders)
        self.assertIsNotNone(brain.persons)
        self.assertIsNotNone(brain.person2s)
        self.assertIsNotNone(brain.properties)
        self.assertIsNotNone(brain.rdf)
        self.assertIsNotNone(brain.sets)
        self.assertIsNotNone(brain.maps)
        self.assertIsNotNone(brain.preprocessors)
        self.assertIsNotNone(brain.postprocessors)
        self.assertIsNotNone(brain.authentication)
        self.assertIsNotNone(brain.authorisation)
        self.assertIsNone(brain.default_oob)
        self.assertEquals({}, brain.oobs)
예제 #30
0
    def test_with_no_data(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text("""
        brain:
        """, ConsoleConfiguration(), ".")

        brain_config = yaml.get_section("brain")

        defaults_config = BrainDefaultsConfiguration()
        defaults_config.load_config_section(yaml, brain_config, ".")

        if os.name == 'posix':
            self.assertEqual('/tmp/learnf', defaults_config.learnf_path)
        elif os.name == 'nt':
            self.assertEqual('C:\Windows\Temp\learnf',
                             defaults_config.learnf_path)