[pypy-svn] r41253 - pypy/dist/pypy/lib/app_test

hpk at codespeak.net hpk at codespeak.net
Sat Mar 24 19:29:58 CET 2007


Author: hpk
Date: Sat Mar 24 19:29:57 2007
New Revision: 41253

Modified:
   pypy/dist/pypy/lib/app_test/sample_aop_code.py
   pypy/dist/pypy/lib/app_test/test_aop.py
Log:
avoid writing to current directories, cleanup test setup


Modified: pypy/dist/pypy/lib/app_test/sample_aop_code.py
==============================================================================
--- pypy/dist/pypy/lib/app_test/sample_aop_code.py	(original)
+++ pypy/dist/pypy/lib/app_test/sample_aop_code.py	Sat Mar 24 19:29:57 2007
@@ -1,3 +1,5 @@
+import py 
+
 code = """
 def foo(b, c):
     '''
@@ -41,18 +43,15 @@
 def _make_filename(name):
     if not name.endswith('.py'):
         name += ".py"
-    return osp.join(osp.dirname(__file__), name)
+    base = py.test.ensuretemp("aop_test")
+    return base.join(name)
 
-def write_module(name):
-    clean_module(name)
-    f = open(_make_filename(name), 'w')
+def _write_module(name):
+    f = _make_filename(name).open('w')
     f.write(code)
     f.close()
 
-def clean_module(name):
-    name = _make_filename(name)
-    if os.path.isfile(name):
-        os.unlink(name)
-    if os.path.isfile(name+'c'):
-        os.unlink(name+'c')
-
+def import_(name):
+    _write_module(name)
+    p = _make_filename(name)
+    return p.pyimport()

Modified: pypy/dist/pypy/lib/app_test/test_aop.py
==============================================================================
--- pypy/dist/pypy/lib/app_test/test_aop.py	(original)
+++ pypy/dist/pypy/lib/app_test/test_aop.py	Sat Mar 24 19:29:57 2007
@@ -151,7 +151,6 @@
         from  aop import PointCut, Aspect, before
         from app_test import sample_aop_code
         __aop__._clear_all()
-        sample_aop_code.write_module('aop_before_execution')
         
         class AspectTest:
             __metaclass__ = Aspect 
@@ -168,20 +167,19 @@
         assert __aop__.advices == [(aspect, AspectTest.advice_before_execution)] 
         assert not aspect.executed
 
-        from app_test import aop_before_execution
+        aop_before_execution = sample_aop_code.import_('aop_before_execution')
+
         assert  aspect.executed == 0
         answ = aop_before_execution.foo(1,2)
         assert aspect.executed == 1
         assert aspect.argnames == ['b', 'c']
         assert aspect.flags == 0
         assert answ == 47
-        sample_aop_code.clean_module('aop_before_execution')
 
     def test_aspect_before_meth_execution(self):
         from  aop import PointCut, Aspect, before
         from app_test import sample_aop_code
         __aop__._clear_all()
-        sample_aop_code.write_module('aop_before_meth_execution')
         
         class AspectTest:
             __metaclass__ = Aspect 
@@ -198,20 +196,19 @@
         assert __aop__.advices == [(aspect, AspectTest.advice_before_meth_execution)] 
         assert not aspect.executed
 
-        from app_test import aop_before_meth_execution
+        aop_before_meth_execution = sample_aop_code.import_(
+            'aop_before_meth_execution')
         assert  aspect.executed == 0
         answ = aop_before_meth_execution.truc()
         assert aspect.executed == 1
         assert aspect.argnames == ['self', 'b']
         assert aspect.flags == 0
         assert answ == 7
-        sample_aop_code.clean_module('aop_before_meth_execution')
 
     def test_simple_aspect_after_execution(self):
         from  aop import PointCut, Aspect, after
         from app_test import sample_aop_code
         __aop__._clear_all()
-        sample_aop_code.write_module('aop_after_execution')
         class AspectTest:
             __metaclass__ = Aspect 
             def __init__(self):
@@ -224,18 +221,16 @@
         aspect = AspectTest()
         assert __aop__.advices == [(aspect, AspectTest.advice_after_execution)] 
         assert not aspect.executed
-        from app_test import aop_after_execution
+        aop_after_execution = sample_aop_code.import_('aop_after_execution')
         assert aspect.executed == 0
         answ = aop_after_execution.foo(1,2)
         assert aspect.executed == 1
         assert answ == 47
-        sample_aop_code.clean_module('aop_after_execution')
 
     def test_simple_aspect_around_execution(self):
         from  aop import PointCut, Aspect, around
         from app_test import sample_aop_code
         __aop__._clear_all()
-        sample_aop_code.write_module('aop_around_execution')
         class AspectTest:
             __metaclass__ = Aspect 
             def __init__(self):
@@ -253,7 +248,7 @@
                 return tjp.result()
         
         aspect = AspectTest()
-        from app_test import aop_around_execution
+        aop_around_execution = sample_aop_code.import_('aop_around_execution')
         assert aspect.executed_before == 0
         assert aspect.executed_after == 0
         answ = aop_around_execution.foo(1,2)
@@ -261,7 +256,6 @@
         assert aspect.executed_after == 1
         assert aspect.result == 47
         assert answ == 47
-        sample_aop_code.clean_module('aop_around_execution')
         
 
 class AppTestWeavingAtCall(object):
@@ -269,7 +263,6 @@
         from  aop import PointCut, Aspect, before
         from app_test import sample_aop_code
         __aop__._clear_all()
-        sample_aop_code.write_module('aop_before_call')
         
         class AspectTest:
             __metaclass__ = Aspect 
@@ -287,18 +280,16 @@
         assert __aop__.advices == [(aspect, AspectTest.advice_before_call)] 
         assert not aspect.executed
 
-        from app_test import aop_before_call
+        aop_before_call = sample_aop_code.import_('aop_before_call')
         assert  aspect.executed == 0
         answ = aop_before_call.foo(1,2)
         assert aspect.executed == 1
         assert answ == 47
-        sample_aop_code.clean_module('aop_before_call')
 
     def test_simple_aspect_after_call(self):
         from  aop import PointCut, Aspect, after
         from app_test import sample_aop_code
         __aop__._clear_all()
-        sample_aop_code.write_module('aop_after_call')
         
         class AspectTest:
             __metaclass__ = Aspect 
@@ -320,20 +311,18 @@
         assert __aop__.advices == [(aspect, AspectTest.advice_after_call)] 
         assert not aspect.executed
 
-        from app_test import aop_after_call
+        aop_after_call = sample_aop_code.import_('aop_after_call')
         assert not aspect.executed 
         answ = aop_after_call.foo(1,2)
         assert aspect.executed 
         assert answ == 47
         assert aspect.result == 42
-        sample_aop_code.clean_module('aop_after_call')
 
     
     def test_simple_aspect_around_call(self):
         from  aop import PointCut, Aspect, around
         from app_test import sample_aop_code
         __aop__._clear_all()
-        sample_aop_code.write_module('aop_around_call')
         class AspectTest:
             __metaclass__ = Aspect 
             def __init__(self):
@@ -351,7 +340,7 @@
                 return tjp.result()
         
         aspect = AspectTest()
-        from app_test import aop_around_call
+        aop_around_call = sample_aop_code.import_('aop_around_call')
         assert aspect.executed_before == 0
         assert aspect.executed_after == 0
         answ = aop_around_call.foo(1,2)
@@ -359,8 +348,6 @@
         assert aspect.executed_after == 1
         assert aspect.result == 42
         assert answ == 47
-        sample_aop_code.clean_module('aop_around_call')
-
 
 
 class AppTestWeavingIntroduce(object):
@@ -368,7 +355,6 @@
         from  aop import PointCut, Aspect, introduce
         from app_test import sample_aop_code
         __aop__._clear_all()
-        sample_aop_code.write_module('aop_introduce')
         class AspectTest:
             __metaclass__ = Aspect 
             @introduce(PointCut(klass='Mumble'))
@@ -376,7 +362,7 @@
                 return it.p*a+b
             
         aspect = AspectTest()
-        from app_test import aop_introduce
+        aop_introduce = sample_aop_code.import_('aop_introduce')
         c = aop_introduce.Mumble(2)
         try:
             answ = c.newmethod(1,3)



More information about the Pypy-commit mailing list