Skip to content

Commit

Permalink
s3: Failing test for universal newline handling
Browse files Browse the repository at this point in the history
  • Loading branch information
craigds committed Feb 13, 2024
1 parent d16c486 commit 795c82f
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion tests/test_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,25 @@ def test_storage_open_read_string(self):
self.assertEqual(content_str, "")
file.close()

def test_storage_open_read_with_newlines(self):
"""
Test opening a file in "r" mode with various newline characters
"""
name = "test_storage_open_read_with_newlines.txt"
with io.BytesIO() as temp_file:
temp_file.write(b"line1\nline2\r\nmore\rtext\n")
temp_file.seek(0)
file = self.storage.open(name, "r")
file._file = temp_file
content_str = file.read()
file.close()
self.assertEqual(content_str, "line1\nline2\nmore\ntext\n")

def test_storage_open_readlines(self):
"""
Test readlines with file opened in "r" and "rb" modes
"""
name = "test_open_readlines_string.txt"
name = "test_storage_open_readlines.txt"
with io.BytesIO() as temp_file:
temp_file.write(b"line1\nline2")
file = self.storage.open(name, "r")
Expand All @@ -324,6 +338,19 @@ def test_storage_open_readlines(self):
content_lines = file.readlines()
self.assertEqual(content_lines, [b"line1\n", b"line2"])

def test_storage_open_readlines_with_newlines(self):
"""
Test readlines with file opened in "r" mode with various newline characters
"""
name = "test_storage_open_readlines_with_newlines.txt"
with io.BytesIO() as temp_file:
temp_file.write(b"line1\nline2\r\nmore\rtext")
file = self.storage.open(name, "r")
file._file = temp_file

content_lines = file.readlines()
self.assertEqual(content_lines, ['line1\n', 'line2\n', 'more\n', 'text'])

def test_storage_open_write(self):
"""
Test opening a file in write mode
Expand Down

0 comments on commit 795c82f

Please sign in to comment.