Mercurial > pydertron
view test_pydertron.py @ 35:6ddc83bb61f8 default tip
added another gc test
| author | Atul Varma <avarma@mozilla.com> |
|---|---|
| date | Mon, 10 May 2010 21:01:58 -0700 |
| parents | 739c87de4667 |
| children |
line wrap: on
line source
import unittest import weakref import gc from StringIO import StringIO import pydertron from pydertron import jsexposed 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') sandbox.finish() def testGC(self): sandbox = pydertron.JsSandbox(pydertron.NullFileSystem()) wrt = weakref.ref(sandbox.rt) del sandbox gc.collect() self.assertEqual(wrt(), None) def testGC2(self): sandbox = pydertron.JsSandbox(pydertron.NullFileSystem()) sandbox.set_globals() sandbox.run_script("var a = 1;") wrt = weakref.ref(sandbox.rt) sandbox.finish() del sandbox gc.collect() self.assertEqual(wrt(), None) def testGC3(self): sandbox = pydertron.JsSandbox(pydertron.NullFileSystem()) stuff = [] @jsexposed def bleh(x): stuff.append(x) sandbox.set_globals(bleh=bleh) sandbox.run_script("bleh({});") wrt = weakref.ref(sandbox.rt) sandbox.finish() stuff.pop() del sandbox gc.collect() self.assertEqual(wrt(), None) if __name__ == '__main__': unittest.main()
