[pypy-svn] r8169 - in pypy/branch/src-pytest/pypy: . interpreter/test

hpk at codespeak.net hpk at codespeak.net
Sat Jan 8 15:05:38 CET 2005


Author: hpk
Date: Sat Jan  8 15:05:37 2005
New Revision: 8169

Modified:
   pypy/branch/src-pytest/pypy/conftest.py
   pypy/branch/src-pytest/pypy/interpreter/test/test_exceptcomp.py
   pypy/branch/src-pytest/pypy/interpreter/test/test_exec.py
   pypy/branch/src-pytest/pypy/interpreter/test/test_extmodule.py
   pypy/branch/src-pytest/pypy/interpreter/test/test_function.py
   pypy/branch/src-pytest/pypy/interpreter/test/test_gateway.py
   pypy/branch/src-pytest/pypy/interpreter/test/test_main.py
   pypy/branch/src-pytest/pypy/interpreter/test/test_module.py
Log:
ported all the rest of the interpreter tests 

moved create-space-magic to setup_class 
because there doesn't appear to be a use 
case for doing it at setup_method time
but there is one (in test_module) for 
having it already at class-level.



Modified: pypy/branch/src-pytest/pypy/conftest.py
==============================================================================
--- pypy/branch/src-pytest/pypy/conftest.py	(original)
+++ pypy/branch/src-pytest/pypy/conftest.py	Sat Jan  8 15:05:37 2005
@@ -85,13 +85,13 @@
     #        mod.space = getttestobjspace(mod.objspacename)
     #    super(PyPyItem, self).setup_module(mod) 
 
-    def setup_method(self, method): 
-        base = getattr(method, 'im_self', method) 
-        name = getattr(base, 'objspacename', None) 
+    def setup_class(self, cls): 
+        name = getattr(cls, 'objspacename', None) 
         if name is None: 
-            name = method.im_func.func_globals.get('objspacename', None) 
-        base.space = gettestobjspace(name) 
-        super(PyPyItem, self).setup_method(method) 
+            m = __import__(cls.__module__) 
+            name = getattr(m, 'objspacename', None) 
+        cls.space = gettestobjspace(name) 
+        super(PyPyItem, self).setup_class(cls) 
 
     def execute_appex(self, space, target, *args):
         try:

Modified: pypy/branch/src-pytest/pypy/interpreter/test/test_exceptcomp.py
==============================================================================
--- pypy/branch/src-pytest/pypy/interpreter/test/test_exceptcomp.py	(original)
+++ pypy/branch/src-pytest/pypy/interpreter/test/test_exceptcomp.py	Sat Jan  8 15:05:37 2005
@@ -3,12 +3,8 @@
 New for PyPy - Could be incorporated into CPython regression tests.
 """
 import autopath
-from pypy.tool import testit
 
-class TestExceptionComp(testit.AppTestCase):
-
-    def setUp(self):
-        self.space = testit.objspace()
+class AppTestExceptionComp: 
 
 ### XXX - String exceptions depreciated?
 ##    def test_string(self):
@@ -133,6 +129,3 @@
             pass
         except:
             self.fail("Exception does not match self in deeply nested tuple.")
-            
-if __name__ == "__main__":
-    testit.main()

Modified: pypy/branch/src-pytest/pypy/interpreter/test/test_exec.py
==============================================================================
--- pypy/branch/src-pytest/pypy/interpreter/test/test_exec.py	(original)
+++ pypy/branch/src-pytest/pypy/interpreter/test/test_exec.py	Sat Jan  8 15:05:37 2005
@@ -3,45 +3,41 @@
 New for PyPy - Could be incorporated into CPython regression tests.
 """
 import autopath
-from pypy.tool import testit 
 
-class TestExecStmt(testit.AppTestCase):
-
-    def setUp(self):
-        self.space = testit.objspace()
+class AppTestExecStmt: 
 
     def test_string(self):
         g = {}
         l = {}
         exec "a = 3" in g, l
-        self.failUnlessEqual(l['a'], 3)
+        assert not l['a'] != 3
 
     def test_localfill(self):
         g = {}
         exec "a = 3" in g
-        self.failUnlessEqual(g['a'], 3)
+        assert not g['a'] != 3
         
     def test_builtinsupply(self):
         g = {}
         exec "pass" in g
