Rev 2325: Add path_info interface and move pack_stat into it. in file:///home/robertc/source/baz/dirstate2/

Robert Collins robertc at robertcollins.net
Fri Mar 9 04:23:55 GMT 2007


At file:///home/robertc/source/baz/dirstate2/

------------------------------------------------------------
revno: 2325
revision-id: robertc at robertcollins.net-20070309042352-6gabe2550go95z2d
parent: pqm at pqm.ubuntu.com-20070307115404-732b59c3532cf919
committer: Robert Collins <robertc at robertcollins.net>
branch nick: dirstate2
timestamp: Fri 2007-03-09 15:23:52 +1100
message:
  Add path_info interface and move pack_stat into it.
added:
  bzrlib/path_info.py            path_info.py-20070309041626-f8val8ukxzzzyudi-1
  bzrlib/path_info_python.py     path_info_python.py-20070309041626-f8val8ukxzzzyudi-2
  bzrlib/tests/path_info_implementations/ path_info_implementa-20070309041626-f8val8ukxzzzyudi-3
  bzrlib/tests/path_info_implementations/__init__.py __init__.py-20070309041626-f8val8ukxzzzyudi-4
  bzrlib/tests/path_info_implementations/test_path_info.py test_path_info.py-20070309041626-f8val8ukxzzzyudi-5
modified:
  bzrlib/dirstate.py             dirstate.py-20060728012006-d6mvoihjb3je9peu-1
  bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
  bzrlib/tests/test_selftest.py  test_selftest.py-20051202044319-c110a115d8c0456a
=== added file 'bzrlib/path_info.py'
--- a/bzrlib/path_info.py	1970-01-01 00:00:00 +0000
+++ b/bzrlib/path_info.py	2007-03-09 04:23:52 +0000
@@ -0,0 +1,24 @@
+# Copyright (C) 2007 Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+"""Functions for accessing data about paths."""
+
+from path_info_python import *
+
+def _test_modules():
+    import bzrlib.path_info_python
+    # todo, look for the C module.
+    return [bzrlib.path_info_python]

=== added file 'bzrlib/path_info_python.py'
--- a/bzrlib/path_info_python.py	1970-01-01 00:00:00 +0000
+++ b/bzrlib/path_info_python.py	2007-03-09 04:23:52 +0000
@@ -0,0 +1,39 @@
+# Copyright (C) 2007 Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+"""Functions for accessing data about paths.
+
+This is the pure python implementation.
+"""
+
+__all__ = ['pack_stat']
+
+import base64
+import struct
+
+
+def pack_stat(st, _encode=base64.encodestring, _pack=struct.pack):
+    """Convert stat values into a packed representation."""
+    # jam 20060614 it isn't really worth removing more entries if we
+    # are going to leave it in packed form.
+    # With only st_mtime and st_mode filesize is 5.5M and read time is 275ms
+    # With all entries filesize is 5.9M and read time is mabye 280ms
+    # well within the noise margin
+
+    # base64.encode always adds a final newline, so strip it off
+    return _encode(_pack('>llllll'
+        , st.st_size, int(st.st_mtime), int(st.st_ctime)
+        , st.st_dev, st.st_ino, st.st_mode))[:-1]

=== added directory 'bzrlib/tests/path_info_implementations'
=== added file 'bzrlib/tests/path_info_implementations/__init__.py'
--- a/bzrlib/tests/path_info_implementations/__init__.py	1970-01-01 00:00:00 +0000
+++ b/bzrlib/tests/path_info_implementations/__init__.py	2007-03-09 04:23:52 +0000
@@ -0,0 +1,80 @@
+# Copyright (C) 2007 Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+
+"""These tests the low level interfaces for getting path information.
+
+There may be multiple implementations, and this package adapts the tests to
+each implementation.
+
+Where a specific implementation is expected to behave differently (i.e. doing
+inode sorting) these are not tested by these interface tests, but by specific
+tests.
+"""
+
+from copy import deepcopy
+
+import bzrlib.errors as errors
+from bzrlib import path_info
+from bzrlib.tests import (
+                          adapt_modules,
+                          TestLoader,
+                          TestSuite,
+                          )
+from bzrlib.tests import TestCaseInTempDir
+
+
+class PathInfoTestAdapter(object):
+    """A tool to generate a suite testing multiple path_info implementations.
+
+    This is done by copying the test once for each path_info implementation
+    and injecting the path info module into it as path_info.
+    Each copy is also given a new id() to make it easy to identify.
+    """
+
+    def __init__(self, modules):
+        self._modules = modules
+    
+    def _clone_test(self, test, path_info_module, variation):
+        """Clone test for adaption."""
+        new_test = deepcopy(test)
+        new_test.path_info = path_info_module
+        def make_new_test_id():
+            new_id = "%s(%s)" % (test.id(), variation)
+            return lambda: new_id
+        new_test.id = make_new_test_id()
+        return new_test
+    
+    def adapt(self, test):
+        from bzrlib.tests import TestSuite
+        result = TestSuite()
+        for path_info_module in self._modules:
+            new_test = self._clone_test(
+                test,
+                path_info_module, path_info_module.__name__)
+            result.addTest(new_test)
+        return result
+
+
+def test_suite():
+    result = TestSuite()
+    test_path_info_implementations = [
+        'bzrlib.tests.path_info_implementations.test_path_info',
+        ]
+    adapter = PathInfoTestAdapter(path_info._test_modules())
+    loader = TestLoader()
+    adapt_modules(test_path_info_implementations, adapter, loader, result)
+    return result

=== added file 'bzrlib/tests/path_info_implementations/test_path_info.py'
--- a/bzrlib/tests/path_info_implementations/test_path_info.py	1970-01-01 00:00:00 +0000
+++ b/bzrlib/tests/path_info_implementations/test_path_info.py	2007-03-09 04:23:52 +0000
@@ -0,0 +1,33 @@
+# Copyright (C) 2007 Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+"""This tests the most primitive path_info call - path_info(abspath)."""
+
+import os
+
+from bzrlib.tests import TestCaseInTempDir
+
+
+class TestPathInfo(TestCaseInTempDir):
+
+    def disabled_test_info_file_non_utf8(self):
+        # a simple non-utf, non-executable test that should pass on all
+        # platforms.
+        self.build_tree(['file'])
+        result = self.path_info.path_info(os.abspath('file'))
+        stat = os.lstat(result)
+        expected = ('file')
+        self.assertEqual(expected, result)

=== modified file 'bzrlib/dirstate.py'
--- a/bzrlib/dirstate.py	2007-03-07 08:00:48 +0000
+++ b/bzrlib/dirstate.py	2007-03-09 04:23:52 +0000
@@ -200,12 +200,10 @@
 """
 
 
