diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2010-10-14 22:11:44 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2010-10-14 22:11:44 (GMT) |
commit | 92f60ed82a302035009835a8d63ff714118a96ad (patch) | |
tree | a119000028c02ecf0317859d0bcda37fe4c505b4 /Lib/test/test_modulefinder.py | |
parent | 73315e92009c88acf53e497a0b9fcd93cd735aed (diff) | |
download | cpython-92f60ed82a302035009835a8d63ff714118a96ad.zip cpython-92f60ed82a302035009835a8d63ff714118a96ad.tar.gz cpython-92f60ed82a302035009835a8d63ff714118a96ad.tar.bz2 |
More proper closing of files
Diffstat (limited to 'Lib/test/test_modulefinder.py')
-rw-r--r-- | Lib/test/test_modulefinder.py | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/Lib/test/test_modulefinder.py b/Lib/test/test_modulefinder.py index b4fa06a..a184217 100644 --- a/Lib/test/test_modulefinder.py +++ b/Lib/test/test_modulefinder.py @@ -204,11 +204,17 @@ def open_file(path): def create_package(source): ofi = None - for line in source.splitlines(): - if line.startswith(" ") or line.startswith("\t"): - ofi.write(line.strip() + "\n") - else: - ofi = open_file(os.path.join(TEST_DIR, line.strip())) + try: + for line in source.splitlines(): + if line.startswith(" ") or line.startswith("\t"): + ofi.write(line.strip() + "\n") + else: + if ofi: + ofi.close() + ofi = open_file(os.path.join(TEST_DIR, line.strip())) + finally: + if ofi: + ofi.close() class ModuleFinderTest(unittest.TestCase): def _do_test(self, info, report=False): |