Rev 5893: (mbp) be more careful about closing files in selftest, in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Wed May 18 19:22:51 UTC 2011


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 5893 [merge]
revision-id: pqm at pqm.ubuntu.com-20110518192246-x1duixv8rt9v2xml
parent: pqm at pqm.ubuntu.com-20110518161105-pbt4yc8mgl0y3qsy
parent: larstiq at larstiq.dyndns.org-20110518145924-l0ab360t1f6xpnee
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2011-05-18 19:22:46 +0000
message:
  (mbp) be more careful about closing files in selftest,
   so that more of it passes on pypy (Wouter van Heyst)
modified:
  bzrlib/export/tar_exporter.py  tar_exporter.py-20051114235828-1f6349a2f090a5d0
  bzrlib/tests/blackbox/test_pack.py test_pack.py-20070712120702-0c7585lh56p894mo-1
  bzrlib/tests/blackbox/test_revert.py test_revert.py-20060124160917-485ce9de629c182c
  bzrlib/tests/blackbox/test_status.py teststatus.py-20050712014354-508855eb9f29f7dc
  bzrlib/tests/blackbox/test_too_much.py blackbox.py-20050620052131-a7370d756399f615
  bzrlib/tests/per_transport.py  test_transport_implementations.py-20051227111451-f97c5c7d5c49fce7
=== modified file 'bzrlib/export/tar_exporter.py'
--- a/bzrlib/export/tar_exporter.py	2011-03-21 09:08:34 +0000
+++ b/bzrlib/export/tar_exporter.py	2011-05-13 21:05:38 +0000
@@ -104,9 +104,12 @@
         root_mtime = tree.get_file_mtime(tree.get_root_id())
     else:
         root_mtime = None
+
+    is_stdout = False
     if dest == '-':
         basename = None
         stream = sys.stdout
+        is_stdout = True
     else:
         stream = open(dest, 'wb')
         # gzip file is used with an explicit fileobj so that
@@ -114,14 +117,17 @@
         # dest. (bug 102234)
         basename = os.path.basename(dest)
     try:
-        stream = gzip.GzipFile(basename, 'w', fileobj=stream, mtime=root_mtime)
+        zipstream = gzip.GzipFile(basename, 'w', fileobj=stream, mtime=root_mtime)
     except TypeError:
         # Python < 2.7 doesn't support the mtime argument
-        stream = gzip.GzipFile(basename, 'w', fileobj=stream)
-    ball = tarfile.open(None, 'w|', fileobj=stream)
+        zipstream = gzip.GzipFile(basename, 'w', fileobj=stream)
+    ball = tarfile.open(None, 'w|', fileobj=zipstream)
     export_tarball(tree, ball, root, subdir, filtered=filtered,
                    force_mtime=force_mtime)
     ball.close()
+    zipstream.close()
+    if not is_stdout:
+        stream.close()
 
 
 def tbz_exporter(tree, dest, root, subdir, filtered=False, force_mtime=None):

=== modified file 'bzrlib/tests/blackbox/test_pack.py'
--- a/bzrlib/tests/blackbox/test_pack.py	2010-04-26 16:59:56 +0000
+++ b/bzrlib/tests/blackbox/test_pack.py	2011-05-13 20:44:45 +0000
@@ -38,7 +38,9 @@
 
     def _update_file(self, path, text, checkin=True):
         """append text to file 'path' and check it in"""
-        open(path, 'a').write(text)
+        with open(path, 'a') as f:
+            f.write(text)
+
         if checkin:
             self.run_bzr(['ci', path, '-m', '"' + path + '"'])
 

=== modified file 'bzrlib/tests/blackbox/test_revert.py'
--- a/bzrlib/tests/blackbox/test_revert.py	2011-05-13 12:51:05 +0000
+++ b/bzrlib/tests/blackbox/test_revert.py	2011-05-18 10:03:10 +0000
@@ -120,16 +120,16 @@
     def test_revert(self):
         self.run_bzr('init')
 
-        file('hello', 'wt').write('foo')
+        with file('hello', 'wt') as f: f.write('foo')
         self.run_bzr('add hello')
         self.run_bzr('commit -m setup hello')
 
-        file('goodbye', 'wt').write('baz')
+        with file('goodbye', 'wt') as f: f.write('baz')
         self.run_bzr('add goodbye')
         self.run_bzr('commit -m setup goodbye')
 
