| OLD | NEW |
| 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 class TestFileSystem(FileSystem): | 8 class TestFileSystem(FileSystem): |
| 9 '''A FileSystem backed by an object. Create with an object representing file | 9 '''A FileSystem backed by an object. Create with an object representing file |
| 10 paths such that {'a': {'b': 'hello'}} will resolve Read('a/b') as 'hello', | 10 paths such that {'a': {'b': 'hello'}} will resolve Read('a/b') as 'hello', |
| 11 Read('a/') as ['b'], and Stat determined by a value incremented via | 11 Read('a/') as ['b'], and Stat determined by a value incremented via |
| 12 IncrementStat. | 12 IncrementStat. |
| 13 ''' | 13 ''' |
| 14 | 14 |
| 15 # TODO(kalman): this method would be unnecessary if we injected paths properly | 15 # TODO(kalman): this method would be unnecessary if we injected paths properly |
| 16 # in ServerInstance. | 16 # in ServerInstance. |
| 17 @staticmethod | 17 @staticmethod |
| 18 def MoveTo(base, obj): | 18 def MoveTo(base, obj): |
| 19 '''Returns an object as |obj| moved to |prefix|. That is, | 19 '''Returns an object as |obj| moved to |base|. That is, |
| 20 MoveTo('foo/bar', {'a': 'b'}) -> {'foo': {'bar': {'a': 'b'}}} | 20 MoveTo('foo/bar', {'a': 'b'}) -> {'foo': {'bar': {'a': 'b'}}} |
| 21 ''' | 21 ''' |
| 22 result = {} | 22 result = {} |
| 23 leaf = result | 23 leaf = result |
| 24 for k in base.split('/'): | 24 for k in base.split('/'): |
| 25 leaf[k] = {} | 25 leaf[k] = {} |
| 26 leaf = leaf[k] | 26 leaf = leaf[k] |
| 27 leaf.update(obj) | 27 leaf.update(obj) |
| 28 return result | 28 return result |
| 29 | 29 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 else: | 122 else: |
| 123 self._global_stat += 1 | 123 self._global_stat += 1 |
| 124 | 124 |
| 125 def CheckAndReset(self, stat_count=0, read_count=0): | 125 def CheckAndReset(self, stat_count=0, read_count=0): |
| 126 try: | 126 try: |
| 127 return (self._read_count == read_count and | 127 return (self._read_count == read_count and |
| 128 self._stat_count == stat_count) | 128 self._stat_count == stat_count) |
| 129 finally: | 129 finally: |
| 130 self._read_count = 0 | 130 self._read_count = 0 |
| 131 self._stat_count = 0 | 131 self._stat_count = 0 |
| OLD | NEW |