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

Side by Side Diff: chrome/common/extensions/docs/server2/test_file_system.py

Issue 26538009: Docserver: make file_system a property of Create (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Done Created 7 years, 2 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 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # 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
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 from file_system import FileSystem, FileNotFoundError, StatInfo 5 from file_system import FileSystem, FileNotFoundError, StatInfo
6 from future import Future 6 from future import Future
7 7
8 8
9 def _MoveTo(base, obj): 9 def _MoveTo(base, obj):
10 '''Returns an object as |obj| moved to |base|. That is, 10 '''Returns an object as |obj| moved to |base|. That is,
11 _MoveTo('foo/bar', {'a': 'b'}) -> {'foo': {'bar': {'a': 'b'}}} 11 _MoveTo('foo/bar', {'a': 'b'}) -> {'foo': {'bar': {'a': 'b'}}}
12 ''' 12 '''
13 result = {} 13 result = {}
14 leaf = result 14 leaf = result
15 for k in base.split('/'): 15 for k in base.split('/'):
16 leaf[k] = {} 16 leaf[k] = {}
17 leaf = leaf[k] 17 leaf = leaf[k]
18 leaf.update(obj) 18 leaf.update(obj)
19 return result 19 return result
20 20
21 21
22 class TestFileSystem(FileSystem): 22 class TestFileSystem(FileSystem):
23 '''A FileSystem backed by an object. Create with an object representing file 23 '''A FileSystem backed by an object. Create with an object representing file
24 paths such that {'a': {'b': 'hello'}} will resolve Read('a/b') as 'hello', 24 paths such that {'a': {'b': 'hello'}} will resolve Read('a/b') as 'hello',
25 Read('a/') as ['b'], and Stat determined by a value incremented via 25 Read('a/') as ['b'], and Stat determined by a value incremented via
26 IncrementStat. 26 IncrementStat.
27 ''' 27 '''
28 28
29 def __init__(self, obj, relative_to=None): 29 def __init__(self, obj, relative_to=None, identity=None):
30 assert obj is not None 30 assert obj is not None
31 self._obj = obj if relative_to is None else _MoveTo(relative_to, obj) 31 self._obj = obj if relative_to is None else _MoveTo(relative_to, obj)
32 self._identity = identity or type(self).__name__
32 self._path_stats = {} 33 self._path_stats = {}
33 self._global_stat = 0 34 self._global_stat = 0
34 35
35 # 36 #
36 # FileSystem implementation. 37 # FileSystem implementation.
37 # 38 #
38 39
39 def Read(self, paths, binary=False): 40 def Read(self, paths, binary=False):
40 test_fs = self 41 test_fs = self
41 class Delegate(object): 42 class Delegate(object):
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 for file_result in read_result) 100 for file_result in read_result)
100 return stat_result 101 return stat_result
101 102
102 def _SinglePathStat(self, path): 103 def _SinglePathStat(self, path):
103 return str(self._global_stat + self._path_stats.get(path, 0)) 104 return str(self._global_stat + self._path_stats.get(path, 0))
104 105
105 # 106 #
106 # Testing methods. 107 # Testing methods.
107 # 108 #
108 109
109 def IncrementStat(self, path=None): 110 def IncrementStat(self, path=None):
Jeffrey Yasskin 2013/10/14 18:52:31 Should this become IncrementVersion at some point?
not at google - send to devlin 2013/10/14 21:03:34 I expect so, yes.
110 if path is not None: 111 if path is not None:
111 self._path_stats[path] = self._path_stats.get(path, 0) + 1 112 self._path_stats[path] = self._path_stats.get(path, 0) + 1
112 else: 113 else:
113 self._global_stat += 1 114 self._global_stat += 1
114 115
115 def GetIdentity(self): 116 def GetIdentity(self):
116 return self.__class__.__name__ 117 return self._identity
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698