-        self.failUnless(g.has_key('__builtins__'))
+        assert g.has_key('__builtins__')
 
     def test_invalidglobal(self):
         def f():
             exec 'pass' in 1
-        self.failUnlessRaises(TypeError,f)
+        raises(TypeError,f)
 
     def test_invalidlocal(self):
         def f():
             exec 'pass' in {}, 2
-        self.failUnlessRaises(TypeError,f)
+        raises(TypeError,f)
 
     def test_codeobject(self):
         co = compile("a = 3", '<string>', 'exec')
         g = {}
         l = {}
         exec co in g, l
-        self.failUnlessEqual(l['a'], 3)
+        assert not l['a'] != 3
         
 ##    # Commented out as PyPy give errors using open()
 ##    #     ["Not availible in restricted mode"]
@@ -54,23 +50,20 @@
     def test_implicit(self):
         a = 4
         exec "a = 3"
-        self.failUnlessEqual(a,3)
+        assert not a !=3
 
     def test_tuplelocals(self):
         g = {}
         l = {}
         exec ("a = 3", g, l)
-        self.failUnlessEqual(l['a'], 3)
+        assert not l['a'] != 3
         
     def test_tupleglobals(self):
         g = {}
         exec ("a = 3", g)
-        self.failUnlessEqual(g['a'], 3)
+        assert not g['a'] != 3
 
     def test_exceptionfallthrough(self):
         def f():
             exec 'raise TypeError' in {}
-        self.failUnlessRaises(TypeError,f)
-
-if __name__ == "__main__":
-    testit.main()
+        raises(TypeError,f)

Modified: pypy/branch/src-pytest/pypy/interpreter/test/test_extmodule.py
==============================================================================
--- pypy/branch/src-pytest/pypy/interpreter/test/test_extmodule.py	(original)
+++ pypy/branch/src-pytest/pypy/interpreter/test/test_extmodule.py	Sat Jan  8 15:05:37 2005
@@ -1,34 +1,25 @@
 
 import autopath
 import os
-from pypy.tool import testit
 from pypy.interpreter.extmodule import BuiltinModule
 
-
-class TestBuiltinModule(testit.IntTestCase):
-    def setUp(self):
-        self.space = testit.objspace()
-
+class TestBuiltinModule: 
     def test_foomodule(self):
         space = self.space
         sourcefile = os.path.join(autopath.this_dir, 'foomodule.py')
         m = BuiltinModule(space, 'foo', sourcefile=sourcefile)
         w = space.wrap
         w_m = space.wrap(m)
-        self.assertEqual_w(space.getattr(w_m, w('__name__')), w('foo'))
-        self.assertEqual_w(space.getattr(w_m, w('__file__')), w(sourcefile))
+        self.space.eq_w(space.getattr(w_m, w('__name__')), w('foo'))
+        self.space.eq_w(space.getattr(w_m, w('__file__')), w(sourcefile))
         # check app-level definitions
-        self.assertEqual_w(m.w_foo, space.w_Ellipsis)
-        self.assertEqual_w(space.getattr(w_m, w('foo1')), space.w_Ellipsis)
-        self.assertEqual_w(space.getattr(w_m, w('foo')), space.w_Ellipsis)
-        self.assertEqual_w(space.call_method(w_m, 'bar', w(4), w(3)), w(12))
-        self.assertEqual_w(space.getattr(w_m, w('foo2')), w('hello'))
-        self.assertEqual_w(space.getattr(w_m, w('foo3')), w('hi, guido!'))
+        self.space.eq_w(m.w_foo, space.w_Ellipsis)
+        self.space.eq_w(space.getattr(w_m, w('foo1')), space.w_Ellipsis)
+        self.space.eq_w(space.getattr(w_m, w('foo')), space.w_Ellipsis)
+        self.space.eq_w(space.call_method(w_m, 'bar', w(4), w(3)), w(12))
+        self.space.eq_w(space.getattr(w_m, w('foo2')), w('hello'))
+        self.space.eq_w(space.getattr(w_m, w('foo3')), w('hi, guido!'))
         # check interp-level definitions
-        self.assertEqual_w(m.w_foo2, w('hello'))
-        self.assertEqual_w(m.foobuilder(w('xyzzy')), w('hi, xyzzy!'))
-        self.assertEqual_w(m.fortytwo, w(42))
-
-
-if __name__ == '__main__':
-    testit.main()
+        self.space.eq_w(m.w_foo2, w('hello'))
+        self.space.eq_w(m.foobuilder(w('xyzzy')), w('hi, xyzzy!'))
+        self.space.eq_w(m.fortytwo, w(42))

Modified: pypy/branch/src-pytest/pypy/interpreter/test/test_function.py
==============================================================================
--- pypy/branch/src-pytest/pypy/interpreter/test/test_function.py	(original)
+++ pypy/branch/src-pytest/pypy/interpreter/test/test_function.py	Sat Jan  8 15:05:37 2005
@@ -1,165 +1,163 @@
 
 import autopath
-from pypy.tool import testit 
 import unittest
 from pypy.interpreter.function import Function, Method
 from pypy.interpreter.pycode import PyCode
 from pypy.interpreter.argument import Arguments
 
 
-class AppTestFunctionIntrospection(testit.AppTestCase):
+class AppTestFunctionIntrospection: 
     def test_attributes(self):
         def f(): pass
-        self.assert_(hasattr(f, 'func_code'))
-        self.assertEquals(f.func_defaults, None)
-        self.assertEquals(f.func_dict, {})
-        self.assertEquals(type(f.func_globals), dict)
+        assert hasattr(f, 'func_code')
+        assert f.func_defaults == None
+        assert f.func_dict == {}
+        assert type(f.func_globals) == dict
         #self.assertEquals(f.func_closure, None)  XXX
-        self.assertEquals(f.func_doc, None)
-        self.assertEquals(f.func_name, 'f')
+        assert f.func_doc == None
+        assert f.func_name == 'f'
 
     def test_code_is_ok(self):
         def f(): pass
-        self.assert_(not hasattr(f.func_code, '__dict__'))
+        assert not hasattr(f.func_code, '__dict__')
 
     def test_underunder_attributes(self):
         def f(): pass
-        self.assertEquals(f.__name__, 'f')
-        self.assertEquals(f.__doc__, None)
-        self.assert_(f.__name__ == f.func_name)
-        self.assert_(f.__doc__ == f.func_doc)
-        self.assert_(f.__dict__ is f.func_dict)
-        self.assert_(hasattr(f, '__class__'))
+        assert f.__name__ == 'f'
+        assert f.__doc__ == None
+        assert f.__name__ == f.func_name
+        assert f.__doc__ == f.func_doc
+        assert f.__dict__ is f.func_dict
+        assert hasattr(f, '__class__')
 
     def test_write_doc(self):
         def f(): "hello"
-        self.assertEquals(f.__doc__, 'hello')
+        assert f.__doc__ == 'hello'
         f.__doc__ = 'good bye'
-        self.assertEquals(f.__doc__, 'good bye')
+        assert f.__doc__ == 'good bye'
         del f.__doc__
-        self.assertEquals(f.__doc__, None)
+        assert f.__doc__ == None
 
     def test_write_func_doc(self):
         def f(): "hello"
-        self.assertEquals(f.func_doc, 'hello')
+        assert f.func_doc == 'hello'
         f.func_doc = 'good bye'
-        self.assertEquals(f.func_doc, 'good bye')
+        assert f.func_doc == 'good bye'
         del f.func_doc
-        self.assertEquals(f.func_doc, None)
+        assert f.func_doc == None
 
-class AppTestFunction(testit.AppTestCase):
+class AppTestFunction: 
     def test_simple_call(self):
         def func(arg1, arg2):
             return arg1, arg2
         res = func(23,42)
-        self.assertEquals(res[0], 23)
-        self.assertEquals(res[1], 42)
+        assert res[0] == 23
+        assert res[1] == 42
 
     def test_simple_varargs(self):
         def func(arg1, *args):
             return arg1, args
         res = func(23,42)
-        self.assertEquals(res[0], 23)
-        self.assertEquals(res[1], (42,))
+        assert res[0] == 23
+        assert res[1] == (42,)
 
     def test_simple_kwargs(self):
         def func(arg1, **kwargs):
             return arg1, kwargs
         res = func(23, value=42)
-        self.assertEquals(res[0], 23)
-        self.assertEquals(res[1], {'value': 42})
+        assert res[0] == 23
+        assert res[1] == {'value': 42}
 
     def test_kwargs_sets_wrong_positional_raises(self):
         def func(arg1):
             pass
