summaryrefslogtreecommitdiffstats
path: root/Lib/distutils/tests
diff options
context:
space:
mode:
authorÉric Araujo <merwok@netwok.org>2010-11-06 02:58:56 (GMT)
committerÉric Araujo <merwok@netwok.org>2010-11-06 02:58:56 (GMT)
commitc6d7ead095fdd3b1ee82a338d4ffd88b2c2c2fce (patch)
tree87bd3d5006d1f4050f64a44c59910461747f08dc /Lib/distutils/tests
parent997980fe13ae7952665da56b122aeff9ea8fa6df (diff)
downloadcpython-c6d7ead095fdd3b1ee82a338d4ffd88b2c2c2fce.zip
cpython-c6d7ead095fdd3b1ee82a338d4ffd88b2c2c2fce.tar.gz
cpython-c6d7ead095fdd3b1ee82a338d4ffd88b2c2c2fce.tar.bz2
Merged revisions 86223-86224,86226,86234 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r86223 | eric.araujo | 2010-11-06 00:51:56 +0100 (sam., 06 nov. 2010) | 2 lines Always close files in distutils code and tests (#10252). ........ r86224 | eric.araujo | 2010-11-06 00:58:34 +0100 (sam., 06 nov. 2010) | 2 lines Add missing entry for r86223. ........ r86226 | eric.araujo | 2010-11-06 00:59:32 +0100 (sam., 06 nov. 2010) | 2 lines Of course, I forgot one file in r86223. ........ r86234 | eric.araujo | 2010-11-06 03:10:32 +0100 (sam., 06 nov. 2010) | 2 lines Also close file descriptors from os.popen and subprocess.Popen ........
Diffstat (limited to 'Lib/distutils/tests')
-rw-r--r--Lib/distutils/tests/test_build_py.py12
-rw-r--r--Lib/distutils/tests/test_build_scripts.py6
-rw-r--r--Lib/distutils/tests/test_config.py8
-rw-r--r--Lib/distutils/tests/test_core.py6
-rw-r--r--Lib/distutils/tests/test_dir_util.py6
-rw-r--r--Lib/distutils/tests/test_dist.py40
-rw-r--r--Lib/distutils/tests/test_file_util.py6
-rw-r--r--Lib/distutils/tests/test_install.py5
-rw-r--r--Lib/distutils/tests/test_install_scripts.py6
-rw-r--r--Lib/distutils/tests/test_msvc9compiler.py14
-rw-r--r--Lib/distutils/tests/test_register.py8
-rw-r--r--Lib/distutils/tests/test_sdist.py8
-rw-r--r--Lib/distutils/tests/test_sysconfig.py16
-rw-r--r--Lib/distutils/tests/test_text_file.py52
14 files changed, 126 insertions, 67 deletions
diff --git a/Lib/distutils/tests/test_build_py.py b/Lib/distutils/tests/test_build_py.py
index 3e45f6e..8a69aaa 100644
--- a/Lib/distutils/tests/test_build_py.py
+++ b/Lib/distutils/tests/test_build_py.py
@@ -19,11 +19,15 @@ class BuildPyTestCase(support.TempdirManager,
def test_package_data(self):
sources = self.mkdtemp()
f = open(os.path.join(sources, "__init__.py"), "w")
- f.write("# Pretend this is a package.")
- f.close()
+ try:
+ f.write("# Pretend this is a package.")
+ finally:
+ f.close()
f = open(os.path.join(sources, "README.txt"), "w")
- f.write("Info about this package")
- f.close()
+ try:
+ f.write("Info about this package")
+ finally:
+ f.close()
destination = self.mkdtemp()
diff --git a/Lib/distutils/tests/test_build_scripts.py b/Lib/distutils/tests/test_build_scripts.py
index b1d2d07..85b0400 100644
--- a/Lib/distutils/tests/test_build_scripts.py
+++ b/Lib/distutils/tests/test_build_scripts.py
@@ -71,8 +71,10 @@ class BuildScriptsTestCase(support.TempdirManager,
def write_script(self, dir, name, text):
f = open(os.path.join(dir, name), "w")
- f.write(text)
- f.close()
+ try:
+ f.write(text)
+ finally:
+ f.close()
def test_version_int(self):
source = self.mkdtemp()
diff --git a/Lib/distutils/tests/test_config.py b/Lib/distutils/tests/test_config.py
index 71c6367..6a45a32 100644
--- a/Lib/distutils/tests/test_config.py
+++ b/Lib/distutils/tests/test_config.py
@@ -105,8 +105,12 @@ class PyPIRCCommandTestCase(support.TempdirManager,
self.assertTrue(not os.path.exists(rc))
cmd._store_pypirc('tarek', 'xxx')
self.assertTrue(os.path.exists(rc))
- content = open(rc).read()
- self.assertEquals(content, WANTED)
+ f = open(rc)
+ try:
+ content = f.read()
+ self.assertEquals(content, WANTED)
+ finally:
+ f.close()
def test_suite():
return unittest.makeSuite(PyPIRCCommandTestCase)
diff --git a/Lib/distutils/tests/test_core.py b/Lib/distutils/tests/test_core.py
index b478fa6..e937b45 100644
--- a/Lib/distutils/tests/test_core.py
+++ b/Lib/distutils/tests/test_core.py
@@ -52,7 +52,11 @@ class CoreTestCase(support.EnvironGuard, unittest.TestCase):
shutil.rmtree(path)
def write_setup(self, text, path=test.support.TESTFN):
- open(path, "w").write(text)
+ f = open(path, "w")
+ try:
+ f.write(text)
+ finally:
+ f.close()
return path
def test_run_setup_provides_file(self):
diff --git a/Lib/distutils/tests/test_dir_util.py b/Lib/distutils/tests/test_dir_util.py
index a1647fb..aa9f9eb 100644
--- a/Lib/distutils/tests/test_dir_util.py
+++ b/Lib/distutils/tests/test_dir_util.py
@@ -88,8 +88,10 @@ class DirUtilTestCase(support.TempdirManager, unittest.TestCase):
mkpath(self.target, verbose=0)
a_file = os.path.join(self.target, 'ok.txt')
f = open(a_file, 'w')
- f.write('some content')
- f.close()
+ try:
+ f.write('some content')
+ finally:
+ f.close()
wanted = ['copying %s -> %s' % (a_file, self.target2)]
copy_tree(self.target, self.target2, verbose=1)
diff --git a/Lib/distutils/tests/test_dist.py b/Lib/distutils/tests/test_dist.py
index 3b7637f..f9c5a4f 100644
--- a/Lib/distutils/tests/test_dist.py
+++ b/Lib/distutils/tests/test_dist.py
@@ -80,29 +80,29 @@ class DistributionTestCase(support.LoggingSilencer,
def test_command_packages_configfile(self):
sys.argv.append("build")
+ self.addCleanup(os.unlink, TESTFN)
f = open(TESTFN, "w")
try:
print("[global]", file=f)
print("command_packages = foo.bar, splat", file=f)
+ finally:
f.close()
- d = self.create_distribution([TESTFN])
- self.assertEqual(d.get_command_packages(),
- ["distutils.command", "foo.bar", "splat"])
-
- # ensure command line overrides config:
- sys.argv[1:] = ["--command-packages", "spork", "build"]
- d = self.create_distribution([TESTFN])
- self.assertEqual(d.get_command_packages(),
- ["distutils.command", "spork"])
-
- # Setting --command-packages to '' should cause the default to
- # be used even if a config file specified something else:
- sys.argv[1:] = ["--command-packages", "", "build"]
- d = self.create_distribution([TESTFN])
- self.assertEqual(d.get_command_packages(), ["distutils.command"])
- finally:
- os.unlink(TESTFN)
+ d = self.create_distribution([TESTFN])
+ self.assertEqual(d.get_command_packages(),
+ ["distutils.command", "foo.bar", "splat"])
+
+ # ensure command line overrides config:
+ sys.argv[1:] = ["--command-packages", "spork", "build"]
+ d = self.create_distribution([TESTFN])
+ self.assertEqual(d.get_command_packages(),
+ ["distutils.command", "spork"])
+
+ # Setting --command-packages to '' should cause the default to
+ # be used even if a config file specified something else:
+ sys.argv[1:] = ["--command-packages", "", "build"]
+ d = self.create_distribution([TESTFN])
+ self.assertEqual(d.get_command_packages(), ["distutils.command"])
def test_empty_options(self):
# an empty options dictionary should not stay in the
@@ -261,8 +261,10 @@ class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
temp_dir = self.mkdtemp()
user_filename = os.path.join(temp_dir, user_filename)
f = open(user_filename, 'w')
- f.write('.')
- f.close()
+ try:
+ f.write('.')
+ finally:
+ f.close()
try:
dist = Distribution()
diff --git a/Lib/distutils/tests/test_file_util.py b/Lib/distutils/tests/test_file_util.py
index fac4a5d..74618b5 100644
--- a/Lib/distutils/tests/test_file_util.py
+++ b/Lib/distutils/tests/test_file_util.py
@@ -31,8 +31,10 @@ class FileUtilTestCase(support.TempdirManager, unittest.TestCase):
def test_move_file_verbosity(self):
f = open(self.source, 'w')
- f.write('some content')
- f.close()
+ try:
+ f.write('some content')
+ finally:
+ f.close()
move_file(self.source, self.target, verbose=0)
wanted = []
diff --git a/Lib/distutils/tests/test_install.py b/Lib/distutils/tests/test_install.py
index 76fa02a..bc407cf 100644
--- a/Lib/distutils/tests/test_install.py
+++ b/Lib/distutils/tests/test_install.py
@@ -182,8 +182,11 @@ class InstallTestCase(support.TempdirManager,
# let's check the RECORD file was created with one
# line (the egg info file)
- with open(cmd.record) as f:
+ f = open(cmd.record)
+ try:
self.assertEquals(len(f.readlines()), 1)
+ finally:
+ f.close()
def test_debug_mode(self):
# this covers the code called when DEBUG is set
diff --git a/Lib/distutils/tests/test_install_scripts.py b/Lib/distutils/tests/test_install_scripts.py
index b7eb625..08360d2 100644
--- a/Lib/distutils/tests/test_install_scripts.py
+++ b/Lib/distutils/tests/test_install_scripts.py
@@ -42,8 +42,10 @@ class InstallScriptsTestCase(support.TempdirManager,
def write_script(name, text):
expected.append(name)
f = open(os.path.join(source, name), "w")
- f.write(text)
- f.close()
+ try:
+ f.write(text)
+ finally:
+ f.close()
write_script("script1.py", ("#! /usr/bin/env python2.3\n"
"# bogus script w/ Python sh-bang\n"
diff --git a/Lib/distutils/tests/test_msvc9compiler.py b/Lib/distutils/tests/test_msvc9compiler.py
index f1da843..40cb8be 100644
--- a/Lib/distutils/tests/test_msvc9compiler.py
+++ b/Lib/distutils/tests/test_msvc9compiler.py
@@ -113,17 +113,21 @@ class msvc9compilerTestCase(support.TempdirManager,
tempdir = self.mkdtemp()
manifest = os.path.join(tempdir, 'manifest')
f = open(manifest, 'w')
- f.write(_MANIFEST)
- f.close()
+ try:
+ f.write(_MANIFEST)
+ finally:
+ f.close()
compiler = MSVCCompiler()
compiler._remove_visual_c_ref(manifest)
# see what we got
f = open(manifest)
- # removing trailing spaces
- content = '\n'.join([line.rstrip() for line in f.readlines()])
- f.close()
+ try:
+ # removing trailing spaces
+ content = '\n'.join([line.rstrip() for line in f.readlines()])
+ finally:
+ f.close()
# makes sure the manifest was properly cleaned
self.assertEquals(content, _CLEANED_MANIFEST)
diff --git a/Lib/distutils/tests/test_register.py b/Lib/distutils/tests/test_register.py
index 7d0ac9e..3b80b6d 100644
--- a/Lib/distutils/tests/test_register.py
+++ b/Lib/distutils/tests/test_register.py
@@ -118,8 +118,12 @@ class RegisterTestCase(PyPIRCCommandTestCase):
self.assertTrue(os.path.exists(self.rc))
# with the content similar to WANTED_PYPIRC
- content = open(self.rc).read()
- self.assertEquals(content, WANTED_PYPIRC)
+ f = open(self.rc)
+ try:
+ content = f.read()
+ self.assertEquals(content, WANTED_PYPIRC)
+ finally:
+ f.close()
# now let's make sure the .pypirc file generated
# really works : we shouldn't be asked anything
diff --git a/Lib/distutils/tests/test_sdist.py b/Lib/distutils/tests/test_sdist.py
index 209aa59..ad527c7 100644
--- a/Lib/distutils/tests/test_sdist.py
+++ b/Lib/distutils/tests/test_sdist.py
@@ -215,8 +215,12 @@ class SDistTestCase(PyPIRCCommandTestCase):
self.assertEquals(len(content), 11)
# checking the MANIFEST
- manifest = open(join(self.tmp_dir, 'MANIFEST')).read()
- self.assertEquals(manifest, MANIFEST % {'sep': os.sep})
+ f = open(join(self.tmp_dir, 'MANIFEST'))
+ try:
+ manifest = f.read()
+ self.assertEquals(manifest, MANIFEST % {'sep': os.sep})
+ finally:
+ f.close()
def test_metadata_check_option(self):
# testing the `medata-check` option
diff --git a/Lib/distutils/tests/test_sysconfig.py b/Lib/distutils/tests/test_sysconfig.py
index edc755e..78bce94 100644
--- a/Lib/distutils/tests/test_sysconfig.py
+++ b/Lib/distutils/tests/test_sysconfig.py
@@ -75,9 +75,11 @@ class SysconfigTestCase(support.EnvironGuard,
def test_parse_makefile_base(self):
self.makefile = TESTFN
fd = open(self.makefile, 'w')
- fd.write(r"CONFIG_ARGS= '--arg1=optarg1' 'ENV=LIB'" '\n')
- fd.write('VAR=$OTHER\nOTHER=foo')
- fd.close()
+ try:
+ fd.write(r"CONFIG_ARGS= '--arg1=optarg1' 'ENV=LIB'" '\n')
+ fd.write('VAR=$OTHER\nOTHER=foo')
+ finally:
+ fd.close()
d = sysconfig.parse_makefile(self.makefile)
self.assertEquals(d, {'CONFIG_ARGS': "'--arg1=optarg1' 'ENV=LIB'",
'OTHER': 'foo'})
@@ -85,9 +87,11 @@ class SysconfigTestCase(support.EnvironGuard,
def test_parse_makefile_literal_dollar(self):
self.makefile = TESTFN
fd = open(self.makefile, 'w')
- fd.write(r"CONFIG_ARGS= '--arg1=optarg1' 'ENV=\$$LIB'" '\n')
- fd.write('VAR=$OTHER\nOTHER=foo')
- fd.close()
+ try:
+ fd.write(r"CONFIG_ARGS= '--arg1=optarg1' 'ENV=\$$LIB'" '\n')
+ fd.write('VAR=$OTHER\nOTHER=foo')
+ finally:
+ fd.close()
d = sysconfig.parse_makefile(self.makefile)
self.assertEquals(d, {'CONFIG_ARGS': r"'--arg1=optarg1' 'ENV=\$LIB'",
'OTHER': 'foo'})
diff --git a/Lib/distutils/tests/test_text_file.py b/Lib/distutils/tests/test_text_file.py
index 00f083a..3093097 100644
--- a/Lib/distutils/tests/test_text_file.py
+++ b/Lib/distutils/tests/test_text_file.py
@@ -58,28 +58,46 @@ class TextFileTestCase(support.TempdirManager, unittest.TestCase):
finally:
out_file.close()
- in_file = TextFile (filename, strip_comments=0, skip_blanks=0,
- lstrip_ws=0, rstrip_ws=0)
- test_input (1, "no processing", in_file, result1)
+ in_file = TextFile(filename, strip_comments=0, skip_blanks=0,
+ lstrip_ws=0, rstrip_ws=0)
+ try:
+ test_input(1, "no processing", in_file, result1)
+ finally:
+ in_file.close()
- in_file = TextFile (filename, strip_comments=1, skip_blanks=0,
- lstrip_ws=0, rstrip_ws=0)
- test_input (2, "strip comments", in_file, result2)
+ in_file = TextFile(filename, strip_comments=1, skip_blanks=0,
+ lstrip_ws=0, rstrip_ws=0)
+ try:
+ test_input(2, "strip comments", in_file, result2)
+ finally:
+ in_file.close()
- in_file = TextFile (filename, strip_comments=0, skip_blanks=1,
- lstrip_ws=0, rstrip_ws=0)
- test_input (3, "strip blanks", in_file, result3)
+ in_file = TextFile(filename, strip_comments=0, skip_blanks=1,
+ lstrip_ws=0, rstrip_ws=0)
+ try:
+ test_input(3, "strip blanks", in_file, result3)
+ finally:
+ in_file.close()
- in_file = TextFile (filename)
- test_input (4, "default processing", in_file, result4)
+ in_file = TextFile(filename)
+ try:
+ test_input(4, "default processing", in_file, result4)
+ finally:
+ in_file.close()
- in_file = TextFile (filename, strip_comments=1, skip_blanks=1,
- join_lines=1, rstrip_ws=1)
- test_input (5, "join lines without collapsing", in_file, result5)
+ in_file = TextFile(filename, strip_comments=1, skip_blanks=1,
+ join_lines=1, rstrip_ws=1)
+ try:
+ test_input(5, "join lines without collapsing", in_file, result5)
+ finally:
+ in_file.close()
- in_file = TextFile (filename, strip_comments=1, skip_blanks=1,
- join_lines=1, rstrip_ws=1, collapse_join=1)
- test_input (6, "join lines with collapsing", in_file, result6)
+ in_file = TextFile(filename, strip_comments=1, skip_blanks=1,
+ join_lines=1, rstrip_ws=1, collapse_join=1)
+ try:
+ test_input(6, "join lines with collapsing", in_file, result6)
+ finally:
+ in_file.close()
def test_suite():
return unittest.makeSuite(TextFileTestCase)