コード例 #1
0
def test_file_io_write_read(tc_unittest):
    temp_file = tc_unittest.get_temp_file()
    fileio = FileIO(temp_file)
    input_content = tc_unittest.get_utf8_test_messages(counter=1)
    fileio.write(input_content)
    output = fileio.read()
    assert input_content == output
コード例 #2
0
def test_file_io_multiple_write_read(tc_unittest):
    temp_file = tc_unittest.get_temp_file()
    fileio = FileIO(tc_unittest.get_fake_logger_factory(), temp_file)
    input_content = tc_unittest.get_utf8_test_messages(counter=1)
    fileio.write(input_content)
    fileio.write(input_content)
    output = fileio.read()
    assert input_content + input_content == output
コード例 #3
0
ファイル: test_file_io.py プロジェクト: zaf00130/syslog-ng
def test_file_io_rewrite_read(temp_file):
    fileio = FileIO(temp_file)
    content1 = "message 1\n"
    fileio.write(content1)
    assert fileio.read() == content1
    content2 = "message 2\n"
    fileio.rewrite(content2)
    assert fileio.read(position=0) == content2
コード例 #4
0
def test_file_io_rewrite_read(tc_unittest):
    temp_file = tc_unittest.get_temp_file()
    fileio = FileIO(temp_file)
    content1 = "message 1\n"
    fileio.write(content1)
    assert fileio.read() == content1
    content2 = "message 2\n"
    fileio.rewrite(content2)
    assert fileio.read(position=0) == content2
コード例 #5
0
class FileSource(SourceDriver):
    def __init__(self, file_name, **options):
        self.driver_name = "file"
        self.set_path(file_name)
        self.io = FileIO(self.get_path())
        super(FileSource, self).__init__([self.path], options)

    def get_path(self):
        return self.path

    def set_path(self, pathname):
        self.path = Path(tc_parameters.WORKING_DIR, pathname)

    def write_log(self, formatted_log, counter=1):
        for _ in range(counter):
            self.io.write(formatted_log)
        logger.info(
            "Content has been written to\nresource: {}\n"
            "number of times: {}\n"
            "content: {}\n".format(self.get_path(), counter, formatted_log), )
コード例 #6
0
ファイル: test_file_io.py プロジェクト: syslog-ng/syslog-ng
def test_file_io_multiple_write_read(temp_file, test_message):
    fileio = FileIO(temp_file)
    fileio.write(test_message)
    fileio.write(test_message)
    output = fileio.read_number_of_lines(2)
    assert [test_message, test_message] == output
コード例 #7
0
ファイル: test_file_io.py プロジェクト: zaf00130/syslog-ng
def test_file_io_multiple_write_read(temp_file, test_message):
    fileio = FileIO(temp_file)
    fileio.write(test_message)
    fileio.write(test_message)
    output = fileio.read()
    assert test_message + test_message == output