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

Side by Side Diff: tests/filesystem_mock.py

Issue 6690034: Add more python 2.5 compatibility. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Don't force python 2.5 anymore (to be done in a separate change) Created 9 years, 8 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 | Annotate | Revision Log
OLDNEW
1 #!/usr/bin/python
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 3 # found in the LICENSE file.
5 4
6 import errno 5 import errno
7 import os 6 import os
8 import re 7 import re
9 import StringIO 8 import StringIO
10 9
10
11 def _RaiseNotFound(path): 11 def _RaiseNotFound(path):
12 raise IOError(errno.ENOENT, path, os.strerror(errno.ENOENT)) 12 raise IOError(errno.ENOENT, path, os.strerror(errno.ENOENT))
13 13
14 14
15 class MockFileSystem(object): 15 class MockFileSystem(object):
16 """Stripped-down version of WebKit's webkitpy.common.system.filesystem_mock 16 """Stripped-down version of WebKit's webkitpy.common.system.filesystem_mock
17 17
18 Implements a filesystem-like interface on top of a dict of filenames -> 18 Implements a filesystem-like interface on top of a dict of filenames ->
19 file contents. A file content value of None indicates that the file should 19 file contents. A file content value of None indicates that the file should
20 not exist (IOError will be raised if it is opened; 20 not exist (IOError will be raised if it is opened;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 return re.sub(re.escape(os.path.sep), self.sep, os.path.join(*comps)) 66 return re.sub(re.escape(os.path.sep), self.sep, os.path.join(*comps))
67 67
68 def open_for_reading(self, path): 68 def open_for_reading(self, path):
69 return StringIO.StringIO(self.read_binary_file(path)) 69 return StringIO.StringIO(self.read_binary_file(path))
70 70
71 def read_binary_file(self, path): 71 def read_binary_file(self, path):
72 # Intentionally raises KeyError if we don't recognize the path. 72 # Intentionally raises KeyError if we don't recognize the path.
73 if self.files[path] is None: 73 if self.files[path] is None:
74 _RaiseNotFound(path) 74 _RaiseNotFound(path)
75 return self.files[path] 75 return self.files[path]
OLDNEW
« no previous file with comments | « tests/fake_repos.py ('k') | tests/fix_encoding_test.py » ('j') | tests/owners_unittest.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698