Rev 3372: Refactor tree_implementation scenario creation (abentley) in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Thu Apr 17 11:07:22 BST 2008


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 3372
revision-id:pqm at pqm.ubuntu.com-20080417100712-7pdn4q0fg9eoy3a2
parent: pqm at pqm.ubuntu.com-20080417075535-shpsll72xkrz5l3m
parent: aaron at aaronbentley.com-20080412060329-qprwz8yqyxkp2m09
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Thu 2008-04-17 11:07:12 +0100
message:
  Refactor tree_implementation scenario creation (abentley)
modified:
  bzrlib/tests/intertree_implementations/__init__.py __init__.py-20060724101752-09ysswo1a92uqyoz-3
  bzrlib/tests/test_selftest.py  test_selftest.py-20051202044319-c110a115d8c0456a
  bzrlib/tests/tree_implementations/__init__.py __init__.py-20060717075546-420s7b0bj9hzeowi-2
  bzrlib/tests/workingtree_implementations/__init__.py __init__.py-20060203003124-b2aa5aca21a8bfad
    ------------------------------------------------------------
    revno: 3363.1.6
    revision-id:aaron at aaronbentley.com-20080412060329-qprwz8yqyxkp2m09
    parent: aaron at aaronbentley.com-20080411230502-xr6qq4epdxtoy6el
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: refactor-intertree
    timestamp: Sat 2008-04-12 02:03:29 -0400
    message:
      Add docs
    modified:
      bzrlib/tests/intertree_implementations/__init__.py __init__.py-20060724101752-09ysswo1a92uqyoz-3
      bzrlib/tests/tree_implementations/__init__.py __init__.py-20060717075546-420s7b0bj9hzeowi-2
      bzrlib/tests/workingtree_implementations/__init__.py __init__.py-20060203003124-b2aa5aca21a8bfad
    ------------------------------------------------------------
    revno: 3363.1.5
    revision-id:aaron at aaronbentley.com-20080411230502-xr6qq4epdxtoy6el
    parent: aaron at aaronbentley.com-20080411225538-tcohbe6qgm8bufct
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: refactor-intertree
    timestamp: Fri 2008-04-11 19:05:02 -0400
    message:
      Update tests
    modified:
      bzrlib/tests/test_selftest.py  test_selftest.py-20051202044319-c110a115d8c0456a
    ------------------------------------------------------------
    revno: 3363.1.4
    revision-id:aaron at aaronbentley.com-20080411225538-tcohbe6qgm8bufct
    parent: aaron at aaronbentley.com-20080411194715-tmr73uvu8ycyoo4r
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: refactor-intertree
    timestamp: Fri 2008-04-11 18:55:38 -0400
    message:
      Fix conversions for intertree
    modified:
      bzrlib/tests/intertree_implementations/__init__.py __init__.py-20060724101752-09ysswo1a92uqyoz-3
    ------------------------------------------------------------
    revno: 3363.1.3
    revision-id:aaron at aaronbentley.com-20080411194715-tmr73uvu8ycyoo4r
    parent: aaron at aaronbentley.com-20080411193418-lzpzicebh5is2nd7
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: refactor-intertree
    timestamp: Fri 2008-04-11 15:47:15 -0400
    message:
      Hide workingtree_to_test_tree behind a method, to get bound self
    modified:
      bzrlib/tests/tree_implementations/__init__.py __init__.py-20060717075546-420s7b0bj9hzeowi-2
    ------------------------------------------------------------
    revno: 3363.1.2
    revision-id:aaron at aaronbentley.com-20080411193418-lzpzicebh5is2nd7
    parent: aaron at aaronbentley.com-20080411191850-g4h43o2d8dwpqmco
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: refactor-intertree
    timestamp: Fri 2008-04-11 15:34:18 -0400
    message:
      Add TestCase as converter param
    modified:
      bzrlib/tests/tree_implementations/__init__.py __init__.py-20060717075546-420s7b0bj9hzeowi-2
    ------------------------------------------------------------
    revno: 3363.1.1
    revision-id:aaron at aaronbentley.com-20080411191850-g4h43o2d8dwpqmco
    parent: pqm at pqm.ubuntu.com-20080411111440-f12xc0wel9kail53
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: preview-tree
    timestamp: Fri 2008-04-11 15:18:50 -0400
    message:
      Refactor intertree scenario creation
    modified:
      bzrlib/tests/tree_implementations/__init__.py __init__.py-20060717075546-420s7b0bj9hzeowi-2
      bzrlib/tests/workingtree_implementations/__init__.py __init__.py-20060203003124-b2aa5aca21a8bfad
