From 472ef6e287fc73cd9d2c61dff41d1f34d0c031cd Mon Sep 17 00:00:00 2001 From: ddelange <14880945+ddelange@users.noreply.github.com> Date: Thu, 15 Aug 2024 15:42:07 +0300 Subject: [PATCH] Fix zstd compression in ab mode (#833) --- smart_open/tests/test_smart_open.py | 16 ++++++++++++++++ smart_open/utils.py | 2 ++ 2 files changed, 18 insertions(+) diff --git a/smart_open/tests/test_smart_open.py b/smart_open/tests/test_smart_open.py index e31f48b7..789f44c6 100644 --- a/smart_open/tests/test_smart_open.py +++ b/smart_open/tests/test_smart_open.py @@ -607,6 +607,22 @@ def test_atplus(self): self.assertEqual(text, SAMPLE_TEXT * 2) +class CompressionRealFileSystemTests(RealFileSystemTests): + """Same as RealFileSystemTests but with a compressed file.""" + + def setUp(self): + with named_temporary_file(prefix='test', suffix='.zst', delete=False) as fout: + self.temp_file = fout.name + with smart_open.open(self.temp_file, 'wb') as fout: + fout.write(SAMPLE_BYTES) + + def test_aplus(self): + pass # transparent (de)compression unsupported for mode 'ab+' + + def test_atplus(self): + pass # transparent (de)compression unsupported for mode 'ab+' + + # # What exactly to patch here differs on _how_ we're opening the file. # See the _shortcut_open function for details. diff --git a/smart_open/utils.py b/smart_open/utils.py index 2be57d19..c06e2cf0 100644 --- a/smart_open/utils.py +++ b/smart_open/utils.py @@ -208,6 +208,8 @@ def __exit__(self, exc_type, exc_val, exc_tb): class FileLikeProxy(wrapt.ObjectProxy): + __inner = ... # initialized before wrapt disallows __setattr__ on certain objects + def __init__(self, outer, inner): super().__init__(outer) self.__inner = inner