@@ -269,7 +269,9 @@ def __init__(self, name, st_mode=S_IFREG | PERM_DEF_FILE,
269269 Args:
270270 name: Name of the file/directory, without parent path information
271271 st_mode: The stat.S_IF* constant representing the file type (i.e.
272- stat.S_IFREG, stat.S_IFDIR)
272+ stat.S_IFREG, stat.S_IFDIR), and the file permissions.
273+ If no file type is set (e.g. permission flags only), a
274+ regular file type is assumed.
273275 contents: The contents of the filesystem object; should be a string
274276 or byte object for regular files, and a list of other
275277 FakeFile or FakeDirectory objects for FakeDirectory objects
@@ -288,6 +290,8 @@ def __init__(self, name, st_mode=S_IFREG | PERM_DEF_FILE,
288290 self .name = name
289291 self .stat_result = FakeStatResult (
290292 filesystem .is_windows_fs , USER_ID , GROUP_ID , time .time ())
293+ if st_mode >> 12 == 0 :
294+ st_mode |= S_IFREG
291295 self .stat_result .st_mode = st_mode
292296 self .encoding = encoding
293297 self .errors = errors or 'strict'
@@ -2906,14 +2910,17 @@ def makedirs(self, dir_name, mode=PERM_DEF, exist_ok=False):
29062910 e .errno = errno .ENOENT
29072911 self .raise_os_error (e .errno , e .filename )
29082912
2909- def _is_of_type (self , path , st_flag , follow_symlinks = True ):
2913+ def _is_of_type (self , path , st_flag , follow_symlinks = True ,
2914+ check_read_perm = True ):
29102915 """Helper function to implement isdir(), islink(), etc.
29112916
29122917 See the stat(2) man page for valid stat.S_I* flag values
29132918
29142919 Args:
29152920 path: Path to file to stat and test
29162921 st_flag: The stat.S_I* flag checked for the file's st_mode
2922+ check_read_perm: If True (default) False is returned for
2923+ existing but unreadable file paths.
29172924
29182925 Returns:
29192926 (boolean) `True` if the st_flag is set in path's st_mode.
@@ -2925,7 +2932,8 @@ def _is_of_type(self, path, st_flag, follow_symlinks=True):
29252932 if path is None :
29262933 raise TypeError
29272934 try :
2928- obj = self .resolve (path , follow_symlinks )
2935+ obj = self .resolve (path , follow_symlinks ,
2936+ check_read_perm = check_read_perm )
29292937 if obj :
29302938 self .raise_for_filepath_ending_with_separator (
29312939 path , obj , macos_handling = not follow_symlinks )
@@ -2960,7 +2968,8 @@ def isfile(self, path, follow_symlinks=True):
29602968 Raises:
29612969 TypeError: if path is None.
29622970 """
2963- return self ._is_of_type (path , S_IFREG , follow_symlinks )
2971+ return self ._is_of_type (path , S_IFREG , follow_symlinks ,
2972+ check_read_perm = False )
29642973
29652974 def islink (self , path ):
29662975 """Determine if path identifies a symbolic link.
0 commit comments