diff Lib/importlib/test/source/util.py @ 53996:0495bc47cd08

Tests for case-senstivity were not being skipped for darwin when installed on a case-sensitive filesystems -- which is not the default case. Along the way also fixed the skipping of tests when sys.dont_write_bytecode is true. Closes issue #5442 again.
author Brett Cannon <bcannon@gmail.com>
date Mon, 11 May 2009 01:47:11 +0000
parents c06f02a5e962
children 93c752875033 d3a81051663b
line wrap: on
line diff
--- a/Lib/importlib/test/source/util.py	Sun May 10 23:43:14 2009 +0000
+++ b/Lib/importlib/test/source/util.py	Mon May 11 01:47:11 2009 +0000
@@ -9,32 +9,23 @@
 from test import support
 
 
-def writes_bytecode(fxn):
-    """Decorator to protect sys.dont_write_bytecode from mutation."""
+def writes_bytecode_files(fxn):
+    """Decorator to protect sys.dont_write_bytecode from mutation and to skip
+    tests that require it to be set to False."""
+    if sys.dont_write_bytecode:
+        return lambda *args, **kwargs: None
     @functools.wraps(fxn)
     def wrapper(*args, **kwargs):
         original = sys.dont_write_bytecode
         sys.dont_write_bytecode = False
-        to_return = fxn(*args, **kwargs)
-        sys.dont_write_bytecode = original
+        try:
+            to_return = fxn(*args, **kwargs)
+        finally:
+            sys.dont_write_bytecode = original
         return to_return
     return wrapper
 
 
-def writes_bytecode_files(fxn):
-    """Decorator that returns the function if writing bytecode is enabled, else
-    a stub function that accepts anything and simply returns None."""
-    if sys.dont_write_bytecode:
-        return lambda *args, **kwargs: None
-    else:
-        @functools.wraps(fxn)
-        def wrapper(*args, **kwargs):
-            to_return = fxn(*args, **kwargs)
-            sys.dont_write_bytecode = False
-            return to_return
-        return wrapper
-
-
 def bytecode_path(source_path):
     for suffix, _, type_ in imp.get_suffixes():
         if type_ == imp.PY_COMPILED: