Exemplo n.º 1
0
    def test_with_new_format_data(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text(
            """
        brain:
            files:
                aiml:
                    errors:
                      file: /tmp/y-bot_errors.csv
                      format: csv
                      encoding: utf-8
                      delete_on_start: true
        """, ConsoleConfiguration(), ".")

        brain_config = yaml.get_section("brain")
        self.assertIsNotNone(brain_config)
        files_config = yaml.get_section("files", brain_config)
        self.assertIsNotNone(files_config)
        aiml_config = yaml.get_section("aiml", files_config)
        self.assertIsNotNone(aiml_config)

        debugfile_config = DebugFileConfiguration("errors")
        debugfile_config.load_config_section(yaml, aiml_config, ".")

        self.assertEquals("/tmp/y-bot_errors.csv", debugfile_config.filename)
        self.assertEquals("csv", debugfile_config.file_format)
        self.assertEquals("utf-8", debugfile_config.encoding)
        self.assertTrue(debugfile_config.delete_on_start)
Exemplo n.º 2
0
 def get_debug_file_configuration(self, configuration_file, files_config, debug_name, bot_root):
     keys = configuration_file.get_keys(files_config)
     if debug_name in keys:
         section = configuration_file.get_section(debug_name, files_config)
         if configuration_file.is_string(section):
             debug_config = configuration_file.get_option(files_config, debug_name, missing_value=None)
             if debug_config is not None:
                 filename = self.sub_bot_root(debug_config, bot_root)
                 return DebugFileConfiguration(debug_name, filename=filename)
         else:
             debug_file = DebugFileConfiguration(debug_name)
             debug_file.load_config_section(configuration_file, files_config, bot_root)
             return debug_file
     return None
Exemplo n.º 3
0
    def test_as_csv(self):
        configuration = DebugFileConfiguration(name="tests", filename="./testfile.txt")

        self.remove_file_assert_not_there(configuration.filename)

        file_writer = FileWriter(configuration)
        self.assertIsNotNone(file_writer)

        self.remove_file_assert_not_there(configuration.filename)
Exemplo n.º 4
0
    def setUp(self):
        bot_config = BotConfiguration()

        if os.name == 'posix':
            bot_config.brain_config[
                0].files.aiml_files._errors = DebugFileConfiguration(
                    "conversation", filename="/tmp/tmp-errors.txt.txt")
        elif os.name == 'nt':
            bot_config.brain_config[
                0].files.aiml_files._errors = DebugFileConfiguration(
                    "conversation",
                    filename='C:\Windows\Temp\\tmp-errors.txt.txt')
        else:
            raise Exception("Unknown os [%s]" % os.name)

        bot = Bot(bot_config)

        self.parser = bot.brain.aiml_parser
        self.parser.create_debug_storage(bot_config.brain_config[0])
        self.assertIsNotNone(self.parser)
Exemplo n.º 5
0
    def test_writing(self):
        configuration = DebugFileConfiguration(name="tests", filename="./testfile.txt")

        self.remove_file_assert_not_there(configuration.filename)

        writer = ConversationFileWriter(configuration)
        self.assertIsNotNone(writer)
        writer.log_question_and_answer("testid", "hello", "hi there")

        self.assertTrue(os.path.exists(configuration.filename))

        self.remove_file_assert_not_there(configuration.filename)
Exemplo n.º 6
0
    def test_error_writing(self):
        configuration = DebugFileConfiguration(name="tests", filename="./testfile.txt")

        self.remove_file_assert_not_there(configuration.filename)

        writer = ErrorsFileWriter(configuration)
        self.assertIsNotNone(writer)

        writer.save_entry("error1", "test.aiml", 100, 103)
        self.assertIsNotNone(writer.entries)
        self.assertEquals(1, len(writer.entries))
        writer.save_entry("error2", "test.aiml", 200, 203)
        self.assertEquals(2, len(writer.entries))

        writer.save_content()
        self.assertTrue(os.path.exists(configuration.filename))

        self.remove_file_assert_not_there(configuration.filename)
Exemplo n.º 7
0
 def to_yaml(self, data, defaults=True):
     self.config_to_yaml(data, DebugFileConfiguration('errors'), defaults)
     self.config_to_yaml(data, DebugFileConfiguration('duplicates'), defaults)
     self.config_to_yaml(data, DebugFileConfiguration('conversation'), defaults)