From 7611d36a7bfe91f57b77de305cd4ab28f7519156 Mon Sep 17 00:00:00 2001 From: ddelange <14880945+ddelange@users.noreply.github.com> Date: Thu, 15 Aug 2024 08:11:50 +0200 Subject: [PATCH] Fix zstd compression in ab mode --- smart_open/tests/test_smart_open.py | 14 ++++++++++++++ smart_open/utils.py | 2 ++ 2 files changed, 16 insertions(+) diff --git a/smart_open/tests/test_smart_open.py b/smart_open/tests/test_smart_open.py index e31f48b7..20c67a62 100644 --- a/smart_open/tests/test_smart_open.py +++ b/smart_open/tests/test_smart_open.py @@ -607,6 +607,20 @@ 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