def test_file_write(self) -> None: """Test FileWrite attributes.""" from pineboolib.application import types from pineboolib import application import os qsa_sys = systype.SysType() txt = "avión, cañita" path_1 = "%s/test_systype_one_iso_8859-15.txt" % application.PROJECT.tmpdir path_2 = "%s/test_systype_one_utf-8.txt" % application.PROJECT.tmpdir if os.path.exists(path_1): os.remove(path_1) if os.path.exists(path_2): os.remove(path_2) qsa_sys.fileWriteIso(path_1, txt) qsa_sys.fileWriteUtf8(path_2, txt) file_1 = types.File(path_1, "ISO-8859-15") file_2 = types.File(path_2, "UTF-8") result_1 = file_1.read() result_2 = file_2.read() self.assertEqual(result_1, txt) self.assertEqual(result_2, txt)
def test_write_read_byte_1(self) -> None: """Check that you read the same as you write.""" temporal = "%s%s" % ( config.value("ebcomportamiento/temp_dir"), u"/test_types_file_bytes.txt", ) contenido = "Texto\n".encode("utf-8") types.File(temporal).write(contenido) contenido_2 = types.File(temporal).read(True) self.assertEqual(contenido, contenido_2.encode("utf-8")) os.remove(temporal)
def test_write_read_values_1(self) -> None: """Check that you read the same as you write.""" temporal = "%s%s" % (config.value("ebcomportamiento/temp_dir"), u"/test_types_file.txt") contenido = 'QT_TRANSLATE_NOOP("MetaData","Código")' contenido_3 = 'QT_TRANSLATE_NOOP("MetaData","Código")' types.File(temporal).write(contenido) contenido_2 = types.File(temporal).read() self.assertEqual(contenido, contenido_2) os.remove(temporal) types.File(temporal).write(contenido_3) contenido_4 = types.File(temporal).read() self.assertEqual(contenido_3, contenido_4) os.remove(temporal)
def test_write_read_line_1(self) -> None: """Check that you read the same as you write.""" temporal = "%s%s" % ( config.value("ebcomportamiento/temp_dir"), u"/test_types_file_lines.txt", ) contenido = "Esta es la linea" types.File(temporal).writeLine("%s 1" % contenido) types.File(temporal).writeLine("%s 2" % contenido, 4) file_read = types.File(temporal) linea_1 = file_read.readLine() self.assertEqual("%s 1\n" % contenido, linea_1) linea_2 = file_read.readLine() self.assertEqual("%s" % contenido[0:4], linea_2) os.remove(temporal)
def test_properties(self) -> None: temporal = "%s%s" % (config.value("ebcomportamiento/temp_dir"), u"/test_last_modified.txt") file_ = types.File(temporal) self.assertEqual(file_.path, config.value("ebcomportamiento/temp_dir")) self.assertEqual(file_.fullName, temporal) self.assertEqual(file_.extension, ".txt") self.assertEqual(file_.baseName, "test_last_modified") self.assertTrue(file_.exists) self.assertEqual(file_.size, 38)
def test_last_modified(self) -> None: """Test lastModified.""" temporal = "%s%s" % (config.value("ebcomportamiento/temp_dir"), u"/test_last_modified.txt") contenido = 'QT_TRANSLATE_NOOP("MetaData","Código")' file_ = types.File(temporal) file_.write(contenido) file_.close() self.assertNotEqual(file_.lastModified(), "")
def test_full_name_and_readable(self) -> None: """Check fullName""" temporal = "%s%s" % ( config.value("ebcomportamiento/temp_dir"), u"/test_types_file_full_name.txt", ) contenido = 'QT_TRANSLATE_NOOP("MetaData","Código")' file_ = types.File(temporal) file_.write(contenido) self.assertEqual(file_.fullName, temporal) self.assertTrue(file_.readable())