-        self.assertRaises(TypeError, func, arg2=23)
+        raises(TypeError, func, arg2=23)
 
     def test_kwargs_sets_positional(self):
         def func(arg1):
             return arg1
         res = func(arg1=42)
-        self.assertEquals(res, 42)
+        assert res == 42
 
     def test_kwargs_sets_positional_mixed(self):
         def func(arg1, **kw):
             return arg1, kw
         res = func(arg1=42, something=23)
-        self.assertEquals(res[0], 42)
-        self.assertEquals(res[1], {'something': 23})
+        assert res[0] == 42
+        assert res[1] == {'something': 23}
 
     def test_kwargs_sets_positional_mixed(self):
         def func(arg1, **kw):
             return arg1, kw
         res = func(arg1=42, something=23)
-        self.assertEquals(res[0], 42)
-        self.assertEquals(res[1], {'something': 23})
+        assert res[0] == 42
+        assert res[1] == {'something': 23}
 
     def test_kwargs_sets_positional_twice(self):
         def func(arg1, **kw):
             return arg1, kw
-        self.assertRaises(
+        raises(
             TypeError, func, 42, {'arg1': 23})
 
     def test_default_arg(self):
         def func(arg1,arg2=42):
             return arg1, arg2
         res = func(arg1=23)
-        self.assertEquals(res[0], 23)
-        self.assertEquals(res[1], 42)
+        assert res[0] == 23
+        assert res[1] == 42
 
     def test_defaults_keyword_overrides(self):
         def func(arg1=42, arg2=23):
             return arg1, arg2
         res = func(arg1=23)
-        self.assertEquals(res[0], 23)
-        self.assertEquals(res[1], 23)
+        assert res[0] == 23
+        assert res[1] == 23
 
     def test_defaults_keyword_override_but_leaves_empty_positional(self):
         def func(arg1,arg2=42):
             return arg1, arg2
-        self.assertRaises(TypeError, func, arg2=23)
+        raises(TypeError, func, arg2=23)
 
     def test_kwargs_disallows_same_name_twice(self):
         def func(arg1, **kw):
             return arg1, kw
-        self.assertRaises(TypeError, func, 42, **{'arg1': 23})
+        raises(TypeError, func, 42, **{'arg1': 23})
 
     def test_kwargs_confusing_name(self):
         def func(self):    # 'self' conflicts with the interp-level
             return self*7  # argument to call_function()
         res = func(self=6)
-        self.assertEquals(res, 42)
+        assert res == 42
 
     def test_get(self):
         def func(self): return self
         obj = object()
         meth = func.__get__(obj, object)
-        self.assertEquals(meth(), obj)
+        assert meth() == obj
 
     def test_call_builtin(self):
         s = 'hello'
-        self.assertRaises(TypeError, len)
-        self.assertEquals(len(s), 5)
-        self.assertRaises(TypeError, len, s, s)
-        self.assertRaises(TypeError, len, s, s, s)
-        self.assertEquals(len(*[s]), 5)
-        self.assertEquals(len(s, *[]), 5)
-        self.assertRaises(TypeError, len, some_unknown_keyword=s)
-        self.assertRaises(TypeError, len, s, some_unknown_keyword=s)
-        self.assertRaises(TypeError, len, s, s, some_unknown_keyword=s)
-
-class AppTestMethod(testit.AppTestCase):
+        raises(TypeError, len)
+        assert len(s) == 5
+        raises(TypeError, len, s, s)
+        raises(TypeError, len, s, s, s)
+        assert len(*[s]) == 5
+        assert len(s, *[]) == 5
+        raises(TypeError, len, some_unknown_keyword=s)
+        raises(TypeError, len, s, some_unknown_keyword=s)
+        raises(TypeError, len, s, s, some_unknown_keyword=s)
 
+class AppTestMethod: 
     def test_get(self):
         def func(self): return self
         class Object(object): pass
         obj = Object()
         # Create bound method from function
         obj.meth = func.__get__(obj, Object)
-        self.assertEquals(obj.meth(), obj)
+        assert obj.meth() == obj
         # Create bound method from method
         meth2 = obj.meth.__get__(obj, Object)
-        self.assertEquals(meth2(), obj)
+        assert meth2() == obj
 
     def test_get_get(self):
         # sanxiyn's test from email
@@ -169,13 +167,12 @@
         C.m = m
         D.m = C.m
         c = C()
-        self.assertEquals(c.m(), c)
+        assert c.m() == c
         d = D()
-        self.assertEquals(d.m(), d)
+        assert d.m() == d
 
-class TestMethod(testit.IntTestCase):
-    def setUp(self):
-        self.space = testit.objspace()
+class TestMethod: 
+    def setup_method(self, method):
         def c(self, bar):
             return bar
         code = PyCode()._from_code(c.func_code)
@@ -185,21 +182,21 @@
         space = self.space
         w_meth = self.fn.descr_function_get(space.wrap(5), space.type(space.wrap(5)))
         meth = space.unwrap(w_meth)
-        self.failUnless(isinstance(meth, Method))
+        assert isinstance(meth, Method)
 
     def test_call(self):
         space = self.space
         w_meth = self.fn.descr_function_get(space.wrap(5), space.type(space.wrap(5)))
         meth = space.unwrap(w_meth)
         w_result = meth.call_args(Arguments(space, [space.wrap(42)]))
-        self.assertEquals(space.unwrap(w_result), 42)
+        assert space.unwrap(w_result) == 42
 
     def test_fail_call(self):
         space = self.space
         w_meth = self.fn.descr_function_get(space.wrap(5), space.type(space.wrap(5)))
         meth = space.unwrap(w_meth)
         args = Arguments(space, [space.wrap("spam"), space.wrap("egg")])
-        self.assertRaises_w(self.space.w_TypeError, meth.call_args, args)
+        self.space.raises_w(self.space.w_TypeError, meth.call_args, args)
 
     def test_method_get(self):
         space = self.space
@@ -213,25 +210,22 @@
         # Check method returned from func.__get__()
         w_meth1 = func.descr_function_get(obj1, space.type(obj1))
         meth1 = space.unwrap(w_meth1)
-        self.failUnless(isinstance(meth1, Method))
-        self.assertEquals(meth1.call_args(args), obj1)
+        assert isinstance(meth1, Method)
+        assert meth1.call_args(args) == obj1
         # Check method returned from method.__get__()
         # --- meth1 is already bound so meth1.__get__(*) is meth1.
         w_meth2 = meth1.descr_method_get(obj2, space.type(obj2))
         meth2 = space.unwrap(w_meth2)
-        self.failUnless(isinstance(meth2, Method))
-        self.assertEquals(meth2.call_args(args), obj1)
+        assert isinstance(meth2, Method)
+        assert meth2.call_args(args) == obj1
         # Check method returned from unbound_method.__get__()
         w_meth3 = func.descr_function_get(None, space.type(obj2))
         meth3 = space.unwrap(w_meth3)
         w_meth4 = meth3.descr_method_get(obj2, space.w_None)
         meth4 = space.unwrap(w_meth4)
-        self.failUnless(isinstance(meth4, Method))
-        self.assertEquals(meth4.call_args(args), obj2)
+        assert isinstance(meth4, Method)
+        assert meth4.call_args(args) == obj2
         # Check method returned from unbound_method.__get__()
         # --- with an incompatible class
         w_meth5 = meth3.descr_method_get(space.wrap('hello'), space.w_None)
-        self.assert_(space.is_true(space.is_(w_meth5, w_meth3)))
-
-if __name__ == '__main__':
-    testit.main()
+        assert space.is_true(space.is_(w_meth5, w_meth3))

Modified: pypy/branch/src-pytest/pypy/interpreter/test/test_gateway.py
==============================================================================
--- pypy/branch/src-pytest/pypy/interpreter/test/test_gateway.py	(original)
+++ pypy/branch/src-pytest/pypy/interpreter/test/test_gateway.py	Sat Jan  8 15:05:37 2005
@@ -1,33 +1,29 @@
 
 import autopath
-from pypy.tool import testit
 from pypy.interpreter import gateway
 
-class TestBuiltinCode(testit.IntTestCase):
-    def setUp(self):
-        self.space = testit.objspace()
-
+class TestBuiltinCode: 
     def test_signature(self):
         def c(space, w_x, w_y, *hello_w):
             pass
         code = gateway.BuiltinCode(c)
-        self.assertEqual(code.signature(), (['x', 'y'], 'hello', None))
+        assert code.signature() == (['x', 'y'], 'hello', None)
         def d(self, w_boo):
             pass
         code = gateway.BuiltinCode(d)
-        self.assertEqual(code.signature(), (['self', 'boo'], None, None))
+        assert code.signature() == (['self', 'boo'], None, None)
         def e(space, w_x, w_y, __args__):
             pass
         code = gateway.BuiltinCode(e)
-        self.assertEqual(code.signature(), (['x', 'y'], 'args', 'keywords'))
+        assert code.signature() == (['x', 'y'], 'args', 'keywords')
 
     def test_call(self):
         def c(space, w_x, w_y, *hello_w):
             u = space.unwrap
             w = space.wrap
-            self.assertEquals(len(hello_w), 2)
-            self.assertEquals(u(hello_w[0]), 0)
-            self.assertEquals(u(hello_w[1]), True)
+            assert len(hello_w) == 2
+            assert u(hello_w[0]) == 0
+            assert u(hello_w[1]) == True
             return w((u(w_x) - u(w_y) + len(hello_w)))
         code = gateway.BuiltinCode(c)
         w = self.space.wrap
@@ -37,7 +33,7 @@
             (w('hello'), self.space.newtuple([w(0), w(True)])),
             ])
         w_result = code.exec_code(self.space, w_dict, w_dict)
