#! /usr/bin/env python # -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*- # # This file is part of the LibreOffice project. # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. #
import unittest
import uno from org.libreoffice.unotest import UnoInProcess
class TestTempFile(unittest.TestCase): """Test temporary file object created from com.sun.star.io.TempFile"""
def test_01(self):
file_uri = self.get_temp_file_url()
file_name = self.get_temp_file_name()
print("Tempfile URL:", file_uri)
print("Tempfile name:", file_name)
self.assertTrue(
file_uri.endswith(file_name.replace("\\", "/")), "FILE NAME AND URL DO NOT MATCH.",
)
# write to the stream using the service.
self.write_bytes_with_stream()
# check the result by reading from the service.
self.temp_file.seek(0)
read_data = self.read_bytes_with_stream()
self.assertEqual(self.file_data, read_data, "Tempfile outputs false data!")
# check the result by reading from the file directly.
read_data = self.read_directly_from_temp_file(file_uri)
self.assertEqual(self.file_data, read_data, "Tempfile contains false data!")
# close the object(by closing input and output), check that the file # was removed.
self.temp_file.RemoveFile = False # After tempfile is closed, file name cannot be got from a TempFile object.
file_name = self.temp_file.ResourceName
self.close_temp_file()
self.assertTrue(
self.file_access.exists(file_name), "TempFile mistakenly removed.",
)
# Finally, cleanup this temp file.
self.file_access.kill(file_name)
def test_02(self):
self.write_bytes_with_stream()
file_url = self.get_temp_file_url() # let the service not to remove the URL.
self.temp_file.RemoveFile = False # close the tempfile by closing input and output.
self.close_temp_file() # check that the file is still available.
read_data = self.read_directly_from_temp_file(file_url)
self.assertEqual(self.file_data, read_data, "Tempfile contains false data!")
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.