-import base64
 import bisect
 import errno
 import os
 from stat import S_IEXEC
-import struct
 import sys
 import time
 import zlib
@@ -217,6 +215,7 @@
     osutils,
     trace,
     )
+from bzrlib.path_info import pack_stat
 
 
 class _Bisector(object):
@@ -2282,18 +2281,3 @@
         if cur_split < dirname_split: lo = mid+1
         else: hi = mid
     return lo
-
-
-
-def pack_stat(st, _encode=base64.encodestring, _pack=struct.pack):
-    """Convert stat values into a packed representation."""
-    # jam 20060614 it isn't really worth removing more entries if we
-    # are going to leave it in packed form.
-    # With only st_mtime and st_mode filesize is 5.5M and read time is 275ms
-    # With all entries filesize is 5.9M and read time is mabye 280ms
-    # well within the noise margin
-
-    # base64.encode always adds a final newline, so strip it off
-    return _encode(_pack('>llllll'
-        , st.st_size, int(st.st_mtime), int(st.st_ctime)
-        , st.st_dev, st.st_ino, st.st_mode))[:-1]

=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py	2007-03-07 11:05:38 +0000
+++ b/bzrlib/tests/__init__.py	2007-03-09 04:23:52 +0000
@@ -116,6 +116,7 @@
     import bzrlib.tests.blackbox
     import bzrlib.tests.branch_implementations
     import bzrlib.tests.bzrdir_implementations
+    import bzrlib.tests.path_info_implementations
     import bzrlib.tests.interrepository_implementations
     import bzrlib.tests.interversionedfile_implementations
     import bzrlib.tests.intertree_implementations
@@ -128,6 +129,7 @@
             bzrlib.tests.blackbox,
             bzrlib.tests.branch_implementations,
             bzrlib.tests.bzrdir_implementations,
+            bzrlib.tests.path_info_implementations,
             bzrlib.tests.interrepository_implementations,
             bzrlib.tests.interversionedfile_implementations,
             bzrlib.tests.intertree_implementations,

=== modified file 'bzrlib/tests/test_selftest.py'
--- a/bzrlib/tests/test_selftest.py	2007-03-01 05:28:19 +0000
+++ b/bzrlib/tests/test_selftest.py	2007-03-09 04:23:52 +0000
@@ -285,6 +285,27 @@
         self.assertEqual(tests[1].transport_readonly_server, server2)
 
 
+class TestPathInfoTestAdapter(TestCase):
+    """A group of tests that test the path_info test adapter."""
+
+    def test_adapted_tests(self):
+        # check that constructor parameters are passed through to the adapted
+        # test.
+        from bzrlib.tests.path_info_implementations import PathInfoTestAdapter
+        input_test = TestPathInfoTestAdapter( "test_adapted_tests")
+        # path_info tests need one thing and one thing only: the module to be
+        # tested. These have a __name__ which is reference, so we use classes
+        # as test objects.
+        module1 = "a".__class__
+        module2 = int(5).__class__
+        adapter = PathInfoTestAdapter([module1, module2])
+        suite = adapter.adapt(input_test)
+        tests = list(iter(suite))
+        self.assertEqual(2, len(tests))
+        self.assertEqual(tests[0].path_info, module1)
+        self.assertEqual(tests[1].path_info, module2)
+
+
 class TestRevisionStoreProviderAdapter(TestCase):
     """A group of tests that test the RevisionStore test adapter."""
 



More information about the bazaar-commits mailing list