Commits

Michael Hudson-Doyle committed f2800d3

rewrite tests as unittests; add test of run_string

Comments (0)

Files changed (1)

pypy/interpreter/test/test_main.py

+import unittest
 import support
 
-from pypy.interpreter import main
+from pypy.interpreter.baseobjspace import OperationError
 
-main.main(['main.py', 'hello_world.py'])
+testcode = """\
+def main():
+    aStr = 'hello world'
+    print len(aStr)
+
+main()
+"""
+
+testfn = 'tmp_hello_world.py'
+
+class TestMain(unittest.TestCase):
+
+    def setUp(self):
+        ofile = open(testfn, 'w')
+        ofile.write(testcode)
+        ofile.close()
+
+    def tearDown(self):
+        import os
+        os.remove(testfn)
+
+    def test_run_file(self):
+        from pypy.interpreter import main
+        self.assertRaises(OperationError,
+                          main.run_file,
+                          testfn)
+
+    def test_run_string(self):
+        from pypy.interpreter import main
+        self.assertRaises(OperationError,
+                          main.run_string,
+                          testcode,
+                          testfn)
+
+if __name__ == '__main__':
+    unittest.main()
+