Esempio n. 1
0
    def test_invalid_file_format(self):

        filename = get_os_specific_path() + 'writefile.tmp'

        with self.assertRaises(Exception):
            filewriter = FileWriter(
                MockFileWriterConfig(filename, fileformat="unknown"))
Esempio n. 2
0
    def test_init(self):
        filename = get_os_specific_path() + os.sep + "conversation.txt"
        config = FileWriterConfiguration(filename=filename, fileformat="txt", mode="a", encoding="utf-8",
                                         delete_on_start=False)

        writer = ConversationFileWriter(config)
        self.assertIsNotNone(writer)

        writer.log_question_and_answer("client1", "question", "answer")
        self.assertTrue(os.path.exists(filename))

        if os.path.exists(filename):
            os.remove(filename)
            self.assertFalse(os.path.exists(filename))
Esempio n. 3
0
    def test_init(self):
        filename = get_os_specific_path() + 'textfile.tmp'

        if os.path.exists(filename):
            os.remove(filename)

        self.assertFalse(os.path.exists(filename))

        textfile = TextFile(filename)
        self.assertIsNotNone(textfile)

        self.assertEqual("/tmp/textfile.tmp", textfile.filename)
        self.assertEqual("utf-8", textfile.encoding)
        self.assertTrue(os.path.exists(filename))

        textfile.write_line(MockFileWriter(), "this is a row")

        os.remove(filename)

        self.assertFalse(os.path.exists(filename))
Esempio n. 4
0
    def test_init_csv(self):

        filename = get_os_specific_path() + 'writefile.tmp'

        if os.path.exists(filename):
            os.remove(filename)

        self.assertFalse(os.path.exists(filename))

        filewriter = FileWriter(
            MockFileWriterConfig(filename,
                                 delete=True,
                                 fileformat='csv',
                                 encoding='utf-8'))
        self.assertIsNotNone(filewriter)

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

        os.remove(filename)

        self.assertFalse(os.path.exists(filename))
Esempio n. 5
0
    def test_init(self):
        filename = get_os_specific_path() + 'csvfile.csv'

        if os.path.exists(filename):
            os.remove(filename)

        self.assertFalse(os.path.exists(filename))

        csvfile = CSVFile(filename)
        self.assertIsNotNone(csvfile)

        self.assertEqual("/tmp/csvfile.csv", csvfile.filename)
        self.assertEqual("utf-8", csvfile.encoding)
        self.assertTrue(os.path.exists(filename))

        csvfile.write_line(None, ["A", "B", "C"])

        csvfile.flush()

        os.remove(filename)

        self.assertFalse(os.path.exists(filename))
Esempio n. 6
0
    def test_init_txt_with_existing_file(self):

        filename = get_os_specific_path() + 'writefile.tmp'

        if os.path.exists(filename) is False:
            with open(filename, 'w') as newfile:
                newfile.writelines(["line1"])

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

        filewriter = FileWriter(
            MockFileWriterConfig(filename,
                                 delete=True,
                                 fileformat='txt',
                                 encoding='utf-8'))
        self.assertIsNotNone(filewriter)

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

        os.remove(filename)

        self.assertFalse(os.path.exists(filename))
Esempio n. 7
0
    def test_init(self):

        filename = get_os_specific_path() + os.sep + "duplicates.txt"
        config = FileWriterConfiguration(filename=filename,
                                         fileformat="txt",
                                         mode="a",
                                         encoding="utf-8",
                                         delete_on_start=False)

        writer = DuplicatesFileWriter(config)
        self.assertIsNotNone(writer)

        writer.save_entry("<xml>Error with line numbers</xml>", "test.aiml",
                          100, 666)
        writer.save_entry("<xml>Error with no line numbers</xml>",
                          "test2.aiml")
        self.assertEquals(2, len(writer.entries))
        writer.save_content()

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

        if os.path.exists(filename):
            os.remove(filename)
            self.assertFalse(os.path.exists(filename))
Esempio n. 8
0
    def test_init_txt(self):

        filename = get_os_specific_path() + 'writefile.tmp'

        if os.path.exists(filename):
            os.remove(filename)

        self.assertFalse(os.path.exists(filename))

        filewriter = FileWriter(
            MockFileWriterConfig(filename,
                                 delete=True,
                                 fileformat='txt',
                                 encoding='utf-8'))
        self.assertIsNotNone(filewriter)

        filewriter.write_header()
        self.assertEquals("line", filewriter.format_row_as_text("line"))

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

        os.remove(filename)

        self.assertFalse(os.path.exists(filename))