Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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: | |
|
qyearsley
2016/06/15 18:35:38
while -> if
| |
| 61 self.permissions[f] = False | |
| 62 for f in self.files: | |
| 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 18:35:38
If we're changing the public API of the FileSystem
| |
| 82 self.make_executable(file_path) | |
| 83 mode = mode | |
| 84 | |
| 85 def make_executable(self, file_path): | |
| 86 self.permissions[file_path] = True | |
| 87 | |
| 78 def abspath(self, path): | 88 def abspath(self, path): |
| 79 if os.path.isabs(path): | 89 if os.path.isabs(path): |
| 80 return self.normpath(path) | 90 return self.normpath(path) |
| 81 return self.abspath(self.join(self.cwd, path)) | 91 return self.abspath(self.join(self.cwd, path)) |
| 82 | 92 |
| 83 def realpath(self, path): | 93 def realpath(self, path): |
| 84 return self.abspath(path) | 94 return self.abspath(path) |
| 85 | 95 |
| 86 def basename(self, path): | 96 def basename(self, path): |
| 87 return self._split(path)[1] | 97 return self._split(path)[1] |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 490 return self.data.readline(length) | 500 return self.data.readline(length) |
| 491 | 501 |
| 492 def __iter__(self): | 502 def __iter__(self): |
| 493 return self.data.__iter__() | 503 return self.data.__iter__() |
| 494 | 504 |
| 495 def next(self): | 505 def next(self): |
| 496 return self.data.next() | 506 return self.data.next() |
| 497 | 507 |
| 498 def seek(self, offset, whence=os.SEEK_SET): | 508 def seek(self, offset, whence=os.SEEK_SET): |
| 499 self.data.seek(offset, whence) | 509 self.data.seek(offset, whence) |
| OLD | NEW |