From 47e81f773aba55d5af9b6e6ba78720cbe4868297 Mon Sep 17 00:00:00 2001 From: ampli Date: Sun, 19 May 2024 01:23:16 +0300 Subject: [PATCH] tests.py: divert_end(): Read the entire output Reading a fixed amount of bytes may truncate a utf8 character, leading to Python errors. Encountered on MacOS in the test_tahi test. --- bindings/python-examples/tests.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bindings/python-examples/tests.py b/bindings/python-examples/tests.py index cc9ab441d..10531c30d 100755 --- a/bindings/python-examples/tests.py +++ b/bindings/python-examples/tests.py @@ -1512,7 +1512,8 @@ def divert_end(self): if not self.filename: return "" os.lseek(self.fd, os.SEEK_SET, 0) - content = os.read(self.fd, 1024) # 1024 is more than needed + with os.fdopen(self.fd, 'rb') as file: + content = file.read() os.dup2(self.savedfd, self.fd) os.close(self.savedfd) os.unlink(self.filename)