def test_load_with_subs(self): subs = Substitutions() subs.add_substitute("$ALLOW_SYSTEM", True) config_data = YamlConfigurationFile() self.assertIsNotNone(config_data) configuration = config_data.load_from_text(""" brain: overrides: allow_system_aiml: true allow_learn_aiml: true allow_learnf_aiml: true """, 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) self.assertEqual(True, config_data.get_option(child_section, "allow_system_aiml")) 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"))
def test_load_with_subs(self): subs = Substitutions() subs.add_substitute("$ALLOW_SYSTEM", True) config_data = XMLConfigurationFile() self.assertIsNotNone(config_data) configuration = config_data.load_from_text("""<?xml version="1.0" encoding="UTF-8" ?> <root> <brain> <overrides> <allow_system_aiml>true</allow_system_aiml> <allow_learn_aiml>true</allow_learn_aiml> <allow_learnf_aiml>true</allow_learnf_aiml> </overrides> </brain> </root>""", 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) self.assertEqual(True, config_data.get_option(child_section, "allow_system_aiml")) 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"))
def test_add_duplicate(self): sub = Substitutions() sub.add_substitute("$FIRSTNAME", "Fred") sub.add_substitute("$FIRSTNAME", "Fred") self.assertTrue(sub.has_substitute("$FIRSTNAME"))
def test_basics(self): sub = Substitutions() sub.add_substitute("$FIRSTNAME", "Fred") sub.add_substitute("$SURNAME", "West") sub.add_substitute("$WIFE", "Mary") self.assertTrue(sub.has_substitute("$FIRSTNAME")) self.assertFalse(sub.has_substitute("$FRED")) self.assertEquals("Fred", sub.get_substitute("$FIRSTNAME")) self.assertEquals("West", sub.get_substitute("$SURNAME")) self.assertEquals("Mary", sub.get_substitute("$WIFE")) with self.assertRaises(ValueError): sub.get_substitute("$NUMBER") sub.empty() self.assertFalse(sub.has_substitute("$FIRSTNAME")) self.assertFalse(sub.has_substitute("$SURNAME")) self.assertFalse(sub.has_substitute("$WIFE"))
def test_replace_subs(self): config = MockBaseConfigurationFile() subs = Substitutions() subs.add_substitute("TEST", "VALUE") self.assertEquals("VALUE", config._replace_subs(subs, "TEST"))