コード例 #1
0
ファイル: test_json.py プロジェクト: frdino131/RyanCBT
    def test_get_methods(self):
        config_data = JSONConfigurationFile()
        self.assertIsNotNone(config_data)
        configuration = config_data.load_from_text(
            """
        {
        	"brain": {
        		"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"))
コード例 #2
0
ファイル: test_json.py プロジェクト: lilnana00/3ddd
    def test_load_with_subs(self):
        subs = Substitutions()
        subs.add_substitute("$ALLOW_SYSTEM", True)

        config_data = JSONConfigurationFile()
        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"))