Example #1
0
    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"))
Example #2
0
    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"))
Example #3
0
    def test_load_from_file(self):
        client_config = ClientConfiguration()
        json = JSONConfigurationFile(client_config)
        self.assertIsNotNone(json)
        json.load_from_file(os.path.dirname(__file__) + "/test_json.json", ",")
        self.assertIsNotNone(json.json_data)
        brain = json.get_section("brain")
        self.assertIsNotNone(brain)
        files = json.get_section("files", brain)
        self.assertIsNotNone(files)
        aiml = json.get_section("aiml", files)
        self.assertIsNotNone(aiml)

        files = json.get_section("files", aiml)
        self.assertIsNotNone(files)
        self.assertEqual(files, "/aiml")
        extension = json.get_section("extension", aiml)
        self.assertIsNotNone(extension)
        self.assertEqual(extension, ".aiml")
        directories = json.get_section("directories", aiml)
        self.assertIsNotNone(directories)
        self.assertEqual(directories, True)
Example #4
0
    def test_get_invalid_values(self):
        config_data = JSONConfigurationFile()
        self.assertIsNotNone(config_data)
        configuration = config_data.load_from_text(
            """
        {"section1": {
            "section2": {
                  "boolvalue": true,
                  "intvalue": 23,
                  "strvalue": "hello",
                  "multivalue": [ "one", "two", "three" ]
                  }
              }
        }
                  """, 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(
            1, 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.assertTrue(config_data.get_bool_option(child_section, "intvalue"))
        self.assertTrue(config_data.get_bool_option(child_section, "strvalue"))

        self.assertEquals(['one', 'two', 'three'],
                          config_data.get_multi_option(child_section,
                                                       "multivalue"))
        self.assertEquals([True],
                          config_data.get_multi_option(child_section,
                                                       "boolvalue"))
        self.assertEquals([23],
                          config_data.get_multi_option(child_section,
                                                       "intvalue"))
        self.assertEquals(["hello"],
                          config_data.get_multi_option(child_section,
                                                       "strvalue"))

        self.assertEquals(['one', 'two', 'three'],
                          config_data.get_multi_file_option(
                              child_section, "multivalue", "."))
        self.assertEquals([],
                          config_data.get_multi_file_option(
                              child_section, "boolvalue", "."))
        self.assertEquals([],
                          config_data.get_multi_file_option(
                              child_section, "intvalue", "."))
        self.assertEquals(["hello"],
                          config_data.get_multi_file_option(
                              child_section, "strvalue", "."))

        self.assertEquals([],
                          config_data.get_multi_file_option(
                              child_section, "unknown1", "."))
        self.assertEquals(["missing1", "missing2"],
                          config_data.get_multi_file_option(
                              child_section,
                              "unknown1",
                              ".",
                              missing_value=["missing1", "missing2"]))