~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/tree_implementations/__init__.py

  • Committer: Matt Nordhoff
  • Date: 2009-04-04 02:50:01 UTC
  • mfrom: (4253 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4256.
  • Revision ID: mnordhoff@mattnordhoff.com-20090404025001-z1403k0tatmc8l91
Merge bzr.dev, fixing conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
 
18
18
"""Tree implementation tests for bzr.
34
34
    )
35
35
from bzrlib.transport import get_transport
36
36
from bzrlib.tests import (
37
 
                          adapt_modules,
 
37
                          multiply_tests,
38
38
                          default_transport,
39
39
                          TestCaseWithTransport,
40
40
                          TestSkipped,
41
41
                          )
42
42
from bzrlib.tests.bzrdir_implementations.test_bzrdir import TestCaseWithBzrDir
43
43
from bzrlib.tests.workingtree_implementations import (
44
 
    WorkingTreeTestProviderAdapter,
 
44
    make_scenarios as wt_make_scenarios,
 
45
    make_scenario as wt_make_scenario,
45
46
    )
46
47
from bzrlib.revision import NULL_REVISION
47
48
from bzrlib.revisiontree import RevisionTree
125
126
 
126
127
    def get_tree_no_parents_no_content(self, empty_tree, converter=None):
127
128
        """Make a tree with no parents and no contents from empty_tree.
128
 
        
 
129
 
129
130
        :param empty_tree: A working tree with no content and no parents to
130
131
            modify.
131
132
        """
147
148
 
148
149
    def get_tree_no_parents_abc_content_2(self, tree, converter=None):
149
150
        """return a test tree with a, b/, b/c contents.
150
 
        
 
151
 
151
152
        This variation changes the content of 'a' to foobar\n.
152
153
        """
153
154
        self._make_abc_tree(tree)
160
161
 
161
162
    def get_tree_no_parents_abc_content_3(self, tree, converter=None):
162
163
        """return a test tree with a, b/, b/c contents.
163
 
        
 
164
 
164
165
        This variation changes the executable flag of b/c to True.
165
166
        """
166
167
        self._make_abc_tree(tree)
172
173
 
173
174
    def get_tree_no_parents_abc_content_4(self, tree, converter=None):
174
175
        """return a test tree with d, b/, b/c contents.
175
 
        
 
176
 
176
177
        This variation renames a to d.
177
178
        """
178
179
        self._make_abc_tree(tree)
181
182
 
182
183
    def get_tree_no_parents_abc_content_5(self, tree, converter=None):
183
184
        """return a test tree with d, b/, b/c contents.
184
 
        
 
185
 
185
186
        This variation renames a to d and alters its content to 'bar\n'.
186
187
        """
187
188
        self._make_abc_tree(tree)
195
196
 
196
197
    def get_tree_no_parents_abc_content_6(self, tree, converter=None):
197
198
        """return a test tree with a, b/, e contents.
198
 
        
 
199
 
199
200
        This variation renames b/c to e, and makes it executable.
200
201
        """
201
202
        self._make_abc_tree(tree)
235
236
        where each component has the type of its name -
236
237
        i.e. '1file..' is afile.
237
238
 
238
 
        note that the order of the paths and fileids is deliberately 
 
239
        note that the order of the paths and fileids is deliberately
239
240
        mismatched to ensure that the result order is path based.
240
241
        """
241
242
        tree = self.make_branch_and_tree('.')
319
320
        return self.workingtree_to_test_tree(tree)
320
321
 
321
322
 
322
 
class TreeTestProviderAdapter(WorkingTreeTestProviderAdapter):
 
323
def make_scenarios(transport_server, transport_readonly_server, formats):
323
324
    """Generate test suites for each Tree implementation in bzrlib.
324
325
 
325
326
    Currently this covers all working tree formats, and RevisionTree and
326
327
    DirStateRevisionTree by committing a working tree to create the revision
327
328
    tree.
328
329
    """
329
 
 
330
 
    def __init__(self, transport_server, transport_readonly_server, formats):
331
 
        """Create a TreeTestProviderAdapter.
332
 
 
333
 
        :param formats: [workingtree_format]
334
 
        """
335
 
        super(TreeTestProviderAdapter, self).__init__(transport_server,
336
 
            transport_readonly_server, formats)
337
 
        # now adjust the scenarios and add the non-working-tree tree scenarios.
338
 
        for scenario in self.scenarios:
339
 
            # for working tree adapted tests, preserve the tree
340
 
            scenario[1]["_workingtree_to_test_tree"] = return_parameter
 
330
    scenarios = wt_make_scenarios(transport_server, transport_readonly_server,
 
331
        formats)
 
332
    # now adjust the scenarios and add the non-working-tree tree scenarios.
 
333
    for scenario in scenarios:
 
334
        # for working tree format tests, preserve the tree
 
335
        scenario[1]["_workingtree_to_test_tree"] = return_parameter
341
336
        # add RevisionTree scenario
342
 
        self.scenarios.append(self.create_tree_scenario(RevisionTree.__name__,
343
 
                              revision_tree_from_workingtree,))
344
 
 
345
 
        # also test WorkingTree4's RevisionTree implementation which is
346
 
        # specialised.
347
 
        self.scenarios.append(self.create_tree_scenario(
348
 
            DirStateRevisionTree.__name__, _dirstate_tree_from_workingtree,
349
 
            WorkingTreeFormat4()))
350
 
        self.scenarios.append(self.create_tree_scenario(
351
 
            DirStateRevisionTree.__name__, _dirstate_tree_from_workingtree,
352
 
            WorkingTreeFormat5()))
353
 
        self.scenarios.append(self.create_tree_scenario('PreviewTree',
354
 
            preview_tree_pre))
355
 
        self.scenarios.append(self.create_tree_scenario('PreviewTreePost',
356
 
            preview_tree_post))
357
 
 
358
 
    def create_tree_scenario(self, name, converter, workingtree_format=None):
359
 
        """Create a scenario for the specified converter
360
 
 
361
 
        :param name: The name to append to tests using this converter
362
 
        :param converter: A function that converts a workingtree into the
363
 
            desired format.
364
 
        :param workingtree_format: The particular workingtree format to
365
 
            convert from.
366
 
        :return: a (name, options) tuple, where options is a dict of values
367
 
            to be used as members of the TestCase.
368
 
        """
369
 
        if workingtree_format is None:
370
 
            workingtree_format = WorkingTreeFormat._default_format
371
 
        scenario_options = WorkingTreeTestProviderAdapter.create_scenario(self,
372
 
            workingtree_format)[1]
373
 
        scenario_options["_workingtree_to_test_tree"] = converter
374
 
        return name, scenario_options
375
 
 
376
 
 
377
 
def load_tests(basic_tests, module, loader):
378
 
    result = loader.suiteClass()
379
 
    # add the tests for this module
380
 
    result.addTests(basic_tests)
381
 
 
382
 
    test_tree_implementations = [
 
337
    workingtree_format = WorkingTreeFormat._default_format
 
338
    scenarios.append((RevisionTree.__name__,
 
339
        create_tree_scenario(transport_server, transport_readonly_server,
 
340
        workingtree_format, revision_tree_from_workingtree,)))
 
341
 
 
342
    # also test WorkingTree4/5's RevisionTree implementation which is
 
343
    # specialised.
 
344
    # XXX: Ask igc if WT5 revision tree actually is different.
 
345
    scenarios.append((DirStateRevisionTree.__name__ + ",WT4",
 
346
        create_tree_scenario(transport_server, transport_readonly_server,
 
347
        WorkingTreeFormat4(), _dirstate_tree_from_workingtree)))
 
348
    scenarios.append((DirStateRevisionTree.__name__ + ",WT5",
 
349
        create_tree_scenario(transport_server, transport_readonly_server,
 
350
        WorkingTreeFormat5(), _dirstate_tree_from_workingtree)))
 
351
    scenarios.append(("PreviewTree", create_tree_scenario(transport_server,
 
352
        transport_readonly_server, workingtree_format, preview_tree_pre)))
 
353
    scenarios.append(("PreviewTreePost", create_tree_scenario(transport_server,
 
354
        transport_readonly_server, workingtree_format, preview_tree_post)))
 
355
    return scenarios
 
356
 
 
357
 
 
358
def create_tree_scenario(transport_server, transport_readonly_server,
 
359
    workingtree_format, converter):
 
360
    """Create a scenario for the specified converter
 
361
 
 
362
    :param name: The name to append to tests using this converter
 
363
    :param converter: A function that converts a workingtree into the
 
364
        desired format.
 
365
    :param workingtree_format: The particular workingtree format to
 
366
        convert from.
 
367
    :return: a (name, options) tuple, where options is a dict of values
 
368
        to be used as members of the TestCase.
 
369
    """
 
370
    scenario_options = wt_make_scenario(transport_server, transport_readonly_server,
 
371
        workingtree_format)
 
372
    scenario_options["_workingtree_to_test_tree"] = converter
 
373
    return scenario_options
 
374
 
 
375
 
 
376
def load_tests(standard_tests, module, loader):
 
377
    submod_tests = loader.loadTestsFromModuleNames([
383
378
        'bzrlib.tests.tree_implementations.test_annotate_iter',
384
379
        'bzrlib.tests.tree_implementations.test_get_file_mtime',
385
380
        'bzrlib.tests.tree_implementations.test_get_root_id',
392
387
        'bzrlib.tests.tree_implementations.test_test_trees',
393
388
        'bzrlib.tests.tree_implementations.test_tree',
394
389
        'bzrlib.tests.tree_implementations.test_walkdirs',
395
 
        ]
396
 
 
397
 
    adapter = TreeTestProviderAdapter(
 
390
        ])
 
391
    scenarios = make_scenarios(
398
392
        default_transport,
399
393
        # None here will cause a readonly decorator to be created
400
394
        # by the TestCaseWithTransport.get_readonly_transport method.
401
395
        None,
402
396
        WorkingTreeFormat._formats.values() + _legacy_formats)
403
 
 
404
397
    # add the tests for the sub modules
405
 
    adapt_modules(test_tree_implementations, adapter, loader, result)
406
 
    return result
 
398
    return multiply_tests(submod_tests, scenarios, standard_tests)