Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Test all compression extensions
  • Loading branch information
ddelange committed Aug 27, 2025
commit 9f081b3fc75d8dc39e58c4d980818a6260432be3
41 changes: 25 additions & 16 deletions tests/test_smart_open.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,28 +78,37 @@ def named_temporary_file(mode='w+b', prefix=None, suffix=None, delete=True):
logger.error(e)


def test_zst_write():
with named_temporary_file(suffix=".zst") as tmp:
with smart_open.open(tmp.name, "wt") as fout:
print("hello world", file=fout)
print("this is a test", file=fout)
def test_compression_extensions():
for extension in smart_open.compression.get_supported_extensions():
with named_temporary_file(suffix=extension) as tmp:
with smart_open.open(tmp.name, "wt") as fout:
print("hello world", file=fout)
print("this is a test", file=fout)

with smart_open.open(tmp.name, "rt") as fin:
got = list(fin)
with smart_open.open(tmp.name, "rt") as fin:
got = list(fin)

assert got == ["hello world\n", "this is a test\n"]
assert got == ["hello world\n", "this is a test\n"], f"Error for {extension=}, mode='wt'"

with named_temporary_file(suffix=extension) as tmp:
with smart_open.open(tmp.name, "w") as fout:
fout.write("hello world\n")
fout.write("this is a test\n")

def test_zst_write_binary():
with named_temporary_file(suffix=".zst") as tmp:
with smart_open.open(tmp.name, "wb") as fout:
fout.write(b"hello world\n")
fout.write(b"this is a test\n")
with smart_open.open(tmp.name, "r") as fin:
got = list(fin)

with smart_open.open(tmp.name, "rb") as fin:
got = list(fin)
assert got == ["hello world\n", "this is a test\n"], f"Error for {extension=}, mode='w'"

assert got == [b"hello world\n", b"this is a test\n"]
with named_temporary_file(suffix=extension) as tmp:
with smart_open.open(tmp.name, "wb") as fout:
fout.write(b"hello world\n")
fout.write(b"this is a test\n")

with smart_open.open(tmp.name, "rb") as fin:
got = list(fin)

assert got == [b"hello world\n", b"this is a test\n"], f"Error for {extension=}, mode='wb'"


class ParseUriTest(unittest.TestCase):
Expand Down