-        file('hello', 'wt').write('bar')
-        file('goodbye', 'wt').write('qux')
+        with file('hello', 'wt') as f: f.write('bar')
+        with file('goodbye', 'wt') as f: f.write('qux')
         self.run_bzr('revert hello')
         self.check_file_contents('hello', 'foo')
         self.check_file_contents('goodbye', 'qux')
@@ -157,7 +157,7 @@
         else:
             self.log("skipping revert symlink tests")
 
-        file('hello', 'wt').write('xyz')
+        with file('hello', 'wt') as f: f.write('xyz')
         self.run_bzr('commit -m xyz hello')
         self.run_bzr('revert -r 1 hello')
         self.check_file_contents('hello', 'foo')

=== modified file 'bzrlib/tests/blackbox/test_status.py'
--- a/bzrlib/tests/blackbox/test_status.py	2011-01-31 22:09:46 +0000
+++ b/bzrlib/tests/blackbox/test_status.py	2011-05-18 14:59:24 +0000
@@ -324,10 +324,10 @@
         wt.add('FILE_D')
         wt.add('FILE_E')
         wt.commit('Create five empty files.')
-        open('FILE_B', 'w').write('Modification to file FILE_B.')
-        open('FILE_C', 'w').write('Modification to file FILE_C.')
+        with open('FILE_B', 'w') as f: f.write('Modification to file FILE_B.')
+        with open('FILE_C', 'w') as f: f.write('Modification to file FILE_C.')
         unlink('FILE_E')  # FILE_E will be versioned but missing
-        open('FILE_Q', 'w').write('FILE_Q is added but not committed.')
+        with open('FILE_Q', 'w') as f: f.write('FILE_Q is added but not committed.')
         wt.add('FILE_Q')  # FILE_Q will be added but not committed
         open('UNVERSIONED_BUT_EXISTING', 'w')
         return wt
@@ -477,10 +477,13 @@
           ' M  FILE_B\n',
           'X   NONEXISTENT\n',
           ]
+        expected.sort()
         out, err = self.run_bzr('status --short NONEXISTENT '
                                 'FILE_A FILE_B UNVERSIONED_BUT_EXISTING '
                                 'FILE_C FILE_D FILE_E FILE_Q', retcode=3)
-        self.assertEqual(expected, out.splitlines(True))
+        actual = out.splitlines(True)
+        actual.sort()
+        self.assertEqual(expected, actual)
         self.assertContainsRe(err,
                               r'.*ERROR: Path\(s\) do not exist: '
                               'NONEXISTENT.*')

=== modified file 'bzrlib/tests/blackbox/test_too_much.py'
--- a/bzrlib/tests/blackbox/test_too_much.py	2011-05-13 12:51:05 +0000
+++ b/bzrlib/tests/blackbox/test_too_much.py	2011-05-18 10:03:10 +0000
@@ -60,16 +60,16 @@
     def test_revert(self):
         self.run_bzr('init')
 
-        file('hello', 'wt').write('foo')
+        with file('hello', 'wt') as f: f.write('foo')
         self.run_bzr('add hello')
         self.run_bzr('commit -m setup hello')
 
-        file('goodbye', 'wt').write('baz')
+        with file('goodbye', 'wt') as f: f.write('baz')
         self.run_bzr('add goodbye')
         self.run_bzr('commit -m setup goodbye')
 
-        file('hello', 'wt').write('bar')
-        file('goodbye', 'wt').write('qux')
+        with file('hello', 'wt') as f: f.write('bar')
+        with file('goodbye', 'wt') as f: f.write('qux')
         self.run_bzr('revert hello')
         self.check_file_contents('hello', 'foo')
         self.check_file_contents('goodbye', 'qux')
@@ -97,7 +97,7 @@
         else:
             self.log("skipping revert symlink tests")
 
-        file('hello', 'wt').write('xyz')
+        with file('hello', 'wt') as f: f.write('xyz')
         self.run_bzr('commit -m xyz hello')
         self.run_bzr('revert -r 1 hello')
         self.check_file_contents('hello', 'foo')
@@ -109,10 +109,10 @@
 
     def example_branch(test):
         test.run_bzr('init')
