Rev 6464: (gz) Close files more promptly in tests to avoid issues on pypy (Wouter van in file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/2.5/
Patch Queue Manager
pqm at pqm.ubuntu.com
Fri Jan 27 21:40:56 UTC 2012
At file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/2.5/
------------------------------------------------------------
revno: 6464 [merge]
revision-id: pqm at pqm.ubuntu.com-20120127214055-x77vzzxfjqco7h2m
parent: pqm at pqm.ubuntu.com-20120127204627-l1k18d3chedgs3bu
parent: martin.packman at canonical.com-20120127153001-v22hlondb77jmqme
committer: Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: 2.5
timestamp: Fri 2012-01-27 21:40:55 +0000
message:
(gz) Close files more promptly in tests to avoid issues on pypy (Wouter van
Heyst)
modified:
bzrlib/tests/blackbox/test_commit.py test_commit.py-20060212094538-ae88fc861d969db0
bzrlib/tests/blackbox/test_revno.py test_revno.py-20051204214528-2f0bf83a71b7656a
bzrlib/tests/blackbox/test_shared_repository.py test_shared_repository.py-20060317053531-ed30c0d79325e483
bzrlib/tests/per_branch/test_bound_sftp.py test_bound_sftp.py-20051231055311-2f96048c4f0940ef
bzrlib/tests/per_bzrdir/test_bzrdir.py test_bzrdir.py-20100829143338-2uachgod1c3liktl-1
bzrlib/tests/per_tree/test_tree.py test_tree.py-20061215160206-usu7lwcj8aq2n3br-1
bzrlib/tests/per_workingtree/test_basis_inventory.py test_basis_inventory.py-20051218151655-3650468941091309
bzrlib/tests/per_workingtree/test_commit.py test_commit.py-20060421013633-1610ec2331c8190f
bzrlib/tests/per_workingtree/test_inv.py test_inv.py-20070311221604-ighlq8tbn5xq0kuo-1
bzrlib/tests/per_workingtree/test_workingtree.py test_workingtree.py-20060203003124-817757d3e31444fb
bzrlib/tests/test_bundle.py test.py-20050630184834-092aa401ab9f039c
bzrlib/tests/test_commit.py test_commit.py-20050914060732-279f057f8c295434
bzrlib/tests/test_diff.py testdiff.py-20050727164403-d1a3496ebb12e339
bzrlib/tests/test_log.py testlog.py-20050728115707-1a514809d7d49309
bzrlib/tests/test_merge.py testmerge.py-20050905070950-c1b5aa49ff911024
bzrlib/tests/test_merge_core.py test_merge_core.py-20050824132511-eb99b23a0eec641b
bzrlib/tests/test_nonascii.py testnonascii.py-20051018022645-ea1d8b6477b058a6
bzrlib/tests/test_patch.py test_patch.py-20060416172603-65c8e3b6c4783426
bzrlib/tests/test_permissions.py test_permissions.py-20051215004520-ccf475789c80e80c
bzrlib/tests/test_plugins.py plugins.py-20050622075746-32002b55e5e943e9
bzrlib/tests/test_registry.py test_lazy_factory.py-20060809213415-2gfvqadtvdn0phtg-2
bzrlib/tests/test_sftp_transport.py testsftp.py-20051027032739-247570325fec7e7e
bzrlib/tests/test_textfile.py test_textfile.py-20060415001558-256482b2206362aa
bzrlib/tests/test_transform.py test_transaction.py-20060105172520-b3ffb3946550e6c4
doc/en/release-notes/bzr-2.5.txt bzr2.5.txt-20110708125756-587p0hpw7oke4h05-1
=== modified file 'bzrlib/tests/blackbox/test_commit.py'
--- a/bzrlib/tests/blackbox/test_commit.py 2012-01-06 11:05:23 +0000
+++ b/bzrlib/tests/blackbox/test_commit.py 2012-01-25 21:13:15 +0000
@@ -139,7 +139,7 @@
self.requireFeature(features.UnicodeFilenameFeature)
file_name = u'\N{euro sign}'
self.run_bzr(['init'])
- open(file_name, 'w').write('hello world')
+ with open(file_name, 'w') as f: f.write('hello world')
self.run_bzr(['add'])
out, err = self.run_bzr(['commit', '-m', file_name])
reflags = re.MULTILINE|re.DOTALL|re.UNICODE
@@ -157,7 +157,7 @@
try:
osutils.get_terminal_encoding = lambda trace=None: 'ascii'
file_name = u'foo\u1234'
- open(file_name, 'w').write('hello world')
+ with open(file_name, 'w') as f: f.write('hello world')
self.run_bzr(['add'])
out, err = self.run_bzr(['commit', '-m', file_name])
reflags = re.MULTILINE|re.DOTALL|re.UNICODE
=== modified file 'bzrlib/tests/blackbox/test_revno.py'
--- a/bzrlib/tests/blackbox/test_revno.py 2011-12-14 20:21:52 +0000
+++ b/bzrlib/tests/blackbox/test_revno.py 2012-01-25 21:13:15 +0000
@@ -36,7 +36,7 @@
bzr('init')
self.assertEquals(int(bzr('revno')), 0)
- open('foo', 'wb').write('foo\n')
+ with open('foo', 'wb') as f: f.write('foo\n')
bzr('add foo')
bzr('commit -m foo')
self.assertEquals(int(bzr('revno')), 1)
=== modified file 'bzrlib/tests/blackbox/test_shared_repository.py'
--- a/bzrlib/tests/blackbox/test_shared_repository.py 2012-01-19 12:39:30 +0000
+++ b/bzrlib/tests/blackbox/test_shared_repository.py 2012-01-25 21:13:15 +0000
@@ -81,7 +81,7 @@
def test_branch_tree(self):
self.run_bzr("init-repo --trees a")
self.run_bzr("init --format=default b")
- file('b/hello', 'wt').write('bar')
+ with file('b/hello', 'wt') as f: f.write('bar')
self.run_bzr("add b/hello")
self.run_bzr("commit -m bar b/hello")
=== modified file 'bzrlib/tests/per_branch/test_bound_sftp.py'
--- a/bzrlib/tests/per_branch/test_bound_sftp.py 2011-05-13 12:51:05 +0000
+++ b/bzrlib/tests/per_branch/test_bound_sftp.py 2012-01-25 21:13:15 +0000
@@ -103,7 +103,7 @@
def test_bound_commit(self):
b_base, wt_child = self.create_branches()
- open('child/a', 'wb').write('new contents\n')
+ with open('child/a', 'wb') as f: f.write('new contents\n')
wt_child.commit('modified a', rev_id='r at c-2')
self.assertEqual(['r at b-1', 'r at c-2'], wt_child.branch.revision_history())
@@ -113,10 +113,10 @@
# Make sure commit fails if out of date.
b_base, wt_child = self.create_branches()
- open('base/a', 'wb').write('new base contents\n')
+ with open('base/a', 'wb') as f: f.write('new base contents\n')
b_base.bzrdir.open_workingtree().commit('base', rev_id='r at b-2')
- open('child/b', 'wb').write('new b child contents\n')
+ with open('child/b', 'wb') as f: f.write('new b child contents\n')
self.assertRaises(errors.BoundBranchOutOfDate,
wt_child.commit, 'child', rev_id='r at c-2')
@@ -139,7 +139,7 @@
wt_child2 = wt_child.branch.create_checkout('child2')
- open('child2/a', 'wb').write('new contents\n')
+ with open('child2/a', 'wb') as f: f.write('new contents\n')
self.assertRaises(errors.CommitToDoubleBoundBranch,
wt_child2.commit, 'child2', rev_id='r at d-2')
@@ -153,10 +153,10 @@
__unused_t = self.get_transport()
wt_base = b_base.bzrdir.open_workingtree()
- open('base/a', 'wb').write('new base contents\n')
+ with open('base/a', 'wb') as f: f.write('new base contents\n')
wt_base.commit('base', rev_id='r at b-2')
- open('child/b', 'wb').write('new b child contents\n')
+ with open('child/b', 'wb') as f: f.write('new b child contents\n')
self.assertRaises(errors.BoundBranchOutOfDate,
wt_child.commit, 'child', rev_id='r at c-2')
self.assertEqual(['r at b-1'], wt_child.branch.revision_history())
@@ -181,7 +181,7 @@
sftp_b_base.bind(sftp_b_newbase)
- open('child/a', 'wb').write('new contents\n')
+ with open('child/a', 'wb') as f: f.write('new contents\n')
self.assertRaises(errors.CommitToDoubleBoundBranch,
wt_child.commit, 'failure', rev_id='r at c-2')
@@ -193,13 +193,13 @@
b_base, wt_child = self.create_branches()
wt_child.branch.unbind()
- open('child/a', 'ab').write('child contents\n')
+ with open('child/a', 'ab') as f: f.write('child contents\n')
wt_child_rev = wt_child.commit('child', rev_id='r at c-2')
self.assertEqual(['r at b-1', 'r at c-2'], wt_child.branch.revision_history())
self.assertEqual(['r at b-1'], b_base.revision_history())
- open('base/b', 'ab').write('base contents\n')
+ with open('base/b', 'ab') as f: f.write('base contents\n')
b_base.bzrdir.open_workingtree().commit('base', rev_id='r at b-2')
self.assertEqual(['r at b-1', 'r at b-2'], b_base.revision_history())
@@ -225,7 +225,7 @@
wt_child.branch.unbind()
- open('a', 'ab').write('base changes\n')
+ with open('a', 'ab') as f: f.write('base changes\n')
wt_base = b_base.bzrdir.open_workingtree()
wt_base.commit('base', rev_id='r at b-2')
self.assertEqual(['r at b-1', 'r at b-2'], b_base.revision_history())
@@ -288,7 +288,7 @@
wt_other = wt_child.bzrdir.sprout('other').open_workingtree()
- open('other/c', 'wb').write('file c\n')
+ with open('other/c', 'wb') as f: f.write('file c\n')
wt_other.add('c')
wt_other.commit('adding c', rev_id='r at d-2')
@@ -312,7 +312,7 @@
def test_commit_fails(self):
b_base, wt_child = self.create_branches()
- open('a', 'ab').write('child adds some text\n')
+ with open('a', 'ab') as f: f.write('child adds some text\n')
# this deletes the branch from memory
del b_base
=== modified file 'bzrlib/tests/per_bzrdir/test_bzrdir.py'
--- a/bzrlib/tests/per_bzrdir/test_bzrdir.py 2012-01-18 17:47:06 +0000
+++ b/bzrlib/tests/per_bzrdir/test_bzrdir.py 2012-01-27 14:36:00 +0000
@@ -125,8 +125,8 @@
self.assertTrue(S_ISDIR(target.stat(path).st_mode))
directories.append(path)
else:
- self.assertEqualDiff(source.get(path).read(),
- target.get(path).read(),
+ self.assertEqualDiff(source.get_bytes(path),
+ target.get_bytes(path),
"text for file %r differs:\n" % path)
def assertRepositoryHasSameItems(self, left_repo, right_repo):
=== modified file 'bzrlib/tests/per_tree/test_tree.py'
--- a/bzrlib/tests/per_tree/test_tree.py 2011-08-29 19:06:57 +0000
+++ b/bzrlib/tests/per_tree/test_tree.py 2012-01-27 15:30:01 +0000
@@ -158,15 +158,21 @@
work_tree = self.make_branch_and_tree('wt')
tree = self.get_tree_no_parents_abc_content_2(work_tree)
tree.lock_read()
- try:
- # Test lookup without path works
- lines = tree.get_file('a-id').readlines()
- self.assertEqual(['foobar\n'], lines)
- # Test lookup with path works
- lines = tree.get_file('a-id', path='a').readlines()
- self.assertEqual(['foobar\n'], lines)
- finally:
- tree.unlock()
+ self.addCleanup(tree.unlock)
+ # Test lookup without path works
+ file_without_path = tree.get_file('a-id')
+ try:
+ lines = file_without_path.readlines()
+ self.assertEqual(['foobar\n'], lines)
+ finally:
+ file_without_path.close()
+ # Test lookup with path works
+ file_with_path = tree.get_file('a-id', path='a')
+ try:
+ lines = file_with_path.readlines()
+ self.assertEqual(['foobar\n'], lines)
+ finally:
+ file_with_path.close()
def test_get_file_text(self):
work_tree = self.make_branch_and_tree('wt')
=== modified file 'bzrlib/tests/per_workingtree/test_basis_inventory.py'
--- a/bzrlib/tests/per_workingtree/test_basis_inventory.py 2011-05-04 21:10:36 +0000
+++ b/bzrlib/tests/per_workingtree/test_basis_inventory.py 2012-01-25 21:13:15 +0000
@@ -34,7 +34,7 @@
# Make sure the basis file is created by a commit
t = self.make_branch_and_tree('.')
b = t.branch
- open('a', 'wb').write('a\n')
+ with open('a', 'wb') as f: f.write('a\n')
t.add('a')
t.commit('a', rev_id='r1')
@@ -46,7 +46,7 @@
store_inv = b.repository.get_inventory('r1')
self.assertEqual([], store_inv._make_delta(basis_inv))
- open('b', 'wb').write('b\n')
+ with open('b', 'wb') as f: f.write('b\n')
t.add('b')
t.commit('b', rev_id='r2')
@@ -69,7 +69,7 @@
% (self.workingtree_format,))
t = self.make_branch_and_tree('.')
b = t.branch
- open('a', 'wb').write('a\n')
+ with open('a', 'wb') as f: f.write('a\n')
t.add('a')
t.commit('a', rev_id='r1')
t._transport.put_bytes('basis-inventory-cache', 'booga')
=== modified file 'bzrlib/tests/per_workingtree/test_commit.py'
--- a/bzrlib/tests/per_workingtree/test_commit.py 2011-05-13 12:51:05 +0000
+++ b/bzrlib/tests/per_workingtree/test_commit.py 2012-01-25 21:13:15 +0000
@@ -552,7 +552,7 @@
"""Make sure a start commit hook can modify the tree that is
committed."""
def start_commit_hook_adds_file(tree):
- open(tree.abspath("newfile"), 'w').write("data")
+ with open(tree.abspath("newfile"), 'w') as f: f.write("data")
tree.add(["newfile"])
def restoreDefaults():
mutabletree.MutableTree.hooks['start_commit'] = []
@@ -573,7 +573,7 @@
mutabletree.PostCommitHookParams))
self.assertTrue(isinstance(params.mutable_tree,
mutabletree.MutableTree))
- open(tree.abspath("newfile"), 'w').write("data")
+ with open(tree.abspath("newfile"), 'w') as f: f.write("data")
params.mutable_tree.add(["newfile"])
tree = self.make_branch_and_tree('.')
mutabletree.MutableTree.hooks.install_named_hook(
=== modified file 'bzrlib/tests/per_workingtree/test_inv.py'
--- a/bzrlib/tests/per_workingtree/test_inv.py 2011-05-17 12:13:59 +0000
+++ b/bzrlib/tests/per_workingtree/test_inv.py 2012-01-25 21:13:15 +0000
@@ -30,7 +30,7 @@
wt.lock_tree_write()
self.addCleanup(wt.unlock)
self.assertEqual(len(wt.all_file_ids()), 1)
- open('b1/a', 'wb').write('a test\n')
+ with open('b1/a', 'wb') as f: f.write('a test\n')
wt.add('a')
self.assertEqual(len(wt.all_file_ids()), 2)
wt.flush() # workaround revert doing wt._write_inventory for now.
=== modified file 'bzrlib/tests/per_workingtree/test_workingtree.py'
--- a/bzrlib/tests/per_workingtree/test_workingtree.py 2012-01-18 17:47:06 +0000
+++ b/bzrlib/tests/per_workingtree/test_workingtree.py 2012-01-25 21:13:15 +0000
@@ -175,7 +175,7 @@
tree = self.make_branch_and_tree('.')
self.build_tree(['hello.txt'])
- file('hello.txt', 'w').write('initial hello')
+ with file('hello.txt', 'w') as f: f.write('initial hello')
self.assertRaises(PathsNotVersionedError,
tree.revert, ['hello.txt'])
@@ -183,7 +183,7 @@
tree.commit('create initial hello.txt')
self.check_file_contents('hello.txt', 'initial hello')
- file('hello.txt', 'w').write('new hello')
+ with file('hello.txt', 'w') as f: f.write('new hello')
self.check_file_contents('hello.txt', 'new hello')
# revert file modified since last revision
@@ -197,7 +197,7 @@
self.check_file_contents('hello.txt.~1~', 'new hello')
# backup files are numbered
- file('hello.txt', 'w').write('new hello2')
+ with file('hello.txt', 'w') as f: f.write('new hello2')
tree.revert(['hello.txt'])
self.check_file_contents('hello.txt', 'initial hello')
self.check_file_contents('hello.txt.~1~', 'new hello')
@@ -206,7 +206,7 @@
def test_revert_missing(self):
# Revert a file that has been deleted since last commit
tree = self.make_branch_and_tree('.')
- file('hello.txt', 'w').write('initial hello')
+ with file('hello.txt', 'w') as f: f.write('initial hello')
tree.add('hello.txt')
tree.commit('added hello.txt')
os.unlink('hello.txt')
@@ -708,16 +708,16 @@
def make_merge_conflicts(self):
from bzrlib.merge import merge_inner
tree = self.make_branch_and_tree('mine')
- file('mine/bloo', 'wb').write('one')
- file('mine/blo', 'wb').write('on')
+ with file('mine/bloo', 'wb') as f: f.write('one')
+ with file('mine/blo', 'wb') as f: f.write('on')
tree.add(['bloo', 'blo'])
tree.commit("blah", allow_pointless=False)
base = tree.branch.repository.revision_tree(tree.last_revision())
bzrdir.BzrDir.open("mine").sprout("other")
- file('other/bloo', 'wb').write('two')
+ with file('other/bloo', 'wb') as f: f.write('two')
othertree = WorkingTree.open('other')
othertree.commit('blah', allow_pointless=False)
- file('mine/bloo', 'wb').write('three')
+ with file('mine/bloo', 'wb') as f: f.write('three')
tree.commit("blah", allow_pointless=False)
merge_inner(tree.branch, othertree, base, this_tree=tree)
return tree
=== modified file 'bzrlib/tests/test_bundle.py'
--- a/bzrlib/tests/test_bundle.py 2011-12-21 14:25:26 +0000
+++ b/bzrlib/tests/test_bundle.py 2012-01-25 21:13:15 +0000
@@ -649,10 +649,10 @@
bundle = self.get_valid_bundle('null:', 'a at cset-0-4')
# Modified files
- open('b1/sub/dir/WithCaps.txt', 'ab').write('\nAdding some text\n')
- open('b1/sub/dir/ pre space', 'ab').write(
+ with open('b1/sub/dir/WithCaps.txt', 'ab') as f: f.write('\nAdding some text\n')
+ with open('b1/sub/dir/ pre space', 'ab') as f: f.write(
'\r\nAdding some\r\nDOS format lines\r\n')
- open('b1/sub/dir/nolastnewline.txt', 'ab').write('\n')
+ with open('b1/sub/dir/nolastnewline.txt', 'ab') as f: f.write('\n')
self.tree1.rename_one('sub/dir/ pre space',
'sub/ start space')
self.tree1.commit('Modified files', rev_id='a at cset-0-5')
@@ -807,12 +807,12 @@
self.tree1 = self.make_branch_and_tree('b1')
self.b1 = self.tree1.branch
- open('b1/one', 'wb').write('one\n')
+ with open('b1/one', 'wb') as f: f.write('one\n')
self.tree1.add('one')
self.tree1.commit('add file', rev_id='a at cset-0-1')
- open('b1/one', 'wb').write('two\n')
+ with open('b1/one', 'wb') as f: f.write('two\n')
self.tree1.commit('modify', rev_id='a at cset-0-2')
- open('b1/one', 'wb').write('three\n')
+ with open('b1/one', 'wb') as f: f.write('three\n')
self.tree1.commit('modify', rev_id='a at cset-0-3')
bundle_file = StringIO()
rev_ids = write_bundle(self.tree1.branch.repository, 'a at cset-0-3',
@@ -897,7 +897,7 @@
bundle = self.get_valid_bundle('null:', 'white-1')
# Modified
- open('b1/trailing space ', 'ab').write('add some text\n')
+ with open('b1/trailing space ', 'ab') as f: f.write('add some text\n')
self.tree1.commit('add text', rev_id='white-2')
bundle = self.get_valid_bundle('white-1', 'white-2')
=== modified file 'bzrlib/tests/test_commit.py'
--- a/bzrlib/tests/test_commit.py 2011-12-21 14:25:26 +0000
+++ b/bzrlib/tests/test_commit.py 2012-01-25 21:13:15 +0000
@@ -82,12 +82,12 @@
"""Commit and check two versions of a single file."""
wt = self.make_branch_and_tree('.')
b = wt.branch
- file('hello', 'w').write('hello world')
+ with file('hello', 'w') as f: f.write('hello world')
wt.add('hello')
rev1 = wt.commit(message='add hello')
file_id = wt.path2id('hello')
- file('hello', 'w').write('version 2')
+ with file('hello', 'w') as f: f.write('version 2')
rev2 = wt.commit(message='commit 2')
eq = self.assertEquals
@@ -111,7 +111,7 @@
"""Attempt a lossy commit to a native branch."""
wt = self.make_branch_and_tree('.')
b = wt.branch
- file('hello', 'w').write('hello world')
+ with file('hello', 'w') as f: f.write('hello world')
wt.add('hello')
revid = wt.commit(message='add hello', rev_id='revid', lossy=True)
self.assertEquals('revid', revid)
@@ -122,7 +122,7 @@
wt = self.make_branch_and_tree('.',
format=test_foreign.DummyForeignVcsDirFormat())
b = wt.branch
- file('hello', 'w').write('hello world')
+ with file('hello', 'w') as f: f.write('hello world')
wt.add('hello')
revid = wt.commit(message='add hello', lossy=True,
timestamp=1302659388, timezone=0)
@@ -135,7 +135,7 @@
format=test_foreign.DummyForeignVcsDirFormat())
wt = foreign_branch.create_checkout("local")
b = wt.branch
- file('local/hello', 'w').write('hello world')
+ with file('local/hello', 'w') as f: f.write('hello world')
wt.add('hello')
revid = wt.commit(message='add hello', lossy=True,
timestamp=1302659388, timezone=0)
@@ -149,7 +149,7 @@
"""Test a commit with a missing file"""
wt = self.make_branch_and_tree('.')
b = wt.branch
- file('hello', 'w').write('hello world')
+ with file('hello', 'w') as f: f.write('hello world')
wt.add(['hello'], ['hello-id'])
wt.commit(message='add hello')
@@ -187,7 +187,7 @@
"""Commit refuses unless there are changes or it's forced."""
wt = self.make_branch_and_tree('.')
b = wt.branch
- file('hello', 'w').write('hello')
+ with file('hello', 'w') as f: f.write('hello')
wt.add(['hello'])
wt.commit(message='add hello')
self.assertEquals(b.revno(), 1)
@@ -213,15 +213,15 @@
"""Selective commit in tree with deletions"""
wt = self.make_branch_and_tree('.')
b = wt.branch
- file('hello', 'w').write('hello')
- file('buongia', 'w').write('buongia')
+ with file('hello', 'w') as f: f.write('hello')
+ with file('buongia', 'w') as f: f.write('buongia')
wt.add(['hello', 'buongia'],
['hello-id', 'buongia-id'])
wt.commit(message='add files',
rev_id='test at rev-1')
os.remove('hello')
- file('buongia', 'w').write('new text')
+ with file('buongia', 'w') as f: f.write('new text')
wt.commit(message='update text',
specific_files=['buongia'],
allow_pointless=False,
@@ -336,7 +336,7 @@
"""Commit with a removed file"""
wt = self.make_branch_and_tree('.')
b = wt.branch
- file('hello', 'w').write('hello world')
+ with file('hello', 'w') as f: f.write('hello world')
wt.add(['hello'], ['hello-id'])
wt.commit(message='add hello')
wt.remove('hello')
@@ -351,7 +351,7 @@
b = wt.branch
rev_ids = []
for i in range(4):
- file('hello', 'w').write((str(i) * 4) + '\n')
+ with file('hello', 'w') as f: f.write((str(i) * 4) + '\n')
if i == 0:
wt.add(['hello'], ['hello-id'])
rev_id = 'test at rev-%d' % (i+1)
@@ -380,9 +380,9 @@
from bzrlib.errors import StrictCommitFailed
wt = self.make_branch_and_tree('.')
b = wt.branch
- file('hello', 'w').write('hello world')
+ with file('hello', 'w') as f: f.write('hello world')
wt.add('hello')
- file('goodbye', 'w').write('goodbye cruel world!')
+ with file('goodbye', 'w') as f: f.write('goodbye cruel world!')
self.assertRaises(StrictCommitFailed, wt.commit,
message='add hello but not goodbye', strict=True)
@@ -391,7 +391,7 @@
should work."""
wt = self.make_branch_and_tree('.')
b = wt.branch
- file('hello', 'w').write('hello world')
+ with file('hello', 'w') as f: f.write('hello world')
wt.add('hello')
wt.commit(message='add hello', strict=True)
@@ -399,9 +399,9 @@
"""Try and commit with unknown files and strict = False, should work."""
wt = self.make_branch_and_tree('.')
b = wt.branch
- file('hello', 'w').write('hello world')
+ with file('hello', 'w') as f: f.write('hello world')
wt.add('hello')
- file('goodbye', 'w').write('goodbye cruel world!')
+ with file('goodbye', 'w') as f: f.write('goodbye cruel world!')
wt.commit(message='add hello but not goodbye', strict=False)
def test_nonstrict_commit_without_unknowns(self):
@@ -409,7 +409,7 @@
should work."""
wt = self.make_branch_and_tree('.')
b = wt.branch
- file('hello', 'w').write('hello world')
+ with file('hello', 'w') as f: f.write('hello world')
wt.add('hello')
wt.commit(message='add hello', strict=False)
=== modified file 'bzrlib/tests/test_diff.py'
--- a/bzrlib/tests/test_diff.py 2011-07-21 06:46:34 +0000
+++ b/bzrlib/tests/test_diff.py 2012-01-25 21:13:15 +0000
@@ -220,8 +220,8 @@
lines = external_udiff_lines(['\x00foobar\n'], ['foo\x00bar\n'])
cmd = ['diff', '-u', '--binary', 'old', 'new']
- open('old', 'wb').write('\x00foobar\n')
- open('new', 'wb').write('foo\x00bar\n')
+ with open('old', 'wb') as f: f.write('\x00foobar\n')
+ with open('new', 'wb') as f: f.write('foo\x00bar\n')
pipe = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stdin=subprocess.PIPE)
out, err = pipe.communicate()
@@ -1191,8 +1191,8 @@
'how are you today?\n']
txt_b = ['hello there\n',
'how are you today?\n']
- open('a1', 'wb').writelines(txt_a)
- open('b1', 'wb').writelines(txt_b)
+ with open('a1', 'wb') as f: f.writelines(txt_a)
+ with open('b1', 'wb') as f: f.writelines(txt_b)
unified_diff_files = patiencediff.unified_diff_files
psm = self._PatienceSequenceMatcher
@@ -1208,8 +1208,8 @@
txt_a = map(lambda x: x+'\n', 'abcdefghijklmnop')
txt_b = map(lambda x: x+'\n', 'abcdefxydefghijklmnop')
- open('a2', 'wb').writelines(txt_a)
- open('b2', 'wb').writelines(txt_b)
+ with open('a2', 'wb') as f: f.writelines(txt_a)
+ with open('b2', 'wb') as f: f.writelines(txt_b)
# This is the result with LongestCommonSubstring matching
self.assertEquals(['--- a2\n',
=== modified file 'bzrlib/tests/test_log.py'
--- a/bzrlib/tests/test_log.py 2011-12-15 14:47:22 +0000
+++ b/bzrlib/tests/test_log.py 2012-01-25 21:13:15 +0000
@@ -250,7 +250,7 @@
wt.commit(message='add file1 and file2')
self.run_bzr('branch parent child')
os.unlink('child/file1')
- file('child/file2', 'wb').write('hello\n')
+ with file('child/file2', 'wb') as f: f.write('hello\n')
self.run_bzr(['commit', '-m', 'remove file1 and modify file2',
'child'])
os.chdir('parent')
=== modified file 'bzrlib/tests/test_merge.py'
--- a/bzrlib/tests/test_merge.py 2012-01-05 13:02:31 +0000
+++ b/bzrlib/tests/test_merge.py 2012-01-25 21:13:15 +0000
@@ -152,7 +152,7 @@
def test_create_rename(self):
"""Rename an inventory entry while creating the file"""
tree =self.make_branch_and_tree('.')
- file('name1', 'wb').write('Hello')
+ with file('name1', 'wb') as f: f.write('Hello')
tree.add('name1')
tree.commit(message="hello")
tree.rename_one('name1', 'name2')
@@ -165,7 +165,7 @@
os.mkdir('dirname1')
tree.add('dirname1')
filename = pathjoin('dirname1', 'name1')
- file(filename, 'wb').write('Hello')
+ with file(filename, 'wb') as f: f.write('Hello')
tree.add(filename)
tree.commit(message="hello")
filename2 = pathjoin('dirname1', 'name2')
=== modified file 'bzrlib/tests/test_merge_core.py'
--- a/bzrlib/tests/test_merge_core.py 2011-09-26 15:21:01 +0000
+++ b/bzrlib/tests/test_merge_core.py 2012-01-25 21:13:15 +0000
@@ -542,12 +542,12 @@
"""Sucessfully merges unrelated branches with no common names"""
wta = self.make_branch_and_tree('a')
a = wta.branch
- file('a/a_file', 'wb').write('contents\n')
+ with file('a/a_file', 'wb') as f: f.write('contents\n')
wta.add('a_file')
wta.commit('a_revision', allow_pointless=False)
wtb = self.make_branch_and_tree('b')
b = wtb.branch
- file('b/b_file', 'wb').write('contents\n')
+ with file('b/b_file', 'wb') as f: f.write('contents\n')
wtb.add('b_file')
b_rev = wtb.commit('b_revision', allow_pointless=False)
wta.merge_from_branch(wtb.branch, b_rev, 'null:')
@@ -558,12 +558,12 @@
"""Sucessfully merges unrelated branches with common names"""
wta = self.make_branch_and_tree('a')
a = wta.branch
- file('a/file', 'wb').write('contents\n')
+ with file('a/file', 'wb') as f: f.write('contents\n')
wta.add('file')
wta.commit('a_revision', allow_pointless=False)
wtb = self.make_branch_and_tree('b')
b = wtb.branch
- file('b/file', 'wb').write('contents\n')
+ with file('b/file', 'wb') as f: f.write('contents\n')
wtb.add('file')
b_rev = wtb.commit('b_revision', allow_pointless=False)
wta.merge_from_branch(wtb.branch, b_rev, 'null:')
@@ -573,13 +573,13 @@
def test_merge_deleted_conflicts(self):
wta = self.make_branch_and_tree('a')
- file('a/file', 'wb').write('contents\n')
+ with file('a/file', 'wb') as f: f.write('contents\n')
wta.add('file')
wta.commit('a_revision', allow_pointless=False)
self.run_bzr('branch a b')
os.remove('a/file')
wta.commit('removed file', allow_pointless=False)
- file('b/file', 'wb').write('changed contents\n')
+ with file('b/file', 'wb') as f: f.write('changed contents\n')
wtb = WorkingTree.open('b')
wtb.commit('changed file', allow_pointless=False)
wtb.merge_from_branch(wta.branch, wta.branch.last_revision(),
@@ -589,7 +589,7 @@
def test_merge_metadata_vs_deletion(self):
"""Conflict deletion vs metadata change"""
a_wt = self.make_branch_and_tree('a')
- file('a/file', 'wb').write('contents\n')
+ with file('a/file', 'wb') as f: f.write('contents\n')
a_wt.add('file')
a_wt.commit('r0')
self.run_bzr('branch a b')
@@ -605,8 +605,8 @@
def test_merge_swapping_renames(self):
a_wt = self.make_branch_and_tree('a')
- file('a/un','wb').write('UN')
- file('a/deux','wb').write('DEUX')
+ with file('a/un','wb') as f: f.write('UN')
+ with file('a/deux','wb') as f: f.write('DEUX')
a_wt.add('un', 'un-id')
a_wt.add('deux', 'deux-id')
a_wt.commit('r0', rev_id='r0')
@@ -626,14 +626,14 @@
def test_merge_delete_and_add_same(self):
a_wt = self.make_branch_and_tree('a')
- file('a/file', 'wb').write('THIS')
+ with file('a/file', 'wb') as f: f.write('THIS')
a_wt.add('file')
a_wt.commit('r0')
self.run_bzr('branch a b')
b_wt = WorkingTree.open('b')
os.remove('b/file')
b_wt.commit('r1')
- file('b/file', 'wb').write('THAT')
+ with file('b/file', 'wb') as f: f.write('THAT')
b_wt.add('file')
b_wt.commit('r2')
a_wt.merge_from_branch(b_wt.branch, b_wt.branch.last_revision(),
@@ -656,13 +656,13 @@
$ bzr commit
"""
a_wt = self.make_branch_and_tree('a')
- file('a/foo', 'wb').write('A/FOO')
+ with file('a/foo', 'wb') as f: f.write('A/FOO')
a_wt.add('foo')
a_wt.commit('added foo')
self.run_bzr('branch a b')
b_wt = WorkingTree.open('b')
b_wt.rename_one('foo', 'bar')
- file('b/foo', 'wb').write('B/FOO')
+ with file('b/foo', 'wb') as f: f.write('B/FOO')
b_wt.add('foo')
b_wt.commit('moved foo to bar, added new foo')
a_wt.merge_from_branch(b_wt.branch, b_wt.branch.last_revision(),
@@ -685,7 +685,7 @@
"""
os.mkdir('a')
a_wt = self.make_branch_and_tree('a')
- file('a/foo', 'wb').write('A/FOO')
+ with file('a/foo', 'wb') as f: f.write('A/FOO')
a_wt.add('foo')
a_wt.commit('added foo')
self.run_bzr('branch a b')
@@ -714,7 +714,7 @@
"""
a_wt = self.make_branch_and_tree('a')
os.mkdir('a/foo')
- file('a/foo/bar', 'wb').write('A/FOO/BAR')
+ with file('a/foo/bar', 'wb') as f: f.write('A/FOO/BAR')
a_wt.add('foo')
a_wt.add('foo/bar')
a_wt.commit('added foo/bar')
@@ -743,8 +743,8 @@
$ bzr commit
"""
a_wt = self.make_branch_and_tree('a')
- file('a/foo', 'wb').write('A/FOO')
- file('a/bar', 'wb').write('A/BAR')
+ with file('a/foo', 'wb') as f: f.write('A/FOO')
+ with file('a/bar', 'wb') as f: f.write('A/BAR')
a_wt.add('foo')
a_wt.add('bar')
a_wt.commit('added foo and bar')
=== modified file 'bzrlib/tests/test_nonascii.py'
--- a/bzrlib/tests/test_nonascii.py 2011-01-12 01:01:53 +0000
+++ b/bzrlib/tests/test_nonascii.py 2012-01-25 21:13:15 +0000
@@ -35,7 +35,7 @@
except UnicodeEncodeError:
raise TestSkipped("filesystem can't accomodate nonascii names")
return
- file(pathjoin(br_dir, "a"), "w").write("hello")
+ with file(pathjoin(br_dir, "a"), "w") as f: f.write("hello")
wt.add(["a"], ["a-id"])
=== modified file 'bzrlib/tests/test_patch.py'
--- a/bzrlib/tests/test_patch.py 2009-03-23 14:59:43 +0000
+++ b/bzrlib/tests/test_patch.py 2012-01-25 21:13:15 +0000
@@ -22,7 +22,7 @@
class TestPatch(TestCaseInTempDir):
def test_diff3_binaries(self):
- file('this', 'wb').write('a')
- file('other', 'wb').write('a')
- file('base', 'wb').write('\x00')
+ with file('this', 'wb') as f: f.write('a')
+ with file('other', 'wb') as f: f.write('a')
+ with file('base', 'wb') as f: f.write('\x00')
self.assertRaises(BinaryFile, diff3, 'unused', 'this', 'other', 'base')
=== modified file 'bzrlib/tests/test_permissions.py'
--- a/bzrlib/tests/test_permissions.py 2011-12-18 15:43:47 +0000
+++ b/bzrlib/tests/test_permissions.py 2012-01-25 21:13:15 +0000
@@ -83,7 +83,7 @@
t = self.make_branch_and_tree('.')
b = t.branch
- open('a', 'wb').write('foo\n')
+ with open('a', 'wb') as f: f.write('foo\n')
# ensure check_mode_r works with capital-letter file-ids like TREE_ROOT
t.add('a', 'CAPS-ID')
t.commit('foo')
@@ -104,13 +104,13 @@
self.assertEqualMode(0644, b.bzrdir._get_file_mode())
# Modifying a file shouldn't break the permissions
- open('a', 'wb').write('foo2\n')
+ with open('a', 'wb') as f: f.write('foo2\n')
t.commit('foo2')
# The mode should be maintained after commit
check_mode_r(self, '.bzr', 0644, 0755)
# Adding a new file should maintain the permissions
- open('b', 'wb').write('new b\n')
+ with open('b', 'wb') as f: f.write('new b\n')
t.add('b')
t.commit('new b')
check_mode_r(self, '.bzr', 0644, 0755)
@@ -125,11 +125,11 @@
self.assertEqualMode(0775, b.bzrdir._get_dir_mode())
self.assertEqualMode(0664, b.bzrdir._get_file_mode())
- open('a', 'wb').write('foo3\n')
+ with open('a', 'wb') as f: f.write('foo3\n')
t.commit('foo3')
check_mode_r(self, '.bzr', 0664, 0775)
- open('c', 'wb').write('new c\n')
+ with open('c', 'wb') as f: f.write('new c\n')
t.add('c')
t.commit('new c')
check_mode_r(self, '.bzr', 0664, 0775)
@@ -157,11 +157,11 @@
self.assertEqualMode(02775, b.bzrdir._get_dir_mode())
self.assertEqualMode(0664, b.bzrdir._get_file_mode())
- open('a', 'wb').write('foo4\n')
+ with open('a', 'wb') as f: f.write('foo4\n')
t.commit('foo4')
check_mode_r(self, '.bzr', 0664, 02775)
- open('d', 'wb').write('new d\n')
+ with open('d', 'wb') as f: f.write('new d\n')
t.add('d')
t.commit('new d')
check_mode_r(self, '.bzr', 0664, 02775)
@@ -182,7 +182,7 @@
os.mkdir('local')
t_local = self.make_branch_and_tree('local')
b_local = t_local.branch
- open('local/a', 'wb').write('foo\n')
+ with open('local/a', 'wb') as f: f.write('foo\n')
t_local.add('a')
t_local.commit('foo')
@@ -212,13 +212,13 @@
self.assertEqualMode(0755, b_sftp.bzrdir._get_dir_mode())
self.assertEqualMode(0644, b_sftp.bzrdir._get_file_mode())
- open('local/a', 'wb').write('foo2\n')
+ with open('local/a', 'wb') as f: f.write('foo2\n')
t_local.commit('foo2')
b_sftp.pull(b_local)
# The mode should be maintained after commit
check_mode_r(self, 'sftp/.bzr', 0644, 0755)
- open('local/b', 'wb').write('new b\n')
+ with open('local/b', 'wb') as f: f.write('new b\n')
t_local.add('b')
t_local.commit('new b')
b_sftp.pull(b_local)
@@ -235,12 +235,12 @@
self.assertEqualMode(0775, b_sftp.bzrdir._get_dir_mode())
self.assertEqualMode(0664, b_sftp.bzrdir._get_file_mode())
- open('local/a', 'wb').write('foo3\n')
+ with open('local/a', 'wb') as f: f.write('foo3\n')
t_local.commit('foo3')
b_sftp.pull(b_local)
check_mode_r(self, 'sftp/.bzr', 0664, 0775)
- open('local/c', 'wb').write('new c\n')
+ with open('local/c', 'wb') as f: f.write('new c\n')
t_local.add('c')
t_local.commit('new c')
b_sftp.pull(b_local)
=== modified file 'bzrlib/tests/test_plugins.py'
--- a/bzrlib/tests/test_plugins.py 2011-08-16 07:33:29 +0000
+++ b/bzrlib/tests/test_plugins.py 2012-01-25 19:07:22 +0000
@@ -309,7 +309,7 @@
# check the plugin is not loaded already
self.assertPluginUnknown('plugin')
# write a plugin that _cannot_ fail to load.
- file('plugin.py', 'w').write(source + '\n')
+ with file('plugin.py', 'w') as f: f.write(source + '\n')
self.addCleanup(self.teardown_plugin)
plugin.load_from_path(['.'])
=== modified file 'bzrlib/tests/test_registry.py'
--- a/bzrlib/tests/test_registry.py 2011-05-26 21:02:47 +0000
+++ b/bzrlib/tests/test_registry.py 2012-01-25 21:13:15 +0000
@@ -272,7 +272,7 @@
"""
os.mkdir('tmp')
plugin_name = 'bzr_plugin_a_%s' % (osutils.rand_chars(4),)
- open('tmp/'+plugin_name+'.py', 'wb').write(contents)
+ with open('tmp/'+plugin_name+'.py', 'wb') as f: f.write(contents)
return plugin_name
def create_simple_plugin(self):
=== modified file 'bzrlib/tests/test_sftp_transport.py'
--- a/bzrlib/tests/test_sftp_transport.py 2011-12-05 09:52:49 +0000
+++ b/bzrlib/tests/test_sftp_transport.py 2012-01-25 21:13:15 +0000
@@ -81,7 +81,7 @@
l.unlock()
self.assertFalse(lexists('bogus.write-lock'))
- open('something.write-lock', 'wb').write('fake lock\n')
+ with open('something.write-lock', 'wb') as f: f.write('fake lock\n')
self.assertRaises(LockError, t.lock_write, 'something')
os.remove('something.write-lock')
@@ -201,7 +201,7 @@
self.assertEquals(b2.last_revision(), 'a1')
- open('a/foo', 'wt').write('something new in foo\n')
+ with open('a/foo', 'wt') as f: f.write('something new in foo\n')
t.commit('new', rev_id='a2')
b2.pull(b)
=== modified file 'bzrlib/tests/test_textfile.py'
--- a/bzrlib/tests/test_textfile.py 2009-03-23 14:59:43 +0000
+++ b/bzrlib/tests/test_textfile.py 2012-01-25 19:07:22 +0000
@@ -41,7 +41,7 @@
class TextPath(TestCaseInTempDir):
def test_text_file(self):
- file('boo', 'wb').write('ab' * 2048)
+ with file('boo', 'wb') as f: f.write('ab' * 2048)
check_text_path('boo')
- file('boo', 'wb').write('a' * 1023 + '\x00')
+ with file('boo', 'wb') as f: f.write('a' * 1023 + '\x00')
self.assertRaises(BinaryFile, check_text_path, 'boo')
=== modified file 'bzrlib/tests/test_transform.py'
--- a/bzrlib/tests/test_transform.py 2012-01-06 01:58:27 +0000
+++ b/bzrlib/tests/test_transform.py 2012-01-25 21:13:15 +0000
@@ -1765,7 +1765,7 @@
merge_modified = this.wt.merge_modified()
self.assertSubset(merge_modified, modified)
self.assertEqual(len(merge_modified), len(modified))
- file(this.wt.id2abspath('a'), 'wb').write('booga')
+ with file(this.wt.id2abspath('a'), 'wb') as f: f.write('booga')
modified.pop(0)
merge_modified = this.wt.merge_modified()
self.assertSubset(merge_modified, modified)
@@ -1887,7 +1887,7 @@
os.mkdir('a')
a = BzrDir.create_standalone_workingtree('a')
os.mkdir('a/foo')
- file('a/foo/bar', 'wb').write('contents')
+ with file('a/foo/bar', 'wb') as f: f.write('contents')
os.symlink('a/foo/bar', 'a/foo/baz')
a.add(['foo', 'foo/bar', 'foo/baz'])
a.commit('initial commit')
=== modified file 'doc/en/release-notes/bzr-2.5.txt'
--- a/doc/en/release-notes/bzr-2.5.txt 2012-01-27 20:46:27 +0000
+++ b/doc/en/release-notes/bzr-2.5.txt 2012-01-27 21:40:55 +0000
@@ -105,6 +105,8 @@
suite. This can include new facilities for writing tests, fixes to
spurious test failures and changes to the way things should be tested.
+* Be more careful about closing open files for pypy interoperability.
+ (Wouter van Heyst)
bzr 2.5b5
#########
More information about the bazaar-commits
mailing list