-        self.assertEqual_w(w_result, w(102))
+        self.space.eq_w(w_result, w(102))
 
     def test_call_args(self):
         def c(space, w_x, w_y, __args__):
@@ -55,19 +51,16 @@
             (w('keywords'), self.space.newdict([(w('boo'), w(10))])),
             ])
         w_result = code.exec_code(self.space, w_dict, w_dict)
-        self.assertEqual_w(w_result, w(1020))
-
+        self.space.eq_w(w_result, w(1020))
 
-class TestGateway(testit.IntTestCase):
-    def setUp(self):
-        self.space = testit.objspace()
 
+class TestGateway: 
     def test_app2interp(self):
         w = self.space.wrap
         def app_g3(a, b):
             return a+b
         g3 = gateway.app2interp_temp(app_g3)
-        self.assertEqual_w(g3(self.space, w('foo'), w('bar')), w('foobar'))
+        self.space.eq_w(g3(self.space, w('foo'), w('bar')), w('foobar'))
         
     def test_interp2app(self):
         space = self.space
@@ -76,12 +69,12 @@
             return space.add(w_a, w_b)
         app_g3 = gateway.interp2app_temp(g3)
         w_app_g3 = space.wrap(app_g3) 
-        self.assertEqual_w(
+        self.space.eq_w(
             space.call(w_app_g3, 
                        space.newtuple([w('foo'), w('bar')]),
                        space.newdict([])),
             w('foobar'))
-        self.assertEqual_w(
+        self.space.eq_w(
             space.call_function(w_app_g3, w('foo'), w('bar')),
             w('foobar'))
 
@@ -96,7 +89,7 @@
 """ in g
         gateway.importall(g, temporary=True)
         g1 = g['g1']
-        self.assertEqual_w(g1(self.space, w('bar')), w('foobar'))
+        self.space.eq_w(g1(self.space, w('bar')), w('foobar'))
 
     def test_exportall(self):
         w = self.space.wrap
@@ -109,8 +102,4 @@
 """ in g
         gateway.exportall(g, temporary=True)
         g1 = gateway.app2interp_temp(g['app_g1'])
-        self.assertEqual_w(g1(self.space, w('bar')), w('foobar'))
-
-
-if __name__ == '__main__':
-    testit.main()
+        self.space.eq_w(g1(self.space, w('bar')), w('foobar'))

Modified: pypy/branch/src-pytest/pypy/interpreter/test/test_main.py
==============================================================================
--- pypy/branch/src-pytest/pypy/interpreter/test/test_main.py	(original)
+++ pypy/branch/src-pytest/pypy/interpreter/test/test_main.py	Sat Jan  8 15:05:37 2005
@@ -1,11 +1,9 @@
-import unittest
 import autopath
 from cStringIO import StringIO
-from pypy.tool.udir import udir
 
-from pypy.tool import testit
+import py 
+from pypy.tool.udir import udir
 from pypy.interpreter.baseobjspace import OperationError
-
 from pypy.interpreter import main
 
 testcode = """\
@@ -18,9 +16,7 @@
 
 testresultoutput = '11\n'
 
-
-def checkoutput(expected_output,f,*args):
-    space = testit.objspace()
+def checkoutput(space, expected_output,f,*args):
     w_sys = space.get_builtin_module("sys")
     w_oldout = space.getattr(w_sys, space.wrap("stdout"))
     capturefn = udir.join('capturefile')
@@ -33,30 +29,26 @@
     capturefile.close() 
     return capturefn.read() == expected_output
 
-testfn = 'tmp_hello_world.py'
 
-class TestMain(testit.TestCase):
+testfn = 'tmp_hello_world.py'
 
-    def setUp(self):
-        self.space = testit.objspace()
+class TestMain: 
+    def setup_class(cls):
         ofile = open(testfn, 'w')
         ofile.write(testcode)
         ofile.close()
 
-    def tearDown(self):
+    def teardown_class(cls):
         import os
         os.remove(testfn)
 
     def test_run_file(self):
-        self.assert_(checkoutput(testresultoutput,main.run_file,testfn))
+        assert checkoutput(self.space, testresultoutput,main.run_file,testfn)
 
     def test_run_string(self):
-        self.assert_(checkoutput(testresultoutput,
-                                 main.run_string,testcode,testfn))
+        assert checkoutput(self.space, testresultoutput,
+                                 main.run_string,testcode,testfn)
 
     def test_eval_string(self):
         w_x = main.eval_string('2+2', space=self.space)
-        self.assertEqual_w(w_x, self.space.wrap(4))
-
-if __name__ == '__main__':
-    testit.main()
+        self.space.eq_w(w_x, self.space.wrap(4))

Modified: pypy/branch/src-pytest/pypy/interpreter/test/test_module.py
==============================================================================
--- pypy/branch/src-pytest/pypy/interpreter/test/test_module.py	(original)
+++ pypy/branch/src-pytest/pypy/interpreter/test/test_module.py	Sat Jan  8 15:05:37 2005
@@ -1,47 +1,39 @@
 
 import autopath
-from pypy.tool import testit
 from pypy.interpreter.module import Module
 
-
-class TestModule(testit.IntTestCase):
-    def setUp(self):
-        self.space = testit.objspace()
-        self.m = Module(self.space, self.space.wrap('m'))
+class TestModule: 
+    def setup_class(cls):
+        cls.m = Module(cls.space, cls.space.wrap('m'))
+    def teardown_class(cls):
+        del cls.m 
 
     def test_name(self):
         w = self.space.wrap
         w_m = w(self.m)
-        self.assertEqual_w(self.space.getattr(w_m, w('__name__')), w('m'))
+        self.space.eq_w(self.space.getattr(w_m, w('__name__')), w('m'))
 
     def test_attr(self):
         w = self.space.wrap
         w_m = w(self.m)
         self.space.setattr(w_m, w('x'), w(15))
-        self.assertEqual_w(self.space.getattr(w_m, w('x')), w(15))
+        self.space.eq_w(self.space.getattr(w_m, w('x')), w(15))
         self.space.delattr(w_m, w('x'))
-        self.assertRaises_w(self.space.w_AttributeError,
+        self.space.raises_w(self.space.w_AttributeError,
                             self.space.delattr, w_m, w('x'))
 
-class Test_ModuleObject(testit.AppTestCase):
-
-    def setUp(self):
-        self.space = testit.objspace()
-        
+class AppTest_ModuleObject: 
     def test_attr(self):
         m = __import__('__builtin__')
         m.x = 15
-        self.assertEqual(m.x, 15)
-        self.assertEqual(getattr(m, 'x'), 15)
+        assert m.x == 15
+        assert getattr(m, 'x') == 15
         setattr(m, 'x', 23)
-        self.assertEqual(m.x, 23)
-        self.assertEqual(getattr(m, 'x'), 23)
+        assert m.x == 23
+        assert getattr(m, 'x') == 23
         del m.x
-        self.assertRaises(AttributeError, getattr, m, 'x')
+        raises(AttributeError, getattr, m, 'x')
         m.x = 15
         delattr(m, 'x')
-        self.assertRaises(AttributeError, getattr, m, 'x')
-        self.assertRaises(AttributeError, delattr, m, 'x')
-
-if __name__ == '__main__':
-    testit.main()
+        raises(AttributeError, getattr, m, 'x')
+        raises(AttributeError, delattr, m, 'x')



More information about the Pypy-commit mailing list