Skip to content

Commit

Permalink
guard warning filter with context manager
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielYang59 committed Sep 19, 2024
1 parent e1786ef commit f90074c
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,13 @@ def test_read_file_with_empty_lines(self, l_end, ram):
"""Empty lines should not be skipped.
Using a very small RAM size to force non in-RAM mode.
"""
warnings.filterwarnings(
"ignore", message="max_mem=4 smaller than blk_size=4096"
)

contents = (f"line1{l_end}", f"{l_end}", f"line3{l_end}")
filename = "test_empty_line.txt"

with ScratchDir("."):
with ScratchDir("."), warnings.catch_warnings():
warnings.filterwarnings(
"ignore", message="max_mem=4 smaller than blk_size=4096"
)
# Test text file
with open(filename, "wb") as file:
for line in contents:
Expand Down Expand Up @@ -244,14 +243,14 @@ def test_read_file_with_empty_lines(self, l_end, ram):
@pytest.mark.parametrize("l_end", ["\n", "\r\n"])
def test_different_line_endings(self, l_end, ram):
"""Using a very small RAM size to force non in-RAM mode."""
warnings.filterwarnings(
"ignore", message="max_mem=4 smaller than blk_size=4096"
)

contents = (f"Line1{l_end}", f"Line2{l_end}", f"Line3{l_end}")
file_name = "test_file.txt"

with ScratchDir("."):
with ScratchDir("."), warnings.catch_warnings():
warnings.filterwarnings(
"ignore", message="max_mem=4 smaller than blk_size=4096"
)

with open(file_name, "wb") as file:
for line in contents:
file.write(line.encode())
Expand Down

0 comments on commit f90074c

Please sign in to comment.