Skip to content

Commit 8efbd4d

Browse files
committed
V5.0.1
1 parent 1e543ce commit 8efbd4d

File tree

1 file changed

+34
-22
lines changed

1 file changed

+34
-22
lines changed

tests/core/test_log_utils.py

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -42,30 +42,42 @@ def test_check_filename_instance(self):
4242
assert "Unable to parse filenames" in str(exec_info.value)
4343

4444
def test_check_directory_permissions(self):
45-
# Test permission error on access
46-
directory = os.path.join(tempfile.gettempdir(), "test_permission")
47-
os.makedirs(directory, mode=0o000, exist_ok=True) # No permissions at all
48-
assert os.path.exists(directory) == True
49-
with pytest.raises(PermissionError) as exec_info:
50-
log_utils.check_directory_permissions(directory)
51-
os.chmod(directory, 0o755) # Restore permissions for cleanup
52-
assert type(exec_info.value) is PermissionError
53-
assert "Unable to access directory" in str(exec_info.value)
54-
log_utils.delete_file(directory)
55-
assert os.path.exists(directory) == False
56-
57-
# test permission error on creation - use a readonly parent directory
58-
with tempfile.TemporaryDirectory() as temp_dir:
59-
readonly_parent = os.path.join(temp_dir, "readonly")
60-
os.makedirs(readonly_parent, mode=0o555) # Read-only parent
61-
try:
62-
non_existent = os.path.join(readonly_parent, "non-existent-directory")
45+
import sys
46+
47+
if sys.platform == "win32":
48+
# On Windows, use a non-existent drive to simulate permission error
49+
invalid_path = "Z:\\nonexistent\\directory"
50+
if not os.path.exists("Z:\\"):
6351
with pytest.raises(PermissionError) as exec_info:
64-
log_utils.check_directory_permissions(non_existent)
65-
assert type(exec_info.value) is PermissionError
52+
log_utils.check_directory_permissions(invalid_path)
6653
assert "Unable to create directory" in str(exec_info.value)
67-
finally:
68-
os.chmod(readonly_parent, 0o755) # Restore permissions for cleanup
54+
else:
55+
pytest.skip("Z: drive exists, cannot test permission error")
56+
else:
57+
# Unix-style permission testing
58+
directory = os.path.join(tempfile.gettempdir(), "test_permission")
59+
os.makedirs(directory, mode=0o000, exist_ok=True) # No permissions at all
60+
assert os.path.exists(directory) == True
61+
with pytest.raises(PermissionError) as exec_info:
62+
log_utils.check_directory_permissions(directory)
63+
os.chmod(directory, 0o755) # Restore permissions for cleanup
64+
assert type(exec_info.value) is PermissionError
65+
assert "Unable to access directory" in str(exec_info.value)
66+
log_utils.delete_file(directory)
67+
assert os.path.exists(directory) == False
68+
69+
# test permission error on creation - use a readonly parent directory
70+
with tempfile.TemporaryDirectory() as temp_dir:
71+
readonly_parent = os.path.join(temp_dir, "readonly")
72+
os.makedirs(readonly_parent, mode=0o555) # Read-only parent
73+
try:
74+
non_existent = os.path.join(readonly_parent, "non-existent-directory")
75+
with pytest.raises(PermissionError) as exec_info:
76+
log_utils.check_directory_permissions(non_existent)
77+
assert type(exec_info.value) is PermissionError
78+
assert "Unable to create directory" in str(exec_info.value)
79+
finally:
80+
os.chmod(readonly_parent, 0o755) # Restore permissions for cleanup
6981

7082
def test_remove_old_logs(self):
7183
directory = os.path.join(tempfile.gettempdir(), "test_remove_logs")

0 commit comments

Comments
 (0)