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

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

Issue 521453003: Docserver: Override Walk in CachingFileSystem (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import os 6 import os
7 import sys 7 import sys
8 import unittest 8 import unittest
9 9
10 from caching_file_system import CachingFileSystem 10 from caching_file_system import CachingFileSystem
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 } 244 }
245 })) 245 }))
246 def read_skip_not_found(paths): 246 def read_skip_not_found(paths):
247 return caching_fs.Read(paths, skip_not_found=True).Get() 247 return caching_fs.Read(paths, skip_not_found=True).Get()
248 self.assertEqual({}, read_skip_not_found(('grub',))) 248 self.assertEqual({}, read_skip_not_found(('grub',)))
249 self.assertEqual({}, read_skip_not_found(('bob/bob2',))) 249 self.assertEqual({}, read_skip_not_found(('bob/bob2',)))
250 self.assertEqual({ 250 self.assertEqual({
251 'bob/bob0': 'bob/bob0 contents', 251 'bob/bob0': 'bob/bob0 contents',
252 }, read_skip_not_found(('bob/bob0', 'bob/bob2'))) 252 }, read_skip_not_found(('bob/bob0', 'bob/bob2')))
253 253
254 def testWalkCaching(self):
255 test_fs = TestFileSystem({
256 'root': {
257 'file1': 'file1',
258 'file2': 'file2',
259 'dir1': {
260 'dir1_file1': 'dir1_file1',
261 'dir2': {},
262 'dir3': {
263 'dir3_file1': 'dir3_file1',
264 'dir3_file2': 'dir3_file2'
265 }
266 }
267 }
268 })
269 mock_fs = MockFileSystem(test_fs)
270 file_system = self._CreateCachingFileSystem(mock_fs, start_empty=True)
271 for walkinfo in file_system.Walk(''):
272 pass
273 self.assertTrue(*mock_fs.CheckAndReset(
274 read_resolve_count=5, read_count=5, stat_count=5))
275
276 all_dirs, all_files = [], []
277 for root, dirs, files in file_system.Walk(''):
278 all_dirs.extend(dirs)
279 all_files.extend(files)
280 self.assertEqual(sorted(['root/', 'dir1/', 'dir2/', 'dir3/']),
281 sorted(all_dirs))
282 self.assertEqual(
283 sorted(['file1', 'file2', 'dir1_file1', 'dir3_file1', 'dir3_file2']),
284 sorted(all_files))
285 # All data should be cached.
286 self.assertTrue(*mock_fs.CheckAndReset())
287
288 # Starting from a different root should still pull cached data.
289 for walkinfo in file_system.Walk('root/dir1/'):
290 pass
291 self.assertTrue(*mock_fs.CheckAndReset())
254 292
255 if __name__ == '__main__': 293 if __name__ == '__main__':
256 unittest.main() 294 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698