@@ -366,7 +366,7 @@ def test_check_directory_permissions(self):
366366 # Clean up any existing directory first
367367 if os .path .exists (directory ):
368368 try :
369- os .chmod (directory , stat . S_IRWXU | stat . S_IRGRP | stat . S_IXGRP | stat . S_IROTH | stat . S_IXOTH )
369+ os .chmod (directory , 0o755 )
370370 log_utils .delete_file (directory )
371371 except (OSError , PermissionError ):
372372 pass # Continue if cleanup fails
@@ -382,7 +382,7 @@ def test_check_directory_permissions(self):
382382 # Always restore permissions for cleanup, even if test fails
383383 if os .path .exists (directory ):
384384 try :
385- os .chmod (directory , stat . S_IRWXU | stat . S_IRGRP | stat . S_IXGRP | stat . S_IROTH | stat . S_IXOTH )
385+ os .chmod (directory , 0o755 )
386386 log_utils .delete_file (directory )
387387 except (OSError , PermissionError ):
388388 pass # Ignore cleanup errors
@@ -392,21 +392,21 @@ def test_check_directory_permissions(self):
392392 # test permission error on creation - use a readonly parent directory
393393 with tempfile .TemporaryDirectory () as temp_dir :
394394 readonly_parent = os .path .join (temp_dir , "readonly" )
395- # Read-only parent 0o555
396- os .makedirs (readonly_parent , mode = stat . S_IRUSR | stat . S_IXUSR | stat . S_IRGRP | stat . S_IXGRP | stat . S_IROTH | stat . S_IXOTH )
395+ # Read-only parent
396+ os .makedirs (readonly_parent , mode = 0o555 )
397397 try :
398398 non_existent = os .path .join (readonly_parent , "non-existent-directory" )
399399 with pytest .raises (PermissionError ) as exec_info :
400400 log_utils .check_directory_permissions (non_existent )
401401 assert type (exec_info .value ) is PermissionError
402402 assert "Unable to create directory" in str (exec_info .value )
403403 finally :
404- # Restore permissions for cleanup 0o755
405- os .chmod (readonly_parent , stat . S_IRWXU | stat . S_IRGRP | stat . S_IXGRP | stat . S_IROTH | stat . S_IXOTH )
404+ # Restore permissions for cleanup
405+ os .chmod (readonly_parent , 0o755 )
406406
407407 def test_remove_old_logs (self ):
408408 directory = os .path .join (tempfile .gettempdir (), "test_remove_logs" )
409- os .makedirs (directory , mode = stat . S_IRWXU | stat . S_IRGRP | stat . S_IXGRP | stat . S_IROTH | stat . S_IXOTH , exist_ok = True )
409+ os .makedirs (directory , mode = 0o755 , exist_ok = True )
410410 assert os .path .exists (directory ) == True
411411
412412 # Create a file and manually set its modification time to be old
@@ -494,15 +494,14 @@ def test_get_log_path(self):
494494 # This test only works on Unix/Linux/macOS systems with chmod
495495 if sys .platform != "win32" :
496496 readonly_dir = os .path .join (temp_dir , "readonly" )
497- # 0o555
498- os .makedirs (readonly_dir , mode = stat .S_IRUSR | stat .S_IXUSR | stat .S_IRGRP | stat .S_IXGRP | stat .S_IROTH | stat .S_IXOTH )
497+ os .makedirs (readonly_dir , mode = 0o555 )
499498 try :
500499 with pytest .raises (PermissionError ) as exc_info :
501500 log_utils .get_log_path (readonly_dir , test_file )
502501 assert "Unable to access directory" in str (exc_info .value )
503502 finally :
504- # Cleanup permissions 0o755
505- os .chmod (readonly_dir , stat . S_IRWXU | stat . S_IRGRP | stat . S_IXGRP | stat . S_IROTH | stat . S_IXOTH )
503+ # Cleanup permissions
504+ os .chmod (readonly_dir , 0o755 )
506505 os .rmdir (readonly_dir )
507506
508507 def test_get_format (self ):
@@ -843,8 +842,8 @@ def test_remove_old_logs_file_error(self):
843842 old_time = time .time () - 2 * 24 * 60 * 60 # 2 days old
844843 os .utime (gz_file , (old_time , old_time ))
845844
846- # Make parent directory read-only to trigger deletion error 0o555
847- os .chmod (temp_dir , stat . S_IRUSR | stat . S_IXUSR | stat . S_IRGRP | stat . S_IXGRP | stat . S_IROTH | stat . S_IXOTH )
845+ # Make parent directory read-only to trigger deletion error
846+ os .chmod (temp_dir , 0o555 )
848847
849848 try :
850849 # Capture stderr to verify error was logged
@@ -856,8 +855,8 @@ def test_remove_old_logs_file_error(self):
856855 output = stderr_capture .getvalue ()
857856 assert "Unable to delete old log" in output
858857 finally :
859- # Restore permissions for cleanup 0o755
860- os .chmod (temp_dir , stat . S_IRWXU | stat . S_IRGRP | stat . S_IXGRP | stat . S_IROTH | stat . S_IXOTH )
858+ # Restore permissions for cleanup
859+ os .chmod (temp_dir , 0o755 )
861860
862861 def test_remove_old_logs_directory_error (self ):
863862 """Test remove_old_logs error handling when directory scan fails"""
@@ -915,8 +914,8 @@ def test_get_log_path_permission_error(self):
915914 # Create a subdirectory and make it read-only
916915 readonly_dir = os .path .join (temp_dir , "readonly" )
917916 os .makedirs (readonly_dir )
918- # Read and execute only 0o555
919- os .chmod (readonly_dir , stat . S_IRUSR | stat . S_IXUSR | stat . S_IRGRP | stat . S_IXGRP | stat . S_IROTH | stat . S_IXOTH )
917+ # Read and execute only
918+ os .chmod (readonly_dir , 0o555 )
920919
921920 try :
922921 with pytest .raises (PermissionError ) as exc_info :
@@ -925,8 +924,8 @@ def test_get_log_path_permission_error(self):
925924 assert ("Unable to access directory" in str (exc_info .value ) or
926925 "Unable to write to log directory" in str (exc_info .value ))
927926 finally :
928- # Restore for cleanup 0o755
929- os .chmod (readonly_dir , stat . S_IRWXU | stat . S_IRGRP | stat . S_IXGRP | stat . S_IROTH | stat . S_IXOTH )
927+ # Restore for cleanup
928+ os .chmod (readonly_dir , 0o755 )
930929
931930 @pytest .mark .skipif (sys .platform == "win32" , reason = "Unix/Linux/macOS-specific chmod test" )
932931 def test_gzip_file_io_error (self ):
@@ -937,8 +936,8 @@ def test_gzip_file_io_error(self):
937936 with open (test_file , "w" ) as f :
938937 f .write ("test content" )
939938
940- # Make directory read-only to trigger gzip error 0o555
941- os .chmod (temp_dir , stat . S_IRUSR | stat . S_IXUSR | stat . S_IRGRP | stat . S_IXGRP | stat . S_IROTH | stat . S_IXOTH )
939+ # Make directory read-only to trigger gzip error
940+ os .chmod (temp_dir , 0o555 )
942941
943942 try :
944943 stderr_capture = io .StringIO ()
@@ -949,8 +948,8 @@ def test_gzip_file_io_error(self):
949948 output = stderr_capture .getvalue ()
950949 assert "Unable to gzip log file" in output
951950 finally :
952- # Restore for cleanup 0o755
953- os .chmod (temp_dir , stat . S_IRWXU | stat . S_IRGRP | stat . S_IXGRP | stat . S_IROTH | stat . S_IXOTH )
951+ # Restore for cleanup
952+ os .chmod (temp_dir , 0o755 )
954953
955954 @pytest .mark .skipif (sys .platform == "win32" , reason = "Unix/Linux/macOS-specific chmod test" )
956955 def test_gzip_file_deletion_error (self ):
@@ -1403,8 +1402,8 @@ def test_get_log_path_write_permission_error(self):
14031402 # Add to cache first to bypass check_directory_permissions
14041403 log_utils ._checked_directories .add (test_dir )
14051404
1406- # Make directory non-writable, Read and execute only 0o555
1407- os .chmod (test_dir , stat . S_IRUSR | stat . S_IXUSR | stat . S_IRGRP | stat . S_IXGRP | stat . S_IROTH | stat . S_IXOTH )
1405+ # Make directory non-writable, Read and execute only
1406+ os .chmod (test_dir , 0o555 )
14081407
14091408 try :
14101409 with pytest .raises (PermissionError ) as exc_info :
@@ -1415,7 +1414,7 @@ def test_get_log_path_write_permission_error(self):
14151414
14161415 finally :
14171416 # Restore for cleanup 0o755
1418- os .chmod (test_dir , stat . S_IRWXU | stat . S_IRGRP | stat . S_IXGRP | stat . S_IROTH | stat . S_IXOTH )
1417+ os .chmod (test_dir , 0o755 )
14191418 log_utils ._checked_directories .discard (test_dir )
14201419
14211420 def test_timezone_offset_fallback_exception (self ):
0 commit comments