~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_knit.py

  • Committer: Michael Hudson
  • Date: 2009-11-26 04:01:58 UTC
  • mto: This revision was merged to the branch mainline in revision 4830.
  • Revision ID: michael.hudson@canonical.com-20091126040158-3q6ukjpb38tlmxr9
test and fix

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007 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,
32
31
    )
33
32
from bzrlib.errors import (
34
33
    RevisionAlreadyPresent,
70
69
    )
71
70
 
72
71
 
73
 
compiled_knit_feature = tests.ModuleAvailableFeature(
74
 
                            'bzrlib._knit_load_data_pyx')
 
72
class _CompiledKnitFeature(Feature):
 
73
 
 
74
    def _probe(self):
 
75
        try:
 
76
            import bzrlib._knit_load_data_pyx
 
77
        except ImportError:
 
78
            return False
 
79
        return True
 
80
 
 
81
    def feature_name(self):
 
82
        return 'bzrlib._knit_load_data_pyx'
 
83
 
 
84
CompiledKnitFeature = _CompiledKnitFeature()
75
85
 
76
86
 
77
87
class KnitContentTestsMixin(object):
862
872
 
863
873
    def get_knit_index(self, transport, name, mode):
864
874
        mapper = ConstantMapper(name)
 
875
        orig = knit._load_data
 
876
        def reset():
 
877
            knit._load_data = orig
 
878
        self.addCleanup(reset)
865
879
        from bzrlib._knit_load_data_py import _load_data_py
866
 
        self.overrideAttr(knit, '_load_data', _load_data_py)
 
880
        knit._load_data = _load_data_py
867
881
        allow_writes = lambda: 'w' in mode
868
882
        return _KndxIndex(transport, mapper, lambda:None, allow_writes, lambda:True)
869
883
 
1294
1308
 
1295
1309
class LowLevelKnitIndexTests_c(LowLevelKnitIndexTests):
1296
1310
 
1297
 
    _test_needs_features = [compiled_knit_feature]
 
1311
    _test_needs_features = [CompiledKnitFeature]
1298
1312
 
1299
1313
    def get_knit_index(self, transport, name, mode):
1300
1314
        mapper = ConstantMapper(name)
 
1315
        orig = knit._load_data
 
1316
        def reset():
 
1317
            knit._load_data = orig
 
1318
        self.addCleanup(reset)
1301
1319
        from bzrlib._knit_load_data_pyx import _load_data_c
1302
 
        self.overrideAttr(knit, '_load_data', _load_data_c)
 
1320
        knit._load_data = _load_data_c
1303
1321
        allow_writes = lambda: mode == 'w'
1304
 
        return _KndxIndex(transport, mapper, lambda:None,
1305
 
                          allow_writes, lambda:True)
 
1322
        return _KndxIndex(transport, mapper, lambda:None, allow_writes, lambda:True)
1306
1323
 
1307
1324
 
1308
1325
class Test_KnitAnnotator(TestCaseWithMemoryTransport):