From 667be49c1cacdeb0fb5ab2fda60967ada28cf402 Mon Sep 17 00:00:00 2001 From: Jan Zerebecki Date: Wed, 9 Aug 2017 11:42:12 +0000 Subject: [PATCH] Fix byte vs string file io for python 3 Reference: https://github.com/avocado-framework/avocado/issues/2024 Signed-off-by: Jan Zerebecki --- selftests/unit/test_archive.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/selftests/unit/test_archive.py b/selftests/unit/test_archive.py index 8b82a2fb..2e1bd098 100644 --- a/selftests/unit/test_archive.py +++ b/selftests/unit/test_archive.py @@ -27,7 +27,8 @@ class ArchiveTest(unittest.TestCase): compressdir = self.compressdir str_length = self.sys_random.randint(30, 50) fd, filename = tempfile.mkstemp(dir=compressdir, text=True) - os.write(fd, data_factory.generate_random_string(str_length)) + with os.fdopen(fd, 'w') as f: + f.write(data_factory.generate_random_string(str_length)) relative_path = filename.replace(self.compressdir, '') hash_map_1[relative_path] = crypto.hash_file(filename) @@ -47,7 +48,8 @@ class ArchiveTest(unittest.TestCase): def compress_and_check_file(self, extension): str_length = self.sys_random.randint(30, 50) fd, filename = tempfile.mkstemp(dir=self.basedir, text=True) - os.write(fd, data_factory.generate_random_string(str_length)) + with os.fdopen(fd, 'w') as f: + f.write(data_factory.generate_random_string(str_length)) original_hash = crypto.hash_file(filename) dstfile = filename + extension archive_filename = os.path.join(self.basedir, dstfile) -- GitLab