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

Unified Diff: tests/filesystem_mock.py

Issue 8508015: Create a new depot_tools_testing_lib to move utility modules there (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Renamed to testing_support Created 9 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tests/fake_repos.py ('k') | tests/gcl_unittest.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/filesystem_mock.py
diff --git a/tests/filesystem_mock.py b/tests/filesystem_mock.py
deleted file mode 100644
index 270b2244a0f2ff9aae93be27022d9e070a59eaa9..0000000000000000000000000000000000000000
--- a/tests/filesystem_mock.py
+++ /dev/null
@@ -1,75 +0,0 @@
-# Copyright (c) 2011 The Chromium Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-import errno
-import os
-import re
-import StringIO
-
-
-def _RaiseNotFound(path):
- raise IOError(errno.ENOENT, path, os.strerror(errno.ENOENT))
-
-
-class MockFileSystem(object):
- """Stripped-down version of WebKit's webkitpy.common.system.filesystem_mock
-
- Implements a filesystem-like interface on top of a dict of filenames ->
- file contents. A file content value of None indicates that the file should
- not exist (IOError will be raised if it is opened;
- reading from a missing key raises a KeyError, not an IOError."""
-
- def __init__(self, files=None):
- self.files = files or {}
- self.written_files = {}
- self._sep = '/'
-
- @property
- def sep(self):
- return self._sep
-
- def _split(self, path):
- return path.rsplit(self.sep, 1)
-
- def abspath(self, path):
- if path.endswith(self.sep):
- return path[:-1]
- return path
-
- def dirname(self, path):
- if self.sep not in path:
- return ''
- return self._split(path)[0] or self.sep
-
- def exists(self, path):
- return self.isfile(path) or self.isdir(path)
-
- def isfile(self, path):
- return path in self.files and self.files[path] is not None
-
- def isdir(self, path):
- if path in self.files:
- return False
- if not path.endswith(self.sep):
- path += self.sep
-
- # We need to use a copy of the keys here in order to avoid switching
- # to a different thread and potentially modifying the dict in
- # mid-iteration.
- files = self.files.keys()[:]
- return any(f.startswith(path) for f in files)
-
- def join(self, *comps):
- # TODO: Might want tests for this and/or a better comment about how
- # it works.
- return re.sub(re.escape(os.path.sep), self.sep, os.path.join(*comps))
-
- def open_for_reading(self, path):
- return StringIO.StringIO(self.read_binary_file(path))
-
- def read_binary_file(self, path):
- # Intentionally raises KeyError if we don't recognize the path.
- if self.files[path] is None:
- _RaiseNotFound(path)
- return self.files[path]
« no previous file with comments | « tests/fake_repos.py ('k') | tests/gcl_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698