changeset 31:3897ed8a350d

Added NullFileSystem and test for it.
author Atul Varma <avarma@mozilla.com>
date Mon, 10 May 2010 01:54:59 -0700
parents 83104982c815
children e3fcfa2bf3bc
files pydertron/__init__.py test_pydertron.py
diffstat 2 files changed, 29 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/pydertron/__init__.py	Mon May 10 01:20:21 2010 -0700
+++ b/pydertron/__init__.py	Mon May 10 01:54:59 2010 -0700
@@ -591,6 +591,17 @@
                                       e.exc_info[2], None, stderr)
         return retval
 
+class NullFileSystem(object):
+    """
+    File system that represents an empty filesystem.
+    """
+
+    def find_module(self, curr_script, path):
+        return None
+
+    def open(self, filename):
+        raise AssertionError('This should never be called.')
+
 class HttpFileSystem(object):
     """
     File system through which all resources are loaded over HTTP.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test_pydertron.py	Mon May 10 01:54:59 2010 -0700
@@ -0,0 +1,18 @@
+import unittest
+from StringIO import StringIO
+
+import pydertron
+
+class PydertronTests(unittest.TestCase):
+    def testNullFilesystem(self):
+        stderr = StringIO()
+        sandbox = pydertron.JsSandbox(pydertron.NullFileSystem())
+        sandbox.set_globals()
+        sandbox.run_script("require('hi');", stderr=stderr)
+        self.assertEqual(stderr.getvalue(),
+                         'Traceback (most recent call last):\n'
+                         '  File "<string>", line 1, in <module>\n'
+                         'Module not found: hi\n')
+
+if __name__ == '__main__':
+    unittest.main()