Update tests/test_io_utils.py
Run Pytest with Allure and Coverage Reports / tests (push) Failing after 34s
Run Pytest with Allure and Coverage Reports / tests (push) Failing after 34s
This commit is contained in:
@@ -11,24 +11,24 @@ def test_read_file(tmp_path):
|
||||
# Write and read file, normal operation
|
||||
file = tmp_path / "test.txt"
|
||||
file.write_text("hello")
|
||||
content = io_utils.read_file(str(file))
|
||||
content = read_file(str(file))
|
||||
assert content == "hello"
|
||||
|
||||
def test_write_file(tmp_path):
|
||||
# Write content to file and verify write success
|
||||
file = tmp_path / "test_write.txt"
|
||||
io_utils.write_file(str(file), "data")
|
||||
write_file(str(file), "data")
|
||||
assert file.read_text() == "data"
|
||||
|
||||
def test_cause_io_error():
|
||||
# Raises manual IOError to simulate IO failure
|
||||
with pytest.raises(IOError):
|
||||
io_utils.cause_io_error()
|
||||
cause_io_error()
|
||||
|
||||
def test_file_not_found():
|
||||
# Reading non-existing file raises FileNotFoundError
|
||||
with pytest.raises(FileNotFoundError):
|
||||
io_utils.read_file("nonexistent.file")
|
||||
read_file("nonexistent.file")
|
||||
|
||||
def test_permission_error(monkeypatch):
|
||||
# Patch open to raise PermissionError simulating access denial
|
||||
@@ -36,7 +36,7 @@ def test_permission_error(monkeypatch):
|
||||
raise PermissionError("Permission denied")
|
||||
monkeypatch.setattr("builtins.open", raise_perm_error)
|
||||
with pytest.raises(PermissionError):
|
||||
io_utils.read_file("anyfile.txt")
|
||||
read_file("anyfile.txt")
|
||||
|
||||
def test_mock_open_error(monkeypatch):
|
||||
# Mock open() to raise IOError simulating read error
|
||||
|
||||
Reference in New Issue
Block a user