comparison tests/mockutil.py @ 349:c484e1ec9150

tests: Add more utility functions to the mock file-system.
author Ludovic Chabant <ludovic@chabant.com>
date Fri, 17 Apr 2015 16:05:28 -0700
parents 89cc71928f6a
children 4b1019bb2533
comparison
equal deleted inserted replaced
348:f43e911cecac 349:c484e1ec9150
163 root = self._fs[self._root] 163 root = self._fs[self._root]
164 if path: 164 if path:
165 root = self._getEntry(self.path(path)) 165 root = self._getEntry(self.path(path))
166 if root is None: 166 if root is None:
167 raise Exception("No such path: %s" % path) 167 raise Exception("No such path: %s" % path)
168 if not isinstance(root, dict):
169 raise Exception("Path is not a directory: %s" % path)
168 170
169 res = {} 171 res = {}
170 for k, v in root.items(): 172 for k, v in root.items():
171 self._getStructureRecursive(v, res, k) 173 self._getStructureRecursive(v, res, k)
172 return res 174 return res
175
176 def getFileEntry(self, path):
177 entry = self._getEntry(self.path(path))
178 if entry is None:
179 raise Exception("No such file: %s" % path)
180 if not isinstance(entry, _MockFsEntry):
181 raise Exception("Path is not a file: %s" % path)
182 return entry.contents
173 183
174 def _getStructureRecursive(self, src, target, name): 184 def _getStructureRecursive(self, src, target, name):
175 if isinstance(src, _MockFsEntry): 185 if isinstance(src, _MockFsEntry):
176 target[name] = src.contents 186 target[name] = src.contents
177 return 187 return