Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(320)

Side by Side Diff: third_party/WebKit/Tools/Scripts/webkitpy/common/system/filesystem_mock.py

Issue 2066963002: Add file permissions to filesystem_mock (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Corrected make_executable and is_executable locations Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright (C) 2009 Google Inc. All rights reserved. 1 # Copyright (C) 2009 Google Inc. All rights reserved.
2 # 2 #
3 # Redistribution and use in source and binary forms, with or without 3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are 4 # modification, are permitted provided that the following conditions are
5 # met: 5 # met:
6 # 6 #
7 # * Redistributions of source code must retain the above copyright 7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer. 8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above 9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer 10 # copyright notice, this list of conditions and the following disclaimer
(...skipping 21 matching lines...) Expand all
32 import os 32 import os
33 import re 33 import re
34 34
35 from webkitpy.common.system import path 35 from webkitpy.common.system import path
36 36
37 37
38 class MockFileSystem(object): 38 class MockFileSystem(object):
39 sep = '/' 39 sep = '/'
40 pardir = '..' 40 pardir = '..'
41 41
42 def __init__(self, files=None, dirs=None, cwd='/'): 42 def __init__(self, files=None, dirs=None, cwd='/', permissions=None):
43 """Initializes a "mock" filesystem that can be used to completely 43 """Initializes a "mock" filesystem that can be used to completely
44 stub out a filesystem. 44 stub out a filesystem.
45 45
46 Args: 46 Args:
47 files: a dict of filenames -> file contents. A file contents 47 files: a dict of filenames -> file contents. A file contents
48 value of None is used to indicate that the file should 48 value of None is used to indicate that the file should
49 not exist. 49 not exist.
50 """ 50 """
51 self.files = files or {} 51 self.files = files or {}
52 self.permissions = permissions or {}
52 self.written_files = {} 53 self.written_files = {}
53 self.last_tmpdir = None 54 self.last_tmpdir = None
54 self.current_tmpno = 0 55 self.current_tmpno = 0
55 self.cwd = cwd 56 self.cwd = cwd
56 self.dirs = set(dirs or []) 57 self.dirs = set(dirs or [])
57 self.dirs.add(cwd) 58 self.dirs.add(cwd)
58 for f in self.files: 59 for f in self.files:
60 while f not in self.permissions:
61 self.permissions[f] = False
62 for f in self.files:
qyearsley 2016/06/15 21:54:25 Depending on how is_executable is implemented, thi
59 d = self.dirname(f) 63 d = self.dirname(f)
60 while not d in self.dirs: 64 while not d in self.dirs:
61 self.dirs.add(d) 65 self.dirs.add(d)
62 d = self.dirname(d) 66 d = self.dirname(d)
63
64 def clear_written_files(self): 67 def clear_written_files(self):
65 # This function can be used to track what is written between steps in a test. 68 # This function can be used to track what is written between steps in a test.
66 self.written_files = {} 69 self.written_files = {}
67 70
68 def _raise_not_found(self, path): 71 def _raise_not_found(self, path):
69 raise IOError(errno.ENOENT, path, os.strerror(errno.ENOENT)) 72 raise IOError(errno.ENOENT, path, os.strerror(errno.ENOENT))
70 73
71 def _split(self, path): 74 def _split(self, path):
72 # This is not quite a full implementation of os.path.split 75 # This is not quite a full implementation of os.path.split
73 # http://docs.python.org/library/os.path.html#os.path.split 76 # http://docs.python.org/library/os.path.html#os.path.split
74 if self.sep in path: 77 if self.sep in path:
75 return path.rsplit(self.sep, 1) 78 return path.rsplit(self.sep, 1)
76 return ('', path) 79 return ('', path)
77 80
81 def chmod(self, file_path, mode):
qyearsley 2016/06/15 21:54:25 In the MockFileSystem class, we still want to have
82 # To be used to fix http://crbug.com/574461
qyearsley 2016/06/15 21:54:25 This kind of thing might be more useful to put in
83 self.permissions[file_path] = True
84 mode = mode
qyearsley 2016/06/15 21:54:25 Note, this statement does nothing.
85
78 def abspath(self, path): 86 def abspath(self, path):
79 if os.path.isabs(path): 87 if os.path.isabs(path):
80 return self.normpath(path) 88 return self.normpath(path)
81 return self.abspath(self.join(self.cwd, path)) 89 return self.abspath(self.join(self.cwd, path))
82 90
83 def realpath(self, path): 91 def realpath(self, path):
84 return self.abspath(path) 92 return self.abspath(path)
85 93
86 def basename(self, path): 94 def basename(self, path):
87 return self._split(path)[1] 95 return self._split(path)[1]
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 return self.data.readline(length) 498 return self.data.readline(length)
491 499
492 def __iter__(self): 500 def __iter__(self):
493 return self.data.__iter__() 501 return self.data.__iter__()
494 502
495 def next(self): 503 def next(self):
496 return self.data.next() 504 return self.data.next()
497 505
498 def seek(self, offset, whence=os.SEEK_SET): 506 def seek(self, offset, whence=os.SEEK_SET):
499 self.data.seek(offset, whence) 507 self.data.seek(offset, whence)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698