Rev 4809: Move all the stat comparison and platform checkning code to assertEqualStat. in http://bazaar.launchpad.net/~jameinel/bzr/2.1.0b4-win32-accepted
John Arbash Meinel
john at arbash-meinel.com
Wed Nov 18 15:47:23 GMT 2009
At http://bazaar.launchpad.net/~jameinel/bzr/2.1.0b4-win32-accepted
------------------------------------------------------------
revno: 4809
revision-id: john at arbash-meinel.com-20091118154716-meiszr5ej7ohas3v
parent: john at arbash-meinel.com-20091118153947-54pqz74mfx0vy0bi
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.1.0b4-win32-accepted
timestamp: Wed 2009-11-18 09:47:16 -0600
message:
Move all the stat comparison and platform checkning code to assertEqualStat.
-------------- next part --------------
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py 2009-11-18 15:39:47 +0000
+++ b/bzrlib/tests/__init__.py 2009-11-18 15:47:16 +0000
@@ -1107,14 +1107,11 @@
self.assertEqual(mode, mode_test,
'mode mismatch %o != %o' % (mode, mode_test))
- def assertEqualStat(self, expected, actual, ignore_ino=False):
+ def assertEqualStat(self, expected, actual):
"""assert that expected and actual are the same stat result.
:param expected: A stat result.
:param actual: A stat result.
- :param ignore_ino: On Windows os.fstat() returns a value for st_ino,
- but os.lstat() returns 0 for st_ino. As such, we can't trust the
- value.
:raises AssertionError: If the expected and actual stat values differ
other than by atime.
"""
@@ -1124,9 +1121,13 @@
'st_mtime did not match')
self.assertEqual(expected.st_ctime, actual.st_ctime,
'st_ctime did not match')
- self.assertEqual(expected.st_dev, actual.st_dev,
- 'st_dev did not match')
- if not ignore_ino:
+ if sys.platform == 'win32':
+ # On Win32 both 'dev' and 'ino' cannot be trusted. In python2.4 it
+ # is 'dev' that varies, in python 2.5 (6?) it is st_ino that is
+ # odd. Regardless we shouldn't actually try to assert anything
+ # about their values
+ self.assertEqual(expected.st_dev, actual.st_dev,
+ 'st_dev did not match')
self.assertEqual(expected.st_ino, actual.st_ino,
'st_ino did not match')
self.assertEqual(expected.st_mode, actual.st_mode,
=== modified file 'bzrlib/tests/per_tree/test_get_file_with_stat.py'
--- a/bzrlib/tests/per_tree/test_get_file_with_stat.py 2009-11-08 03:49:39 +0000
+++ b/bzrlib/tests/per_tree/test_get_file_with_stat.py 2009-11-18 15:47:16 +0000
@@ -17,7 +17,6 @@
"""Test that all WorkingTree's implement get_file_with_stat."""
import os
-import sys
from bzrlib.tests.per_tree import TestCaseWithTree
@@ -25,13 +24,6 @@
class TestGetFileWithStat(TestCaseWithTree):
- # On Windows, 'os.fstat(f.fileno())' will return a value for 'st_ino' but
- # 'os.lstat(filename)' does *not* return a value. As such, we can't just
- # compare all attributes of the stat object to assert that fstat returns
- # identical content to lstat...
- # However, see also bug #478023
- ignore_ino = (sys.platform == 'win32')
-
def test_get_file_with_stat_id_only(self):
work_tree = self.make_branch_and_tree('.')
self.build_tree(['foo'])
@@ -40,14 +32,11 @@
tree.lock_read()
self.addCleanup(tree.unlock)
file_obj, statvalue = tree.get_file_with_stat('foo-id')
- try:
- if statvalue is not None:
- expected = os.lstat('foo')
- self.assertEqualStat(expected, statvalue,
- ignore_ino=self.ignore_ino)
- self.assertEqual(["contents of foo\n"], file_obj.readlines())
- finally:
- file_obj.close()
+ self.addCleanup(file_obj.close)
+ if statvalue is not None:
+ expected = os.lstat('foo')
+ self.assertEqualStat(expected, statvalue)
+ self.assertEqual(["contents of foo\n"], file_obj.readlines())
def test_get_file_with_stat_id_and_path(self):
work_tree = self.make_branch_and_tree('.')
@@ -57,11 +46,8 @@
tree.lock_read()
self.addCleanup(tree.unlock)
file_obj, statvalue = tree.get_file_with_stat('foo-id', 'foo')
- try:
- if statvalue is not None:
- expected = os.lstat('foo')
- self.assertEqualStat(expected, statvalue,
- ignore_ino=self.ignore_ino)
- self.assertEqual(["contents of foo\n"], file_obj.readlines())
- finally:
- file_obj.close()
+ self.addCleanup(file_obj.close)
+ if statvalue is not None:
+ expected = os.lstat('foo')
+ self.assertEqualStat(expected, statvalue)
+ self.assertEqual(["contents of foo\n"], file_obj.readlines())
=== modified file 'bzrlib/tests/test_workingtree_4.py'
--- a/bzrlib/tests/test_workingtree_4.py 2009-11-08 04:15:00 +0000
+++ b/bzrlib/tests/test_workingtree_4.py 2009-11-18 15:47:16 +0000
@@ -18,7 +18,6 @@
"""Tests for WorkingTreeFormat4"""
import os
-import sys
import time
from bzrlib import (
@@ -663,8 +662,7 @@
self.addCleanup(tree.unlock)
file_obj, statvalue = tree.get_file_with_stat('foo-id')
expected = os.lstat('foo')
- self.assertEqualStat(expected, statvalue,
- ignore_ino=(sys.platform == 'win32'))
+ self.assertEqualStat(expected, statvalue)
self.assertEqual(["contents of foo\n"], file_obj.readlines())
More information about the bazaar-commits
mailing list