mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
Always close files in distutils code and tests (#10252).
This commit is contained in:
parent
afb078dd26
commit
bee5cef7db
24 changed files with 261 additions and 171 deletions
|
@ -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)
|
||||
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)
|
||||
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"])
|
||||
|
||||
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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue