summaryrefslogtreecommitdiffstats
path: root/Lib/distutils/tests/test_dist.py
diff options
context:
space:
mode:
authorÉric Araujo <merwok@netwok.org>2010-11-05 23:51:56 (GMT)
committerÉric Araujo <merwok@netwok.org>2010-11-05 23:51:56 (GMT)
commitbee5cef7dbff40734c347da5b93797e8db9103e8 (patch)
tree06dcc726207cfad3016f2b0f7c365fb9fe5b3cc6 /Lib/distutils/tests/test_dist.py
parentafb078dd2673d919ac3733104757c441f256f30f (diff)
downloadcpython-bee5cef7dbff40734c347da5b93797e8db9103e8.zip
cpython-bee5cef7dbff40734c347da5b93797e8db9103e8.tar.gz
cpython-bee5cef7dbff40734c347da5b93797e8db9103e8.tar.bz2
Always close files in distutils code and tests (#10252).
Diffstat (limited to 'Lib/distutils/tests/test_dist.py')
-rw-r--r--Lib/distutils/tests/test_dist.py40
1 files changed, 21 insertions, 19 deletions
diff --git a/Lib/distutils/tests/test_dist.py b/Lib/distutils/tests/test_dist.py
index 007803e..ee8e8d4 100644
--- a/Lib/distutils/tests/test_dist.py
+++ b/Lib/distutils/tests/test_dist.py
@@ -79,29 +79,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
@@ -260,8 +260,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()