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(""" <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_get_methods(self): config_data = XMLConfigurationFile() self.assertIsNotNone(config_data) configuration = config_data.load_from_text( """ <root> <brain> <overrides> <allow_system_aiml>true</allow_system_aiml> <allow_learn_aiml>true</allow_learn_aiml> <allow_learnf_aiml>true</allow_learnf_aiml> <int_value>999</int_value> </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) 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_get_invalid_values(self): config_data = XMLConfigurationFile() self.assertIsNotNone(config_data) configuration = config_data.load_from_text( """ <console> <section1> <section2> <boolvalue>true</boolvalue> <intvalue>23</intvalue> <strvalue>hello</strvalue> <multivalue> <dir>one</dir> <dir>two</dir> <dir>three</dir> </multivalue> </section2> </section1> </console> """, ConsoleConfiguration(), ".") self.assertIsNotNone(configuration) section = config_data.get_section("section1") self.assertIsNotNone(section) child_section = config_data.get_section("section2", section) self.assertIsNotNone(child_section) self.assertEquals( 0, config_data.get_int_option(child_section, "boolvalue")) self.assertEquals( 23, config_data.get_int_option(child_section, "intvalue")) self.assertEquals( 0, config_data.get_int_option(child_section, "strvalue")) self.assertTrue(config_data.get_bool_option(child_section, "boolvalue")) self.assertFalse(config_data.get_bool_option(child_section, "intvalue")) self.assertFalse(config_data.get_bool_option(child_section, "strvalue")) self.assertEquals([], config_data.get_multi_option(child_section, "multivalue2")) self.assertEquals([], config_data.get_multi_file_option( child_section, "multivalue2", "."))
def test_get_methods(self): config_data = XMLConfigurationFile() self.assertIsNotNone(config_data) configuration = config_data.load_from_text(""" <root> <brain> <overrides> <allow_system_aiml>true</allow_system_aiml> <allow_learn_aiml>true</allow_learn_aiml> <allow_learnf_aiml>true</allow_learnf_aiml> <int_value>999</int_value> </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) 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"))