Changeset 83631 in webkit
- Timestamp:
- Apr 12, 2011 1:34:45 PM (13 years ago)
- Location:
- trunk/Tools
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Tools/ChangeLog
r83628 r83631 1 2011-04-12 Dirk Pranke <dpranke@chromium.org> 2 3 Reviewed by Eric Seidel. 4 5 webkitpy: fix mock_filesystem abspath to handle relative paths 6 and add filesystem.chdir() and filesystem.getcwd() to be able 7 to test this and mock it out. 8 9 https://bugs.webkit.org/show_bug.cgi?id=58288 10 11 * Scripts/webkitpy/common/system/filesystem.py: 12 * Scripts/webkitpy/common/system/filesystem_mock.py: 13 * Scripts/webkitpy/common/system/filesystem_unittest.py: 14 1 15 2011-04-12 Alice Liu <alice.liu@apple.com> 2 16 -
trunk/Tools/Scripts/webkitpy/common/system/filesystem.py
r82279 r83631 62 62 return os.path.basename(path) 63 63 64 def chdir(self, path): 65 """Wraps os.chdir().""" 66 return os.chdir(path) 67 64 68 def copyfile(self, source, destination): 65 69 """Copies the contents of the file at the given path to the destination … … 108 112 files.append(self.join(dirpath, filename)) 109 113 return files 114 115 def getcwd(self): 116 """Wraps os.getcwd().""" 117 return os.getcwd() 110 118 111 119 def glob(self, path): -
trunk/Tools/Scripts/webkitpy/common/system/filesystem_mock.py
r82972 r83631 36 36 37 37 class MockFileSystem(object): 38 def __init__(self, files=None ):38 def __init__(self, files=None, cwd='/'): 39 39 """Initializes a "mock" filesystem that can be used to completely 40 40 stub out a filesystem. … … 49 49 self._sep = '/' 50 50 self.current_tmpno = 0 51 self.cwd = cwd 52 self.dirs = {} 51 53 52 54 def _get_sep(self): … … 62 64 63 65 def abspath(self, path): 64 if path. endswith(self.sep):65 return path[:-1]66 return path66 if path.startswith(self.sep): 67 return self.normpath(path) 68 return self.abspath(self.join(self.cwd, path)) 67 69 68 70 def basename(self, path): 69 71 return self._split(path)[1] 72 73 def chdir(self, path): 74 path = self.normpath(path) 75 if not self.isdir(path): 76 raise OSError(errno.ENOENT, path, os.strerror(errno.ENOENT)) 77 self.cwd = path 70 78 71 79 def copyfile(self, source, destination): … … 118 126 return files 119 127 128 def getcwd(self, path): 129 return self.cwd 130 120 131 def glob(self, path): 121 132 # FIXME: This only handles a wildcard '*' at the end of the path. … … 135 146 if path in self.files: 136 147 return False 137 if not path.endswith(self.sep): 138 path += self.sep 148 path = self.normpath(path) 149 if path in self.dirs: 150 return True 139 151 140 152 # We need to use a copy of the keys here in order to avoid switching … … 142 154 # mid-iteration. 143 155 files = self.files.keys()[:] 144 return any(f.startswith(path) for f in files) 156 result = any(f.startswith(path) for f in files) 157 if result: 158 self.dirs[path] = True 159 return result 145 160 146 161 def join(self, *comps): … … 205 220 206 221 def maybe_make_directory(self, *path): 207 # FIXME: Implement such that subsequent calls to isdir() work? 208 pass 222 norm_path = self.normpath(self.join(*path)) 223 if not self.isdir(norm_path): 224 self.dirs[norm_path] = True 209 225 210 226 def move(self, source, destination): -
trunk/Tools/Scripts/webkitpy/common/system/filesystem_unittest.py
r77093 r83631 49 49 self._this_file = os.path.join(self._this_dir, 'filesystem_unittest.py') 50 50 51 def test_chdir(self): 52 fs = FileSystem() 53 cwd = fs.getcwd() 54 newdir = '/' 55 if sys.platform == 'win32': 56 newdir = 'c:\\' 57 fs.chdir(newdir) 58 self.assertEquals(fs.getcwd(), newdir) 59 fs.chdir(cwd) 60 61 def test_chdir__notexists(self): 62 fs = FileSystem() 63 newdir = '/dirdoesnotexist' 64 if sys.platform == 'win32': 65 newdir = 'c:\\dirdoesnotexist' 66 self.assertRaises(OSError, fs.chdir, newdir) 67 51 68 def test_exists__true(self): 52 69 fs = FileSystem() … … 56 73 fs = FileSystem() 57 74 self.assertFalse(fs.exists(self._missing_file)) 75 76 def test_getcwd(self): 77 fs = FileSystem() 78 self.assertTrue(fs.exists(fs.getcwd())) 58 79 59 80 def test_isdir__true(self):
Note: See TracChangeset
for help on using the changeset viewer.