changeset 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 f43e911cecac
children b8ff1780b491
files tests/mockutil.py
diffstat 1 files changed, 10 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/tests/mockutil.py	Wed Apr 15 16:43:27 2015 -0700
+++ b/tests/mockutil.py	Fri Apr 17 16:05:28 2015 -0700
@@ -165,12 +165,22 @@
             root = self._getEntry(self.path(path))
             if root is None:
                 raise Exception("No such path: %s" % path)
+            if not isinstance(root, dict):
+                raise Exception("Path is not a directory: %s" % path)
 
         res = {}
         for k, v in root.items():
             self._getStructureRecursive(v, res, k)
         return res
 
+    def getFileEntry(self, path):
+        entry = self._getEntry(self.path(path))
+        if entry is None:
+            raise Exception("No such file: %s" % path)
+        if not isinstance(entry, _MockFsEntry):
+            raise Exception("Path is not a file: %s" % path)
+        return entry.contents
+
     def _getStructureRecursive(self, src, target, name):
         if isinstance(src, _MockFsEntry):
             target[name] = src.contents