def test_with_data(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text(""" bot: license_keys: $BOT_ROOT/config/license.keys prompt: ">>>" initial_question: Hi, how can I help you today? default_response: Sorry, I don't have an answer for that! empty_string: YEMPTY exit_response: So long, and thanks for the fish! override_predicates: true max_recursion: 10 spelling: classname: programy.utils.spelling.checker.SpellingChecker alphabet: 'abcdefghijklmnopqrstuvwxyz' corpus: $BOT_ROOT/corpus.txt check_before: true check_and_retry: true """, ConsoleConfiguration(), ".") bot_config = BotConfiguration() bot_config.load_config_section(yaml, ".") self.assertEqual("./config/license.keys", bot_config.license_keys) self.assertEqual(">>>", bot_config.prompt) self.assertEqual("Hi, how can I help you today?", bot_config.initial_question) self.assertEqual("Sorry, I don't have an answer for that!", bot_config.default_response) self.assertEqual("YEMPTY", bot_config.empty_string) self.assertEqual(10, bot_config.max_recursion) self.assertTrue(bot_config.override_predicates) self.assertIsNotNone(bot_config.spelling) self.assertEqual("programy.utils.spelling.checker.SpellingChecker", bot_config.spelling.classname)
class ProgramyConfiguration(object): def __init__(self, client_configuration, brain_config=None, bot_config=None): if brain_config is None: self._brain_config = BrainConfiguration() else: self._brain_config = brain_config if bot_config is None: self._bot_config = BotConfiguration() else: self._bot_config = bot_config self._client_config = client_configuration @property def brain_configuration(self): return self._brain_config @property def bot_configuration(self): return self._bot_config @property def client_configuration(self): return self._client_config def load_config_data(self, config_file, bot_root): self._brain_config.load_config_section(config_file, bot_root) self._bot_config.load_config_section(config_file, bot_root) self._client_config.load_config_section(config_file, bot_root)
def test_without_data(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text(""" bot: """, ConsoleConfiguration(), ".") bot_config = BotConfiguration() bot_config.load_config_section(yaml, ".") self.assertIsNone(bot_config.license_keys) self.assertEqual(">>> ", bot_config.prompt) self.assertEqual("Hello", bot_config.initial_question) self.assertEqual("", bot_config.default_response) self.assertEqual("", bot_config.empty_string) self.assertEqual(10, bot_config.max_recursion) self.assertTrue(bot_config.override_predicates) self.assertIsNotNone(bot_config.spelling)