=== modified file 'bzrlib/tests/intertree_implementations/__init__.py'
--- a/bzrlib/tests/intertree_implementations/__init__.py	2007-06-28 07:15:28 +0000
+++ b/bzrlib/tests/intertree_implementations/__init__.py	2008-04-12 06:03:29 +0000
@@ -89,7 +89,7 @@
                 "mutable_trees_to_test_trees":mutable_trees_to_test_trees,
                 # workingtree_to_test_tree is set to disable changing individual,
                 # trees: instead the mutable_trees_to_test_trees helper is used.,
-                "workingtree_to_test_tree":return_parameter,
+                "_workingtree_to_test_tree": return_parameter,
                 })
             result.append(scenario)
         return result

=== modified file 'bzrlib/tests/test_selftest.py'
--- a/bzrlib/tests/test_selftest.py	2008-04-07 04:44:56 +0000
+++ b/bzrlib/tests/test_selftest.py	2008-04-11 23:05:02 +0000
@@ -510,18 +510,18 @@
         self.assertEqual(tests[0].bzrdir_format, formats[0][1])
         self.assertEqual(tests[0].transport_server, server1)
         self.assertEqual(tests[0].transport_readonly_server, server2)
-        self.assertEqual(tests[0].workingtree_to_test_tree, return_parameter)
+        self.assertEqual(tests[0]._workingtree_to_test_tree, return_parameter)
         self.assertEqual(tests[1].workingtree_format, formats[1][0])
         self.assertEqual(tests[1].bzrdir_format, formats[1][1])
         self.assertEqual(tests[1].transport_server, server1)
         self.assertEqual(tests[1].transport_readonly_server, server2)
-        self.assertEqual(tests[1].workingtree_to_test_tree, return_parameter)
+        self.assertEqual(tests[1]._workingtree_to_test_tree, return_parameter)
         self.assertIsInstance(tests[2].workingtree_format, default_format)
         #self.assertEqual(tests[2].bzrdir_format,
         #                 default_format._matchingbzrdir)
         self.assertEqual(tests[2].transport_server, server1)
         self.assertEqual(tests[2].transport_readonly_server, server2)
-        self.assertEqual(tests[2].workingtree_to_test_tree,
+        self.assertEqual(tests[2]._workingtree_to_test_tree,
             revision_tree_from_workingtree)
 
 
@@ -562,14 +562,14 @@
         self.assertEqual(tests[0].workingtree_format, formats[0][1])
         self.assertEqual(tests[0].workingtree_format_to, formats[0][2])
         self.assertEqual(tests[0].mutable_trees_to_test_trees, formats[0][3])
-        self.assertEqual(tests[0].workingtree_to_test_tree, return_parameter)
+        self.assertEqual(tests[0]._workingtree_to_test_tree, return_parameter)
         self.assertEqual(tests[0].transport_server, server1)
         self.assertEqual(tests[0].transport_readonly_server, server2)
         self.assertEqual(tests[1].intertree_class, formats[1][0])
         self.assertEqual(tests[1].workingtree_format, formats[1][1])
         self.assertEqual(tests[1].workingtree_format_to, formats[1][2])
         self.assertEqual(tests[1].mutable_trees_to_test_trees, formats[1][3])
-        self.assertEqual(tests[1].workingtree_to_test_tree, return_parameter)
+        self.assertEqual(tests[1]._workingtree_to_test_tree, return_parameter)
         self.assertEqual(tests[1].transport_server, server1)
         self.assertEqual(tests[1].transport_readonly_server, server2)
 

=== modified file 'bzrlib/tests/tree_implementations/__init__.py'
--- a/bzrlib/tests/tree_implementations/__init__.py	2008-03-15 09:25:32 +0000
+++ b/bzrlib/tests/tree_implementations/__init__.py	2008-04-12 06:03:29 +0000
@@ -56,18 +56,18 @@
     )
 
 
-def return_parameter(something):
+def return_parameter(testcase, something):
     """A trivial thunk to return its input."""
     return something
 
 
-def revision_tree_from_workingtree(tree):
+def revision_tree_from_workingtree(testcase, tree):
     """Create a revision tree from a working tree."""
     revid = tree.commit('save tree', allow_pointless=True, recursive=None)
     return tree.branch.repository.revision_tree(revid)
 
 
-def _dirstate_tree_from_workingtree(tree):
+def _dirstate_tree_from_workingtree(testcase, tree):
     revid = tree.commit('save tree', allow_pointless=True)
     return tree.basis_tree()
 
@@ -76,7 +76,7 @@
 
     def test_revision_tree_from_workingtree(self):
         tree = self.make_branch_and_tree('.')
