Rev 4798: merge the get-file-with-stat fixes. in http://bazaar.launchpad.net/~jameinel/bzr/2.1.0b4-win32-test-suite

John Arbash Meinel john at arbash-meinel.com
Sun Nov 8 04:16:36 GMT 2009


At http://bazaar.launchpad.net/~jameinel/bzr/2.1.0b4-win32-test-suite

------------------------------------------------------------
revno: 4798 [merge]
revision-id: john at arbash-meinel.com-20091108041625-t97xu97mammdhrls
parent: john at arbash-meinel.com-20091108032801-t3cvy8ny40321fin
parent: john at arbash-meinel.com-20091108041500-rj9t0wfq6h8ryudi
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.1.0b4-win32-test-suite
timestamp: Sat 2009-11-07 22:16:25 -0600
message:
  merge the get-file-with-stat fixes.
modified:
  bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
  bzrlib/tests/per_tree/test_get_file_with_stat.py test_get_file_with_s-20080922035909-lhdovrr36jpxmu0v-1
  bzrlib/tests/test_workingtree_4.py test_workingtree_4.p-20070223025758-531n3tznl3zacv2o-1
-------------- next part --------------
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py	2009-11-08 01:30:44 +0000
+++ b/bzrlib/tests/__init__.py	2009-11-08 04:16:25 +0000
@@ -1107,20 +1107,30 @@
         self.assertEqual(mode, mode_test,
                          'mode mismatch %o != %o' % (mode, mode_test))
 
-    def assertEqualStat(self, expected, actual):
+    def assertEqualStat(self, expected, actual, ignore_ino=False):
         """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.
         """
-        self.assertEqual(expected.st_size, actual.st_size)
-        self.assertEqual(expected.st_mtime, actual.st_mtime)
-        self.assertEqual(expected.st_ctime, actual.st_ctime)
-        self.assertEqual(expected.st_dev, actual.st_dev)
-        self.assertEqual(expected.st_ino, actual.st_ino)
-        self.assertEqual(expected.st_mode, actual.st_mode)
+        self.assertEqual(expected.st_size, actual.st_size,
+                         'st_size did not match')
+        self.assertEqual(expected.st_mtime, actual.st_mtime,
+                         '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:
+            self.assertEqual(expected.st_ino, actual.st_ino,
+                             'st_ino did not match')
+        self.assertEqual(expected.st_mode, actual.st_mode,
+                         'st_mode did not match')
 
     def assertLength(self, length, obj_with_len):
         """Assert that obj_with_len is of length length."""

=== modified file 'bzrlib/tests/per_tree/test_get_file_with_stat.py'
--- a/bzrlib/tests/per_tree/test_get_file_with_stat.py	2009-07-10 07:14:02 +0000
+++ b/bzrlib/tests/per_tree/test_get_file_with_stat.py	2009-11-08 03:49:39 +0000
@@ -17,12 +17,21 @@
 """Test that all WorkingTree's implement get_file_with_stat."""
 
 import os
+import sys
 
 from bzrlib.tests.per_tree import TestCaseWithTree
 
 
+
 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'])
@@ -31,10 +40,14 @@
         tree.lock_read()
         self.addCleanup(tree.unlock)
         file_obj, statvalue = tree.get_file_with_stat('foo-id')
-        if statvalue is not None:
-            expected = os.lstat('foo')
-            self.assertEqualStat(expected, statvalue)
-        self.assertEqual(["contents of foo\n"], file_obj.readlines())
+        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()
 
     def test_get_file_with_stat_id_and_path(self):
         work_tree = self.make_branch_and_tree('.')
@@ -44,8 +57,11 @@
         tree.lock_read()
         self.addCleanup(tree.unlock)
         file_obj, statvalue = tree.get_file_with_stat('foo-id', 'foo')
-        expected = os.lstat('foo')
-        if statvalue is not None:
-            expected = os.lstat('foo')
-            self.assertEqualStat(expected, statvalue)
-        self.assertEqual(["contents of foo\n"], file_obj.readlines())
+        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()

=== modified file 'bzrlib/tests/test_workingtree_4.py'
--- a/bzrlib/tests/test_workingtree_4.py	2009-08-28 05:00:33 +0000
+++ b/bzrlib/tests/test_workingtree_4.py	2009-11-08 04:15:00 +0000
@@ -18,6 +18,7 @@
 """Tests for WorkingTreeFormat4"""
 
 import os
+import sys
 import time
 
 from bzrlib import (
@@ -662,7 +663,8 @@
         self.addCleanup(tree.unlock)
         file_obj, statvalue = tree.get_file_with_stat('foo-id')
         expected = os.lstat('foo')
-        self.assertEqualStat(expected, statvalue)
+        self.assertEqualStat(expected, statvalue,
+                             ignore_ino=(sys.platform == 'win32'))
         self.assertEqual(["contents of foo\n"], file_obj.readlines())
 
 



More information about the bazaar-commits mailing list