| 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', |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 '%s (%s) did not resolve to a dict, instead %s' % | 96 '%s (%s) did not resolve to a dict, instead %s' % |
| 97 (path, parts, dir_contents)) | 97 (path, parts, dir_contents)) |
| 98 | 98 |
| 99 return GetPaths(dir_contents) | 99 return GetPaths(dir_contents) |
| 100 | 100 |
| 101 def Stat(self, path): | 101 def Stat(self, path): |
| 102 self._stat_count += 1 | 102 self._stat_count += 1 |
| 103 return self._StatImpl(path) | 103 return self._StatImpl(path) |
| 104 | 104 |
| 105 def _StatImpl(self, path): | 105 def _StatImpl(self, path): |
| 106 read_result = self._ReadImpl([path]).Get()[path] | 106 read_result = self._ReadImpl([path]).Get().get(path) |
| 107 stat_result = StatInfo(self._SinglePathStat(path)) | 107 stat_result = StatInfo(self._SinglePathStat(path)) |
| 108 if isinstance(read_result, list): | 108 if isinstance(read_result, list): |
| 109 stat_result.child_versions = dict( | 109 stat_result.child_versions = dict( |
| 110 (file_result, self._SinglePathStat('%s%s' % (path, file_result))) | 110 (file_result, self._SinglePathStat('%s%s' % (path, file_result))) |
| 111 for file_result in read_result) | 111 for file_result in read_result) |
| 112 return stat_result | 112 return stat_result |
| 113 | 113 |
| 114 def _SinglePathStat(self, path): | 114 def _SinglePathStat(self, path): |
| 115 return str(self._global_stat + self._path_stats.get(path, 0)) | 115 return str(self._global_stat + self._path_stats.get(path, 0)) |
| 116 | 116 |
| 117 # | 117 # |
| 118 # Testing methods. | 118 # Testing methods. |
| 119 # | 119 # |
| 120 | 120 |
| 121 def IncrementStat(self, path=None): | 121 def IncrementStat(self, path=None): |
| 122 if path is not None: | 122 if path is not None: |
| 123 self._path_stats[path] = self._path_stats.get(path, 0) + 1 | 123 self._path_stats[path] = self._path_stats.get(path, 0) + 1 |
| 124 else: | 124 else: |
| 125 self._global_stat += 1 | 125 self._global_stat += 1 |
| 126 | 126 |
| 127 def CheckAndReset(self, stat_count=0, read_count=0): | 127 def CheckAndReset(self, stat_count=0, read_count=0): |
| 128 try: | 128 try: |
| 129 return (self._read_count == read_count and | 129 return (self._read_count == read_count and |
| 130 self._stat_count == stat_count) | 130 self._stat_count == stat_count) |
| 131 finally: | 131 finally: |
| 132 self._read_count = 0 | 132 self._read_count = 0 |
| 133 self._stat_count = 0 | 133 self._stat_count = 0 |
| OLD | NEW |