-        tree = revision_tree_from_workingtree(tree)
+        tree = revision_tree_from_workingtree(self, tree)
         self.assertIsInstance(tree, RevisionTree)
 
 
@@ -89,6 +89,9 @@
         made_control.create_branch()
         return self.workingtree_format.initialize(made_control)
 
+    def workingtree_to_test_tree(self, tree):
+        return self._workingtree_to_test_tree(self, tree)
+
     def _convert_tree(self, tree, converter=None):
         """helper to convert using the converter or a supplied one."""
         # convert that to the final shape
@@ -301,22 +304,34 @@
         # now adjust the scenarios and add the non-working-tree tree scenarios.
         for scenario in self.scenarios:
             # for working tree adapted tests, preserve the tree
-            scenario[1]["workingtree_to_test_tree"] = return_parameter
+            scenario[1]["_workingtree_to_test_tree"] = return_parameter
         # add RevisionTree scenario
-        # this is the 'default format' in that it's used to test the generic InterTree
-        # code.
-        default_format = WorkingTreeFormat3()
-        self.scenarios.append(self.formats_to_scenarios([
-            (default_format, default_format._matchingbzrdir)])[0])
-        self.scenarios[-1] = (RevisionTree.__name__, self.scenarios[-1][1])
-        self.scenarios[-1][1]["workingtree_to_test_tree"] = revision_tree_from_workingtree
-
-        # also test WorkingTree4's RevisionTree implementation which is specialised.
-        dirstate_format = WorkingTreeFormat4()
-        self.scenarios.append(self.formats_to_scenarios([
-            (dirstate_format, dirstate_format._matchingbzrdir)])[0])
-        self.scenarios[-1] = (DirStateRevisionTree.__name__, self.scenarios[-1][1])
-        self.scenarios[-1][1]["workingtree_to_test_tree"] = _dirstate_tree_from_workingtree
+        self.scenarios.append(self.create_tree_scenario(RevisionTree.__name__,
+                              revision_tree_from_workingtree,))
+
+        # also test WorkingTree4's RevisionTree implementation which is
+        # specialised.
+        self.scenarios.append(self.create_tree_scenario(
+            DirStateRevisionTree.__name__, _dirstate_tree_from_workingtree,
+            WorkingTreeFormat4()))
+
+    def create_tree_scenario(self, name, converter, workingtree_format=None):
+        """Create a scenario for the specified converter
+
+        :param name: The name to append to tests using this converter
+        :param converter: A function that converts a workingtree into the
+            desired format.
+        :param workingtree_format: The particular workingtree format to
+            convert from.
+        :return: a (name, options) tuple, where options is a dict of values
+            to be used as members of the TestCase.
+        """
+        if workingtree_format is None:
+            workingtree_format = WorkingTreeFormat3()
+        scenario_options = WorkingTreeTestProviderAdapter.create_scenario(self,
+            workingtree_format, workingtree_format._matchingbzrdir)[1]
+        scenario_options["_workingtree_to_test_tree"] = converter
+        return name, scenario_options
 
 
 def test_suite():

=== modified file 'bzrlib/tests/workingtree_implementations/__init__.py'
--- a/bzrlib/tests/workingtree_implementations/__init__.py	2007-07-12 07:22:52 +0000
+++ b/bzrlib/tests/workingtree_implementations/__init__.py	2008-04-12 06:03:29 +0000
@@ -59,15 +59,26 @@
     
         result = []
         for workingtree_format, bzrdir_format in formats:
-            scenario = (workingtree_format.__class__.__name__, {
-                "transport_server":self._transport_server,
-                "transport_readonly_server":self._transport_readonly_server,
-                "bzrdir_format":bzrdir_format,
-                "workingtree_format":workingtree_format,
-                })
-            result.append(scenario)
+            result.append(self.create_scenario(workingtree_format,
+                          bzrdir_format))
         return result
 
+    def create_scenario(self, workingtree_format, bzrdir_format):
+        """Create a scenario for the specified converter
+
+        :param workingtree_format: The particular workingtree format to test.
+        :param bzrdir_format: The bzrdir format to test.
+        :return: a (name, options) tuple, where options is a dict of values
+            to be used as members of the TestCase.
+        """
+        scenario_options = {
+            "transport_server": self._transport_server,
+            "transport_readonly_server": self._transport_readonly_server,
+            "bzrdir_format": bzrdir_format,
+            "workingtree_format": workingtree_format,
+            }
+        return workingtree_format.__class__.__name__, scenario_options
+
 
 class TestCaseWithWorkingTree(TestCaseWithBzrDir):
 




More information about the bazaar-commits mailing list