Rev 3509: Add tests to ensure that you can skip subdirs, start exposing the function. in http://bzr.arbash-meinel.com/branches/bzr/1.6-dev/win32_find_files

John Arbash Meinel john at arbash-meinel.com
Thu Jul 17 03:21:43 BST 2008


At http://bzr.arbash-meinel.com/branches/bzr/1.6-dev/win32_find_files

------------------------------------------------------------
revno: 3509
revision-id: john at arbash-meinel.com-20080717022133-hcd78dqy2qn60drx
parent: john at arbash-meinel.com-20080716232929-pcyg06005uxpveav
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: win32_find_files
timestamp: Wed 2008-07-16 21:21:33 -0500
message:
  Add tests to ensure that you can skip subdirs, start exposing the function.
-------------- next part --------------
=== modified file 'bzrlib/osutils.py'
--- a/bzrlib/osutils.py	2008-07-16 23:29:29 +0000
+++ b/bzrlib/osutils.py	2008-07-17 02:21:33 +0000
@@ -1191,8 +1191,14 @@
         pass to os functions to affect the file in question. (such as os.lstat)
     """
     fs_encoding = _fs_enc.upper()
-    if (sys.platform == 'win32' or
-        fs_encoding not in ('UTF-8', 'US-ASCII', 'ANSI_X3.4-1968')): # ascii
+    if (sys.platform == 'win32'):
+        try:
+            from bzrlib._walkdirs_win32 import _walkdirs_utf8_win32_find_file
+        except ImportError:
+            return _walkdirs_unicode_to_utf8(top, prefix=prefix)
+        else:
+            return _walkdirs_utf8_win32_find_file(top, prefix=prefix)
+    if (fs_encoding not in ('UTF-8', 'US-ASCII', 'ANSI_X3.4-1968')): # ascii
         return _walkdirs_unicode_to_utf8(top, prefix=prefix)
     else:
         return _walkdirs_fs_utf8(top, prefix=prefix)

=== modified file 'bzrlib/tests/test__walkdirs_win32.py'
--- a/bzrlib/tests/test__walkdirs_win32.py	2008-07-16 23:29:29 +0000
+++ b/bzrlib/tests/test__walkdirs_win32.py	2008-07-17 02:21:33 +0000
@@ -39,15 +39,21 @@
 
     _test_needs_features = [WalkdirsWin32Feature]
 
-    def assertWalkdirs(self, expected, top, prefix=''):
+    def setUp(self):
+        super(TestWin32Finder, self).setUp()
         from bzrlib._walkdirs_win32 import (
-            _walkdirs_utf8_win32_find_file as walkdirs_utf8,
+            _walkdirs_utf8_win32_find_file
             )
-        finder = walkdirs_utf8(top, prefix=prefix)
+        self.walkdirs_utf8 = _walkdirs_utf8_win32_find_file
+
+    def _remove_stat_from_dirblock(self, dirblock):
+        return [info[:3] + info[4:] for info in dirblock]
+
+    def assertWalkdirs(self, expected, top, prefix=''):
+        finder = self.walkdirs_utf8(top, prefix=prefix)
         result = []
         for dirname, dirblock in finder:
-            block_no_stat = [info[:3] + info[4:] for info in dirblock]
-            result.append((dirname, block_no_stat))
+            result.append((dirname, self._remove_stat_from_dirblock(dirblock)))
         self.assertEqual(expected, result)
 
     def test_empty_directory(self):
@@ -58,3 +64,50 @@
         self.assertWalkdirs([
             (('', u'.'), [('foo', 'foo', 'file', u'./foo')])
             ], u'.')
+
+    def test_subdir(self):
+        self.build_tree(['foo', 'bar/', 'bar/baz'])
+        self.assertWalkdirs([
+            (('', u'.'), [('bar', 'bar', 'directory', u'./bar'),
+                          ('foo', 'foo', 'file', u'./foo'),
+                         ]),
+            (('bar', u'./bar'), [('bar/baz', 'baz', 'file', u'./bar/baz')]),
+            ], '.')
+        self.assertWalkdirs([
+            (('xxx', u'.'), [('xxx/bar', 'bar', 'directory', u'./bar'),
+                             ('xxx/foo', 'foo', 'file', u'./foo'),
+                            ]),
+            (('xxx/bar', u'./bar'), [('xxx/bar/baz', 'baz', 'file', u'./bar/baz')]),
+            ], '.', prefix='xxx')
+        self.assertWalkdirs([
+            (('', u'bar'), [('baz', 'baz', 'file', u'bar/baz')]),
+            ], 'bar')
+
+    def test_skip_subdir(self): 
+        self.build_tree(['a/', 'b/', 'c/', 'a/aa', 'b/bb', 'c/cc'])
+        base_dirblock = [('a', 'a', 'directory', u'./a'),
+                          ('b', 'b', 'directory', u'./b'),
+                          ('c', 'c', 'directory', u'./c'),
+                         ]
+        self.assertWalkdirs([
+            (('', u'.'), base_dirblock),
+            (('a', u'./a'), [('a/aa', 'aa', 'file', u'./a/aa')]),
+            (('b', u'./b'), [('b/bb', 'bb', 'file', u'./b/bb')]),
+            (('c', u'./c'), [('c/cc', 'cc', 'file', u'./c/cc')]),
+            ], '.')
+
+        walker = self.walkdirs_utf8('.')
+        dir_info, first_dirblock = walker.next()
+        self.assertEqual(('', u'.'), dir_info)
+        self.assertEqual(base_dirblock,
+                         self._remove_stat_from_dirblock(first_dirblock))
+        # Now, remove 'b' and it should be skipped on the next round
+        del first_dirblock[1]
+        dir_info, second_dirblock = walker.next()
+        second_dirblock = self._remove_stat_from_dirblock(second_dirblock)
+        self.assertEqual(('a', u'./a'), dir_info)
+        self.assertEqual([('a/aa', 'aa', 'file', u'./a/aa')], second_dirblock)
+        dir_info, third_dirblock = walker.next()
+        third_dirblock = self._remove_stat_from_dirblock(third_dirblock)
+        self.assertEqual(('c', u'./c'), dir_info)
+        self.assertEqual([('c/cc', 'cc', 'file', u'./c/cc')], third_dirblock)

=== modified file 'bzrlib/tests/test_osutils.py'
--- a/bzrlib/tests/test_osutils.py	2008-06-26 21:18:00 +0000
+++ b/bzrlib/tests/test_osutils.py	2008-07-17 02:21:33 +0000
@@ -1054,10 +1054,9 @@
     def assertStatIsCorrect(self, path, win32stat):
         os_stat = os.stat(path)
         self.assertEqual(os_stat.st_size, win32stat.st_size)
-        import pdb; pdb.set_trace()
-        self.assertEqual(int(os_stat.st_mtime), win32stat.st_mtime)
-        self.assertEqual(int(os_stat.st_ctime), win32stat.st_ctime)
-        self.assertEqual(int(os_stat.st_atime), win32stat.st_atime)
+        self.assertEqual(os_stat.st_mtime, win32stat.st_mtime)
+        self.assertEqual(os_stat.st_ctime, win32stat.st_ctime)
+        self.assertEqual(os_stat.st_atime, win32stat.st_atime)
         self.assertEqual(os_stat.st_dev, win32stat.st_dev)
         self.assertEqual(os_stat.st_ino, win32stat.st_ino)
         self.assertEqual(os_stat.st_mode, win32stat.st_mode)



More information about the bazaar-commits mailing list