~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_knit.py

  • Committer: Robert Collins
  • Date: 2010-05-06 23:41:35 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506234135-yivbzczw1sejxnxc
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
expected to return an object which can be used to unlock them. This reduces
duplicate code when using cleanups. The previous 'tokens's returned by
``Branch.lock_write`` and ``Repository.lock_write`` are now attributes
on the result of the lock_write. ``repository.RepositoryWriteLockResult``
and ``branch.BranchWriteLockResult`` document this. (Robert Collins)

``log._get_info_for_log_files`` now takes an add_cleanup callable.
(Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
 
1
# Copyright (C) 2006-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
28
28
    multiparent,
29
29
    osutils,
30
30
    pack,
 
31
    tests,
31
32
    )
32
33
from bzrlib.errors import (
33
34
    RevisionAlreadyPresent,
69
70
    )
70
71
 
71
72
 
72
 
class _CompiledKnitFeature(Feature):
73
 
 
74
 
    def _probe(self):
75
 
        try:
76
 
            import bzrlib._knit_load_data_c
77
 
        except ImportError:
78
 
            return False
79
 
        return True
80
 
 
81
 
    def feature_name(self):
82
 
        return 'bzrlib._knit_load_data_c'
83
 
 
84
 
CompiledKnitFeature = _CompiledKnitFeature()
 
73
compiled_knit_feature = tests.ModuleAvailableFeature(
 
74
                            'bzrlib._knit_load_data_pyx')
85
75
 
86
76
 
87
77
class KnitContentTestsMixin(object):
366
356
        :return: (versioned_file, reload_counter)
367
357
            versioned_file  a KnitVersionedFiles using the packs for access
368
358
        """
369
 
        builder = self.make_branch_builder('.')
 
359
        builder = self.make_branch_builder('.', format="1.9")
370
360
        builder.start_series()
371
361
        builder.build_snapshot('rev-1', None, [
372
362
            ('add', ('', 'root-id', 'directory', None)),
872
862
 
873
863
    def get_knit_index(self, transport, name, mode):
874
864
        mapper = ConstantMapper(name)
875
 
        orig = knit._load_data
876
 
        def reset():
877
 
            knit._load_data = orig
878
 
        self.addCleanup(reset)
879
865
        from bzrlib._knit_load_data_py import _load_data_py
880
 
        knit._load_data = _load_data_py
 
866
        self.overrideAttr(knit, '_load_data', _load_data_py)
881
867
        allow_writes = lambda: 'w' in mode
882
868
        return _KndxIndex(transport, mapper, lambda:None, allow_writes, lambda:True)
883
869
 
1308
1294
 
1309
1295
class LowLevelKnitIndexTests_c(LowLevelKnitIndexTests):
1310
1296
 
1311
 
    _test_needs_features = [CompiledKnitFeature]
 
1297
    _test_needs_features = [compiled_knit_feature]
1312
1298
 
1313
1299
    def get_knit_index(self, transport, name, mode):
1314
1300
        mapper = ConstantMapper(name)
1315
 
        orig = knit._load_data
1316
 
        def reset():
1317
 
            knit._load_data = orig
1318
 
        self.addCleanup(reset)
1319
 
        from bzrlib._knit_load_data_c import _load_data_c
1320
 
        knit._load_data = _load_data_c
 
1301
        from bzrlib._knit_load_data_pyx import _load_data_c
 
1302
        self.overrideAttr(knit, '_load_data', _load_data_c)
1321
1303
        allow_writes = lambda: mode == 'w'
1322
 
        return _KndxIndex(transport, mapper, lambda:None, allow_writes, lambda:True)
 
1304
        return _KndxIndex(transport, mapper, lambda:None,
 
1305
                          allow_writes, lambda:True)
1323
1306
 
1324
1307
 
1325
1308
class Test_KnitAnnotator(TestCaseWithMemoryTransport):
2230
2213
        # self.assertEqual([("annotate", key_basis)], basis.calls)
2231
2214
        self.assertEqual([('get_parent_map', set([key_basis])),
2232
2215
            ('get_parent_map', set([key_basis])),
2233
 
            ('get_record_stream', [key_basis], 'unordered', True)],
 
2216
            ('get_record_stream', [key_basis], 'topological', True)],
2234
2217
            basis.calls)
2235
2218
 
2236
2219
    def test_check(self):
2342
2325
        # ask which fallbacks have which parents.
2343
2326
        self.assertEqual([
2344
2327
            ("get_parent_map", set([key_basis, key_basis_2, key_missing])),
2345
 
            # unordered is asked for by the underlying worker as it still
2346
 
            # buffers everything while answering - which is a problem!
2347
 
            ("get_record_stream", [key_basis_2, key_basis], 'unordered', True)],
 
2328
            # topological is requested from the fallback, because that is what
 
2329
            # was requested at the top level.
 
2330
            ("get_record_stream", [key_basis_2, key_basis], 'topological', True)],
2348
2331
            calls)
2349
2332
 
2350
2333
    def test_get_record_stream_unordered_deltas(self):
2571
2554
        last_call = basis.calls[-1]
2572
2555
        self.assertEqual('get_record_stream', last_call[0])
2573
2556
        self.assertEqual(set([key_left, key_right]), set(last_call[1]))
2574
 
        self.assertEqual('unordered', last_call[2])
 
2557
        self.assertEqual('topological', last_call[2])
2575
2558
        self.assertEqual(True, last_call[3])
2576
2559
 
2577
2560