[Python-checkins] cpython (2.7): #11420: make test suite pass with -B/DONTWRITEBYTECODE set. Initial patch by

ezio.melotti python-checkins at python.org
Sat Mar 16 20:50:38 CET 2013


http://hg.python.org/cpython/rev/c70746a0291f
changeset: 82689:c70746a0291f
branch: 2.7
parent: 82670:274e68e2a5a6
user: Ezio Melotti <ezio.melotti at gmail.com>
date: Sat Mar 16 20:04:44 2013 +0200
summary:
 #11420: make test suite pass with -B/DONTWRITEBYTECODE set. Initial patch by Thomas Wouters.
files:
 Lib/distutils/tests/test_bdist_dumb.py | 5 +-
 Lib/test/test_import.py | 13 +++-
 Lib/test/test_runpy.py | 37 +++++++------
 Misc/NEWS | 3 +
 4 files changed, 36 insertions(+), 22 deletions(-)
diff --git a/Lib/distutils/tests/test_bdist_dumb.py b/Lib/distutils/tests/test_bdist_dumb.py
--- a/Lib/distutils/tests/test_bdist_dumb.py
+++ b/Lib/distutils/tests/test_bdist_dumb.py
@@ -87,8 +87,9 @@
 fp.close()
 
 contents = sorted(os.path.basename(fn) for fn in contents)
- wanted = ['foo-0.1-py%s.%s.egg-info' % sys.version_info[:2],
- 'foo.py', 'foo.pyc']
+ wanted = ['foo-0.1-py%s.%s.egg-info' % sys.version_info[:2], 'foo.py']
+ if not sys.dont_write_bytecode:
+ wanted.append('foo.pyc')
 self.assertEqual(contents, sorted(wanted))
 
 def test_finalize_options(self):
diff --git a/Lib/test/test_import.py b/Lib/test/test_import.py
--- a/Lib/test/test_import.py
+++ b/Lib/test/test_import.py
@@ -88,7 +88,8 @@
 unlink(source)
 
 try:
- imp.reload(mod)
+ if not sys.dont_write_bytecode:
+ imp.reload(mod)
 except ImportError, err:
 self.fail("import from .pyc/.pyo failed: %s" % err)
 finally:
@@ -105,7 +106,10 @@
 finally:
 del sys.path[0]
 
- @unittest.skipUnless(os.name == 'posix', "test meaningful only on posix systems")
+ @unittest.skipUnless(os.name == 'posix',
+ "test meaningful only on posix systems")
+ @unittest.skipIf(sys.dont_write_bytecode,
+ "test meaningful only when writing bytecode")
 def test_execute_bit_not_copied(self):
 # Issue 6070: under posix .pyc files got their execute bit set if
 # the .py file had the execute bit set, but they aren't executable.
@@ -132,6 +136,8 @@
 unload(TESTFN)
 del sys.path[0]
 
+ @unittest.skipIf(sys.dont_write_bytecode,
+ "test meaningful only when writing bytecode")
 def test_rewrite_pyc_with_read_only_source(self):
 # Issue 6074: a long time ago on posix, and more recently on Windows,
 # a read only source file resulted in a read only pyc file, which
@@ -441,7 +447,8 @@
 self.assertEqual(mod.func_filename, self.file_name)
 del sys.modules[self.module_name]
 mod = self.import_module()
- self.assertEqual(mod.module_filename, self.compiled_name)
+ if not sys.dont_write_bytecode:
+ self.assertEqual(mod.module_filename, self.compiled_name)
 self.assertEqual(mod.code_filename, self.file_name)
 self.assertEqual(mod.func_filename, self.file_name)
 
diff --git a/Lib/test/test_runpy.py b/Lib/test/test_runpy.py
--- a/Lib/test/test_runpy.py
+++ b/Lib/test/test_runpy.py
@@ -170,11 +170,12 @@
 del d1 # Ensure __loader__ entry doesn't keep file open
 __import__(mod_name)
 os.remove(mod_fname)
- if verbose: print "Running from compiled:", mod_name
- d2 = run_module(mod_name) # Read from bytecode
- self.assertIn("x", d2)
- self.assertTrue(d2["x"] == 1)
- del d2 # Ensure __loader__ entry doesn't keep file open
+ if not sys.dont_write_bytecode:
+ if verbose: print "Running from compiled:", mod_name
+ d2 = run_module(mod_name) # Read from bytecode
+ self.assertIn("x", d2)
+ self.assertTrue(d2["x"] == 1)
+ del d2 # Ensure __loader__ entry doesn't keep file open
 finally:
 self._del_pkg(pkg_dir, depth, mod_name)
 if verbose: print "Module executed successfully"
@@ -192,11 +193,12 @@
 del d1 # Ensure __loader__ entry doesn't keep file open
 __import__(mod_name)
 os.remove(mod_fname)
- if verbose: print "Running from compiled:", pkg_name
- d2 = run_module(pkg_name) # Read from bytecode
- self.assertIn("x", d2)
- self.assertTrue(d2["x"] == 1)
- del d2 # Ensure __loader__ entry doesn't keep file open
+ if not sys.dont_write_bytecode:
+ if verbose: print "Running from compiled:", pkg_name
+ d2 = run_module(pkg_name) # Read from bytecode
+ self.assertIn("x", d2)
+ self.assertTrue(d2["x"] == 1)
+ del d2 # Ensure __loader__ entry doesn't keep file open
 finally:
 self._del_pkg(pkg_dir, depth, pkg_name)
 if verbose: print "Package executed successfully"
@@ -246,13 +248,14 @@
 del d1 # Ensure __loader__ entry doesn't keep file open
 __import__(mod_name)
 os.remove(mod_fname)
- if verbose: print "Running from compiled:", mod_name
- d2 = run_module(mod_name, run_name=run_name) # Read from bytecode
- self.assertIn("__package__", d2)
- self.assertTrue(d2["__package__"] == pkg_name)
- self.assertIn("sibling", d2)
- self.assertIn("nephew", d2)
- del d2 # Ensure __loader__ entry doesn't keep file open
+ if not sys.dont_write_bytecode:
+ if verbose: print "Running from compiled:", mod_name
+ d2 = run_module(mod_name, run_name=run_name) # Read from bytecode
+ self.assertIn("__package__", d2)
+ self.assertTrue(d2["__package__"] == pkg_name)
+ self.assertIn("sibling", d2)
+ self.assertIn("nephew", d2)
+ del d2 # Ensure __loader__ entry doesn't keep file open
 finally:
 self._del_pkg(pkg_dir, depth, mod_name)
 if verbose: print "Module executed successfully"
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -818,6 +818,9 @@
 Tests
 -----
 
+- Issue #11420: make test suite pass with -B/DONTWRITEBYTECODE set.
+ Initial patch by Thomas Wouters.
+
 - Issue #17299: Add test coverage for cPickle with file objects and general IO
 objects. Original patch by Aman Shah.
 
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /