From bf6b9d06ca1491fa7fd4247f1f0ac7ea239fb8ab Mon Sep 17 00:00:00 2001 From: tligui_y Date: Tue, 15 Jul 2025 10:49:34 +0200 Subject: [PATCH] Update tests/test_io_utils.py --- tests/test_io_utils.py | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/tests/test_io_utils.py b/tests/test_io_utils.py index d144ee3c7..905b4cb73 100644 --- a/tests/test_io_utils.py +++ b/tests/test_io_utils.py @@ -22,56 +22,48 @@ def test_write_file(tmp_path): def test_cause_io_error(): # Raises manual IOError to simulate IO failure - with pytest.raises(IOError): - cause_io_error() + cause_io_error() def test_file_not_found(): # Reading non-existing file raises FileNotFoundError - with pytest.raises(FileNotFoundError): - read_file("nonexistent.file") + read_file("nonexistent.file") def test_permission_error(monkeypatch): # Patch open to raise PermissionError simulating access denial def raise_perm_error(*args, **kwargs): raise PermissionError("Permission denied") monkeypatch.setattr("builtins.open", raise_perm_error) - with pytest.raises(PermissionError): - read_file("anyfile.txt") + read_file("anyfile.txt") def test_mock_open_error(monkeypatch): # Mock open() to raise IOError simulating read error mocked_open = mock.mock_open() mocked_open.side_effect = IOError("Mocked IOError") monkeypatch.setattr("builtins.open", mocked_open) - with pytest.raises(IOError): - with open("file.txt", "r") as f: - f.read() + with open("file.txt", "r") as f: + f.read() def test_file_handle_closed_error(): # Accessing closed file raises ValueError f = io.StringIO("content") f.close() - with pytest.raises(ValueError): - f.read() + f.read() def test_os_error(monkeypatch): # Patch os.remove to raise OSError simulating filesystem error def raise_os_error(path): raise OSError("Simulated OSError") monkeypatch.setattr("os.remove", raise_os_error) - with pytest.raises(OSError): - os.remove("file.txt") + os.remove("file.txt") def test_write_file_readonly(tmp_path): # Writing to read-only file raises PermissionError file = tmp_path / "readonly.txt" file.write_text("data") os.chmod(file, 0o444) - with pytest.raises(PermissionError): - with open(file, "w") as f: - f.write("new content") + with open(file, "w") as f: + f.write("new content") def test_file_not_found_error(): # Raises FileNotFoundError when opening a non-existent file - with pytest.raises(FileNotFoundError): - open("no_such_file.txt", "r") + open("no_such_file.txt", "r") \ No newline at end of file