def test_pandora_with_data(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text( """ brain: services: Pandora: classname: programr.services.pandora.PandoraService url: http://www.pandorabots.com/pandora/talk-xml """, ConsoleConfiguration(), ".") brain_config = yaml.get_section("brain") self.assertIsNotNone(brain_config) services_config = yaml.get_section("services", brain_config) self.assertIsNotNone(services_config) service_config = BrainServiceConfiguration("Pandora") service_config.load_config_section(yaml, services_config, ".") self.assertEqual("programr.services.pandora.PandoraService", service_config.classname) self.assertEqual("http://www.pandorabots.com/pandora/talk-xml", service_config.url) self.assertIsNone(service_config.method) self.assertIsNone(service_config.host) self.assertIsNone(service_config.port)
def test_rest_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 """, ConsoleConfiguration(), ".") brain_config = yaml.get_section("brain") self.assertIsNotNone(brain_config) services_config = yaml.get_section("services", brain_config) self.assertIsNotNone(services_config) service_config = BrainServiceConfiguration("REST") service_config.load_config_section(yaml, services_config, ".") self.assertEqual("programr.services.rest.GenericRESTService", service_config.classname) self.assertEqual("GET", service_config.method) self.assertEqual("0.0.0.0", service_config.host) self.assertIsNone(service_config.port) self.assertIsNone(service_config.url)
def test_with_file_data(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text( """ brain: files: aiml: file: $BOT_ROOT/aiml/test.aiml errors: /tmp/y-bot-errors.txt duplicates: /tmp/y-bot-duplicates.txt conversation: /tmp/y-bot-conversation.txt """, ConsoleConfiguration(), ".") brain_config = yaml.get_section("brain") self.assertIsNotNone(brain_config) files_config = yaml.get_section("files", brain_config) self.assertIsNotNone(files_config) aiml_config = BrainAIMLFileConfiguration() aiml_config.load_config_section(yaml, files_config, ".") self.assertEqual("./aiml/test.aiml", aiml_config.file) self.assertEqual("aiml", aiml_config.extension) self.assertFalse(aiml_config.directories) self.assertEqual("/tmp/y-bot-errors.txt", aiml_config.errors.filename) self.assertEqual("/tmp/y-bot-duplicates.txt", aiml_config.duplicates.filename) self.assertEqual("/tmp/y-bot-conversation.txt", aiml_config.conversation.filename)
def test_wikipedia_with_data(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text( """ brain: services: Wikipedia: classname: programr.services.wikipediaservice.WikipediaService """, ConsoleConfiguration(), ".") brain_config = yaml.get_section("brain") self.assertIsNotNone(brain_config) services_config = yaml.get_section("services", brain_config) self.assertIsNotNone(services_config) service_config = BrainServiceConfiguration("Wikipedia") service_config.load_config_section(yaml, services_config, ".") self.assertEqual("programr.services.wikipediaservice.WikipediaService", service_config.classname) self.assertIsNone(service_config.method) self.assertIsNone(service_config.host) self.assertIsNone(service_config.port) self.assertIsNone(service_config.url)
def test_with_new_format_data(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text( """ brain: files: aiml: errors: file: /tmp/y-bot_errors.csv format: csv encoding: utf-8 delete_on_start: true """, ConsoleConfiguration(), ".") brain_config = yaml.get_section("brain") self.assertIsNotNone(brain_config) files_config = yaml.get_section("files", brain_config) self.assertIsNotNone(files_config) aiml_config = yaml.get_section("aiml", files_config) self.assertIsNotNone(aiml_config) debugfile_config = DebugFileConfiguration("errors") debugfile_config.load_config_section(yaml, aiml_config, ".") self.assertEquals("/tmp/y-bot_errors.csv", debugfile_config.filename) self.assertEquals("csv", debugfile_config.file_format) self.assertEquals("utf-8", debugfile_config.encoding) self.assertTrue(debugfile_config.delete_on_start)
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)
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"))
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)
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)
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)
def test_with_files_data(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text( """ brain: files: aiml: files: $BOT_ROOT/aiml extension: .aiml directories: true errors: file: /tmp/y-bot-errors.txt format: txt encoding: utf-8 delete_on_start: true duplicates: file: /tmp/y-bot-duplicates.txt format: txt encoding: utf-8 delete_on_start: true conversation: file: /tmp/y-bot-conversation.csv format: csv delete_on_start: true """, ConsoleConfiguration(), ".") brain_config = yaml.get_section("brain") self.assertIsNotNone(brain_config) files_config = yaml.get_section("files", brain_config) self.assertIsNotNone(files_config) aiml_config = BrainAIMLFileConfiguration() aiml_config.load_config_section(yaml, files_config, ".") self.assertEqual(["./aiml"], aiml_config.files) self.assertEqual(".aiml", aiml_config.extension) self.assertTrue(aiml_config.directories) self.assertEqual("/tmp/y-bot-errors.txt", aiml_config.errors.filename) self.assertEqual("/tmp/y-bot-duplicates.txt", aiml_config.duplicates.filename) self.assertEqual("/tmp/y-bot-conversation.csv", aiml_config.conversation.filename)
def test_default_without_data(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text( """ brain: oobs: default: """, ConsoleConfiguration(), ".") brain_config = yaml.get_section("brain") self.assertIsNotNone(brain_config) oobs_config = yaml.get_section("oobs", brain_config) self.assertIsNotNone(oobs_config) oob_config = BrainOOBConfiguration("default") oob_config.load_config_section(yaml, oobs_config, ".") self.assertIsNone(oob_config.classname)
def test_with_file_data(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text( """ brain: files: sets: file: $BOT_ROOT/sets/test.txt """, ConsoleConfiguration(), ".") brain_config = yaml.get_section("brain") self.assertIsNotNone(brain_config) files_config = yaml.get_section("files", brain_config) self.assertIsNotNone(files_config) sets_config = BrainFileConfiguration("sets") sets_config.load_config_section(yaml, files_config, ".") self.assertEqual("./sets/test.txt", sets_config.file)
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, ".")
def test_oob_with_data(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text( """ brain: oobs: default: classname: programr.oob.default.DefaultOutOfBandProcessor """, ConsoleConfiguration(), ".") brain_config = yaml.get_section("brain") self.assertIsNotNone(brain_config) oobs_config = yaml.get_section("oobs", brain_config) self.assertIsNotNone(oobs_config) oob_config = BrainOOBConfiguration("default") oob_config.load_config_section(yaml, oobs_config, ".") self.assertEqual("programr.oob.default.DefaultOutOfBandProcessor", oob_config.classname)
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, ".")
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)
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)
def test_rest_without_data(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text( """ brain: services: REST: """, ConsoleConfiguration(), ".") brain_config = yaml.get_section("brain") self.assertIsNotNone(brain_config) services_config = yaml.get_section("services", brain_config) self.assertIsNotNone(services_config) service_config = BrainServiceConfiguration("REST") service_config.load_config_section(yaml, services_config, ".") self.assertIsNone(service_config.classname) self.assertIsNone(service_config.method) self.assertIsNone(service_config.host) self.assertIsNone(service_config.port) self.assertIsNone(service_config.url)
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)
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)
def test_get_methods(self): config_data = YamlConfigurationFile() self.assertIsNotNone(config_data) configuration = config_data.load_from_text(""" brain: # Overrides overrides: allow_system_aiml: true allow_learn_aiml: true allow_learnf_aiml: true int_value: 999 """, ConsoleConfiguration(), ".") self.assertIsNotNone(configuration) section = config_data.get_section("brainx") self.assertIsNone(section) section = config_data.get_section("brain") self.assertIsNotNone(section) child_section = config_data.get_section("overrides", section) self.assertIsNotNone(child_section) keys = list(config_data.get_child_section_keys("overrides", section)) self.assertIsNotNone(keys) self.assertEqual(4, len(keys)) self.assertTrue("allow_system_aiml" in keys) self.assertTrue("allow_learn_aiml" in keys) self.assertTrue("allow_learnf_aiml" in keys) self.assertIsNone(config_data.get_child_section_keys("missing", section)) self.assertEqual(True, config_data.get_option(child_section, "allow_system_aiml")) self.assertEqual(True, config_data.get_option(child_section, "missing", missing_value=True)) self.assertEqual(True, config_data.get_bool_option(child_section, "allow_system_aiml")) self.assertEqual(False, config_data.get_bool_option(child_section, "other_value")) self.assertEqual(999, config_data.get_int_option(child_section, "int_value")) self.assertEqual(0, config_data.get_int_option(child_section, "other_value"))
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)
def test_with_files_data(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text( """ brain: files: sets: files: $BOT_ROOT/sets extension: .txt directories: false """, ConsoleConfiguration(), ".") brain_config = yaml.get_section("brain") self.assertIsNotNone(brain_config) files_config = yaml.get_section("files", brain_config) self.assertIsNotNone(files_config) sets_config = BrainFileConfiguration("sets") sets_config.load_config_section(yaml, files_config, ".") self.assertEqual(["./sets"], sets_config.files) self.assertEqual(".txt", sets_config.extension) self.assertFalse(sets_config.directories)
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)
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"))
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)
def test_with_data(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text( """ brain: tokenizer: classname: programr.utils.language.chinese.ChineseLanguage """, ConsoleConfiguration(), ".") brain_config = yaml.get_section("brain") tokenizer_config = BrainTokenizerConfiguration() tokenizer_config.load_config_section(yaml, brain_config, ".") self.assertEqual("programr.utils.language.chinese.ChineseLanguage", tokenizer_config.classname)
def test_with_no_data(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text(""" bot: """, ConsoleConfiguration(), ".") bot_config = yaml.get_section("bot") spelling_config = BotSpellingConfiguration() spelling_config.load_config_section(yaml, bot_config, ".") self.assertIsNone(spelling_config.classname) self.assertIsNone(spelling_config.corpus) self.assertIsNone(spelling_config.alphabet) self.assertFalse(spelling_config.check_before) self.assertFalse(spelling_config.check_and_retry)
def test_with_no_data(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text(""" brain: """, ConsoleConfiguration(), ".") brain_config = yaml.get_section("brain") services_config = BrainServicesConfiguration() services_config.load_config_section(yaml, brain_config, ".") self.assertFalse(services_config.exists("REST")) self.assertFalse(services_config.exists("Pannous")) self.assertFalse(services_config.exists("Pandora")) self.assertFalse(services_config.exists("Wikipedia")) self.assertFalse(services_config.exists("Other"))