diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2011-05-19 13:51:27 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2011-05-19 13:51:27 (GMT) |
commit | 21a9c748aa8698c8201e30a58320d587f6bb7540 (patch) | |
tree | ddfcb60a800bc010237ee750a449c4639e5515e3 /Lib/packaging/tests | |
parent | 0e3f3a70760f5ef1c0d1f7baf55046514b6bfbb6 (diff) | |
download | cpython-21a9c748aa8698c8201e30a58320d587f6bb7540.zip cpython-21a9c748aa8698c8201e30a58320d587f6bb7540.tar.gz cpython-21a9c748aa8698c8201e30a58320d587f6bb7540.tar.bz2 |
packaging: use with open() instead of try/finally: close
Diffstat (limited to 'Lib/packaging/tests')
-rw-r--r-- | Lib/packaging/tests/support.py | 5 | ||||
-rw-r--r-- | Lib/packaging/tests/test_command_build_scripts.py | 5 | ||||
-rw-r--r-- | Lib/packaging/tests/test_command_install_dist.py | 5 | ||||
-rw-r--r-- | Lib/packaging/tests/test_command_install_scripts.py | 5 | ||||
-rw-r--r-- | Lib/packaging/tests/test_create.py | 5 | ||||
-rw-r--r-- | Lib/packaging/tests/test_pypi_server.py | 8 | ||||
-rw-r--r-- | Lib/packaging/tests/test_util.py | 16 |
7 files changed, 15 insertions, 34 deletions
diff --git a/Lib/packaging/tests/support.py b/Lib/packaging/tests/support.py index cf5d788..dbd8683 100644 --- a/Lib/packaging/tests/support.py +++ b/Lib/packaging/tests/support.py @@ -146,11 +146,8 @@ class TempdirManager: """ if isinstance(path, (list, tuple)): path = os.path.join(*path) - f = open(path, 'w') - try: + with open(path, 'w') as f: f.write(content) - finally: - f.close() def create_dist(self, **kw): """Create a stub distribution object and files. diff --git a/Lib/packaging/tests/test_command_build_scripts.py b/Lib/packaging/tests/test_command_build_scripts.py index 60d8b68..fd3ac24 100644 --- a/Lib/packaging/tests/test_command_build_scripts.py +++ b/Lib/packaging/tests/test_command_build_scripts.py @@ -71,11 +71,8 @@ class BuildScriptsTestCase(support.TempdirManager, return expected def write_script(self, dir, name, text): - f = open(os.path.join(dir, name), "w") - try: + with open(os.path.join(dir, name), "w") as f: f.write(text) - finally: - f.close() def test_version_int(self): source = self.mkdtemp() diff --git a/Lib/packaging/tests/test_command_install_dist.py b/Lib/packaging/tests/test_command_install_dist.py index a06d1f6..1974a2f 100644 --- a/Lib/packaging/tests/test_command_install_dist.py +++ b/Lib/packaging/tests/test_command_install_dist.py @@ -193,11 +193,8 @@ class InstallTestCase(support.TempdirManager, # let's check the record file was created with four # lines, one for each .dist-info entry: METADATA, # INSTALLER, REQUSTED, RECORD - f = open(cmd.record) - try: + with open(cmd.record) as f: self.assertEqual(len(f.readlines()), 4) - finally: - f.close() # XXX test that fancy_getopt is okay with options named # record and no-record but unrelated diff --git a/Lib/packaging/tests/test_command_install_scripts.py b/Lib/packaging/tests/test_command_install_scripts.py index 08c7338..6452a34 100644 --- a/Lib/packaging/tests/test_command_install_scripts.py +++ b/Lib/packaging/tests/test_command_install_scripts.py @@ -38,11 +38,8 @@ class InstallScriptsTestCase(support.TempdirManager, def write_script(name, text): expected.append(name) - f = open(os.path.join(source, name), "w") - try: + with open(os.path.join(source, name), "w") as f: 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/packaging/tests/test_create.py b/Lib/packaging/tests/test_create.py index 99ab063..9c7a912 100644 --- a/Lib/packaging/tests/test_create.py +++ b/Lib/packaging/tests/test_create.py @@ -173,11 +173,8 @@ class CreateTestCase(support.TempdirManager, dedent(""" # -*- coding: utf-8 -*- from distutils.core import setup - fp = open('README.txt') - try: + with open('README.txt') as fp: long_description = fp.read() - finally: - fp.close() setup(name='pyxfoil', version='0.2', diff --git a/Lib/packaging/tests/test_pypi_server.py b/Lib/packaging/tests/test_pypi_server.py index 1fcbdcb..2c4ec0d 100644 --- a/Lib/packaging/tests/test_pypi_server.py +++ b/Lib/packaging/tests/test_pypi_server.py @@ -54,11 +54,9 @@ class PyPIServerTest(unittest.TestCase): url = server.full_address + url_path request = urllib.request.Request(url) response = urllib.request.urlopen(request) - file = open(PYPI_DEFAULT_STATIC_PATH + "/test_pypi_server" + - url_path) - answer = response.read().decode() == file.read() - file.close() - return answer + with open(PYPI_DEFAULT_STATIC_PATH + "/test_pypi_server" + + url_path) as file: + return response.read().decode() == file.read() server = PyPIServer(static_uri_paths=["simple", "external"], static_filesystem_paths=["test_pypi_server"]) diff --git a/Lib/packaging/tests/test_util.py b/Lib/packaging/tests/test_util.py index 336086d..203c708 100644 --- a/Lib/packaging/tests/test_util.py +++ b/Lib/packaging/tests/test_util.py @@ -720,17 +720,15 @@ class EggInfoToDistInfoTestCase(support.TempdirManager, dir_paths.append(path) for f in files: path = os.path.join(tempdir, f) - _f = open(path, 'w') - _f.write(f) - _f.close() + with open(path, 'w') as _f: + _f.write(f) file_paths.append(path) - record_file = open(record_file_path, 'w') - for fpath in file_paths: - record_file.write(fpath + '\n') - for dpath in dir_paths: - record_file.write(dpath + '\n') - record_file.close() + with open(record_file_path, 'w') as record_file: + for fpath in file_paths: + record_file.write(fpath + '\n') + for dpath in dir_paths: + record_file.write(dpath + '\n') return (tempdir, record_file_path) |