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

Unified Diff: chrome/common/extensions/docs/server2/mock_file_system.py

Issue 15009006: Docserver: refactor Servlet, ObjectStore, and ServerInstance architecture to (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cduvall, redirect fix Created 7 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/common/extensions/docs/server2/mock_file_system.py
diff --git a/chrome/common/extensions/docs/server2/mock_file_system.py b/chrome/common/extensions/docs/server2/mock_file_system.py
new file mode 100644
index 0000000000000000000000000000000000000000..70e37c10bf4e7864a1681c07c9c5c32cca288fb7
--- /dev/null
+++ b/chrome/common/extensions/docs/server2/mock_file_system.py
@@ -0,0 +1,66 @@
+# Copyright 2013 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.
+
+from file_system import FileSystem
+
+class MockFileSystem(FileSystem):
+ '''Wraps a FileSystem to add simple mock behaviour - asserting how often
+ Stat/Read calls are being made to it. The Read/Stat implementations
+ themselves are provided by a delegate FileSystem.
+ '''
+ def __init__(self, file_system):
+ self._file_system = file_system
+ self._read_count = 0
+ self._stat_count = 0
+
+ #
+ # FileSystem implementation.
+ #
+
+ def Read(self, paths, binary=False):
+ self._read_count += 1
+ return self._file_system.Read(paths, binary=binary)
+
+ def Stat(self, path):
+ self._stat_count += 1
+ return self._file_system.Stat(path)
+
+ def GetIdentity(self):
+ return self._file_system.GetIdentity()
+
+ def __str__(self):
+ return repr(self)
+
+ def __repr__(self):
+ return 'MockFileSystem(read_count=%s, stat_count=%s)' % (
+ self._read_count, self._stat_count)
+
+ #
+ # Testing methods.
+ #
+
+ def GetReadCount(self):
+ return self._read_count
+
+ def GetStatCount(self):
+ return self._stat_count
+
+ def CheckAndReset(self, stat_count=0, read_count=0):
+ '''Returns a tuple (success, error). Use in tests like:
+ self.assertTrue(*object_store.CheckAndReset(...))
+ '''
+ errors = []
+ for desc, expected, actual in (
+ ('read_count', read_count, self._read_count),
+ ('stat_count', stat_count, self._stat_count)):
+ if actual != expected:
+ errors.append('%s: expected %s got %s' % (desc, expected, actual))
+ try:
+ return (len(errors) == 0, ', '.join(errors))
+ finally:
+ self.Reset()
+
+ def Reset(self):
+ self._read_count = 0
+ self._stat_count = 0

Powered by Google App Engine
This is Rietveld 408576698