Rev 5913: Fix a test that was failing on win32. in http://bazaar.launchpad.net/~jameinel/bzr/2.4-dirstate-test-on-win32
John Arbash Meinel
john at arbash-meinel.com
Wed May 25 13:44:32 UTC 2011
At http://bazaar.launchpad.net/~jameinel/bzr/2.4-dirstate-test-on-win32
------------------------------------------------------------
revno: 5913
revision-id: john at arbash-meinel.com-20110525134428-pgce0hkk91qhjyyc
parent: pqm at pqm.ubuntu.com-20110524200712-z0ay7c4lsbg1x7qs
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.4-dirstate-test-on-win32
timestamp: Wed 2011-05-25 15:44:28 +0200
message:
Fix a test that was failing on win32.
You can't open() a file that is exclusive locked.
So just read it from the raw file.
-------------- next part --------------
=== modified file 'bzrlib/tests/test_dirstate.py'
--- a/bzrlib/tests/test_dirstate.py 2011-05-19 15:08:25 +0000
+++ b/bzrlib/tests/test_dirstate.py 2011-05-25 13:44:28 +0000
@@ -1351,6 +1351,19 @@
stat = os.lstat(path)
return dirstate.update_entry(state, entry, os.path.abspath(path), stat)
+ def _read_state_content(self, state):
+ """Read the content of the dirstate file.
+
+ On Windows when one process locks a file, you can't even open() the
+ file in another process (to read it). So we go directly to
+ state._state_file. This should always be the exact disk representation,
+ so it is reasonable to do so.
+ DirState also always seeks before reading, so it doesn't matter if we
+ bump the file pointer.
+ """
+ state._state_file.seek(0)
+ return state._state_file.read()
+
def test_worth_saving_limit_avoids_writing(self):
tree = self.make_branch_and_tree('.')
self.build_tree(['c', 'd'])
@@ -1366,11 +1379,7 @@
state.adjust_time(+20) # Allow things to be cached
self.assertEqual(dirstate.DirState.IN_MEMORY_UNMODIFIED,
state._dirblock_state)
- f = open(state._filename, 'rb')
- try:
- content = f.read()
- finally:
- f.close()
+ content = self._read_state_content(state)
self.do_update_entry(state, 'c')
self.assertEqual(1, len(state._known_hash_changes))
self.assertEqual(dirstate.DirState.IN_MEMORY_HASH_MODIFIED,
@@ -1380,7 +1389,7 @@
# hash values haven't been written out.
self.assertEqual(dirstate.DirState.IN_MEMORY_HASH_MODIFIED,
state._dirblock_state)
- self.assertFileEqual(content, state._filename)
+ self.assertEqual(content, self._read_state_content(state))
self.assertEqual(dirstate.DirState.IN_MEMORY_HASH_MODIFIED,
state._dirblock_state)
self.do_update_entry(state, 'd')
More information about the bazaar-commits
mailing list