[pypy-svn] r78703 - in pypy/branch/fast-forward/pypy/module/_warnings: . test

afa at codespeak.net afa at codespeak.net
Thu Nov 4 21:21:32 CET 2010


Author: afa
Date: Thu Nov  4 21:21:18 2010
New Revision: 78703

Modified:
   pypy/branch/fast-forward/pypy/module/_warnings/interp_warnings.py
   pypy/branch/fast-forward/pypy/module/_warnings/test/test_warnings.py
Log:
Fixes in the _warnings module


Modified: pypy/branch/fast-forward/pypy/module/_warnings/interp_warnings.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/_warnings/interp_warnings.py	(original)
+++ pypy/branch/fast-forward/pypy/module/_warnings/interp_warnings.py	Thu Nov  4 21:21:18 2010
@@ -72,7 +72,7 @@
     # Setup globals and lineno
     ec = space.getexecutioncontext()
     frame = ec.gettopframe_nohidden()
-    while frame and stacklevel:
+    while frame and stacklevel > 1:
         frame = ec.getnextframe_nohidden(frame)
         stacklevel -= 1
     if frame:
@@ -106,8 +106,8 @@
         if not e.match(space, space.w_KeyError):
             raise
         if space.str_w(w_module) == '__main__':
-            w_argv = space.sys.get('argv')
-            if space.int_w(space.len(w_argv)) > 0:
+            w_argv = space.sys.getdictvalue(space, 'argv')
+            if w_argv and space.int_w(space.len(w_argv)) > 0:
                 w_filename = space.getitem(w_argv, space.wrap(0))
                 if not space.is_true(w_filename):
                     w_filename = space.wrap('__main__')
@@ -157,7 +157,7 @@
     return action, None
 
 def get_default_action(space):
-    w_action = get_warnings_attr(space, "default_action");
+    w_action = get_warnings_attr(space, "defaultaction");
     if w_action is None:
         return space.str_w(space.fromcache(State).w_default_action)
 

Modified: pypy/branch/fast-forward/pypy/module/_warnings/test/test_warnings.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/_warnings/test/test_warnings.py	(original)
+++ pypy/branch/fast-forward/pypy/module/_warnings/test/test_warnings.py	Thu Nov  4 21:21:18 2010
@@ -25,3 +25,16 @@
         _warnings.warn_explicit("some message", Warning,
                                 "<string>", 1, module_globals=globals())
 
+    def test_default_action(self):
+        import warnings, _warnings
+        warnings.defaultaction = 'ignore'
+        warnings.resetwarnings()
+        with warnings.catch_warnings(record=True) as w:
+            __warningregistry__ = {}
+            _warnings.warn_explicit("message", UserWarning, "<test>", 44,
+                                    registry={})
+            assert len(w) == 0
+        warnings.defaultaction = 'default'
+
+
+



More information about the Pypy-commit mailing list