-        file('hello', 'wt').write('foo')
+        with file('hello', 'wt') as f: f.write('foo')
         test.run_bzr('add hello')
         test.run_bzr('commit -m setup hello')
-        file('goodbye', 'wt').write('baz')
+        with file('goodbye', 'wt') as f: f.write('baz')
         test.run_bzr('add goodbye')
         test.run_bzr('commit -m setup goodbye')
 
@@ -127,7 +127,7 @@
         os.chdir('..')
         self.run_bzr('branch a b')
         os.chdir('b')
-        open('b', 'wb').write('else\n')
+        with open('b', 'wb') as f: f.write('else\n')
         self.run_bzr('add b')
         self.run_bzr(['commit', '-m', 'added b'])
 
@@ -195,21 +195,21 @@
         """Create a conflicted tree"""
         os.mkdir('base')
         os.chdir('base')
-        file('hello', 'wb').write("hi world")
-        file('answer', 'wb').write("42")
+        with file('hello', 'wb') as f: f.write("hi world")
+        with file('answer', 'wb') as f: f.write("42")
         self.run_bzr('init')
         self.run_bzr('add')
         self.run_bzr('commit -m base')
         self.run_bzr('branch . ../other')
         self.run_bzr('branch . ../this')
         os.chdir('../other')
-        file('hello', 'wb').write("Hello.")
-        file('answer', 'wb').write("Is anyone there?")
+        with file('hello', 'wb') as f: f.write("Hello.")
+        with file('answer', 'wb') as f: f.write("Is anyone there?")
         self.run_bzr('commit -m other')
         os.chdir('../this')
-        file('hello', 'wb').write("Hello, world")
+        with file('hello', 'wb') as f: f.write("Hello, world")
         self.run_bzr('mv answer question')
-        file('question', 'wb').write("What do you get when you multiply six"
+        with file('question', 'wb') as f: f.write("What do you get when you multiply six"
                                    "times nine?")
         self.run_bzr('commit -m this')
 
@@ -438,7 +438,7 @@
 
         progress("file with spaces in name")
         mkdir('sub directory')
-        file('sub directory/file with spaces ', 'wt').write('see how this works\n')
+        with file('sub directory/file with spaces ', 'wt') as f: f.write('see how this works\n')
         self.run_bzr('add .')
         self.run_bzr('diff', retcode=1)
         self.run_bzr('commit -m add-spaces')
@@ -590,7 +590,7 @@
         os.mkdir('my-branch')
         os.chdir('my-branch')
         self.run_bzr('init')
-        file('hello', 'wt').write('foo')
+        with file('hello', 'wt') as f: f.write('foo')
         self.run_bzr('add hello')
         self.run_bzr('commit -m setup')
 

=== modified file 'bzrlib/tests/per_transport.py'
--- a/bzrlib/tests/per_transport.py	2011-05-13 12:51:05 +0000
+++ b/bzrlib/tests/per_transport.py	2011-05-18 14:45:15 +0000
@@ -1626,7 +1626,7 @@
     def test_readv(self):
         transport = self.get_transport()
         if transport.is_readonly():
-            file('a', 'w').write('0123456789')
+            with file('a', 'w') as f: f.write('0123456789')
         else:
             transport.put_bytes('a', '0123456789')
 
@@ -1642,7 +1642,7 @@
     def test_readv_out_of_order(self):
         transport = self.get_transport()
         if transport.is_readonly():
-            file('a', 'w').write('0123456789')
+            with file('a', 'w') as f: f.write('0123456789')
         else:
             transport.put_bytes('a', '01234567890')
 
@@ -1720,7 +1720,7 @@
         transport = self.get_transport()
         # test from observed failure case.
         if transport.is_readonly():
-            file('a', 'w').write('a'*1024*1024)
+            with file('a', 'w') as f: f.write('a'*1024*1024)
         else:
             transport.put_bytes('a', 'a'*1024*1024)
         broken_vector = [(465219, 800), (225221, 800), (445548, 800),
@@ -1760,7 +1760,7 @@
     def test_readv_short_read(self):
         transport = self.get_transport()
         if transport.is_readonly():
-            file('a', 'w').write('0123456789')
+            with file('a', 'w') as f: f.write('0123456789')
         else:
             transport.put_bytes('a', '01234567890')
 




More information about the bazaar-commits mailing list