~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_weave.py

(jameinel) Allow 'bzr serve' to interpret SIGHUP as a graceful shutdown.
 (bug #795025) (John A Meinel)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 Canonical Ltd
 
1
# Copyright (C) 2005-2009, 2011 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
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
# TODO: tests regarding version names
19
 
# TODO: rbc 20050108 test that join does not leave an inconsistent weave 
 
19
# TODO: rbc 20050108 test that join does not leave an inconsistent weave
20
20
#       if it fails.
21
21
 
22
22
"""test suite for weave algorithm"""
28
28
    )
29
29
from bzrlib.osutils import sha_string
30
30
from bzrlib.tests import TestCase, TestCaseInTempDir
31
 
from bzrlib.weave import Weave, WeaveFormatError, WeaveError
 
31
from bzrlib.weave import Weave, WeaveFormatError
32
32
from bzrlib.weavefile import write_weave, read_weave
33
33
 
34
34
 
64
64
 
65
65
class WeaveContains(TestBase):
66
66
    """Weave __contains__ operator"""
 
67
 
67
68
    def runTest(self):
68
69
        k = Weave(get_scope=lambda:None)
69
70
        self.assertFalse('foo' in k)
72
73
 
73
74
 
74
75
class Easy(TestBase):
 
76
 
75
77
    def runTest(self):
76
78
        k = Weave()
77
79
 
78
80
 
79
81
class AnnotateOne(TestBase):
 
82
 
80
83
    def runTest(self):
81
84
        k = Weave()
82
85
        k.add_lines('text0', [], TEXT_0)
86
89
 
87
90
class InvalidAdd(TestBase):
88
91
    """Try to use invalid version number during add."""
 
92
 
89
93
    def runTest(self):
90
94
        k = Weave()
91
95
 
107
111
 
108
112
 
109
113
class InvalidRepeatedAdd(TestBase):
 
114
 
110
115
    def runTest(self):
111
116
        k = Weave()
112
117
        k.add_lines('basis', [], TEXT_0)
121
126
                          'text0',
122
127
                          ['basis'],         # not the right parents
123
128
                          TEXT_0)
124
 
        
 
129
 
125
130
 
126
131
class InsertLines(TestBase):
127
132
    """Store a revision that adds one line to the original.
170
175
              ['text0', 'text1', 'text3'],
171
176
              ['line 1', 'aaa', 'middle line', 'bbb', 'line 2', 'ccc'])
172
177
 
173
 
        self.assertEqual(k.annotate('text4'), 
 
178
        self.assertEqual(k.annotate('text4'),
174
179
                         [('text0', 'line 1'),
175
180
                          ('text4', 'aaa'),
176
181
                          ('text3', 'middle line'),
189
194
        base_text = ['one', 'two', 'three', 'four']
190
195
 
191
196
        k.add_lines('text0', [], base_text)
192
 
        
 
197
 
193
198
        texts = [['one', 'two', 'three'],
194
199
                 ['two', 'three', 'four'],
195
200
                 ['one', 'four'],
226
231
                ]
227
232
        ################################### SKIPPED
228
233
        # Weave.get doesn't trap this anymore
229
 
        return 
 
234
        return
230
235
 
231
236
        self.assertRaises(WeaveFormatError,
232
237
                          k.get_lines,
233
 
                          0)        
 
238
                          0)
234
239
 
235
240
 
236
241
class CannedDelete(TestBase):
278
283
                'line to be deleted',
279
284
                (']', 1),
280
285
                ('{', 1),
281
 
                'replacement line',                
 
286
                'replacement line',
282
287
                ('}', 1),
283
288
                'last line',
284
289
                ('}', 0),
321
326
 
322
327
        ################################### SKIPPED
323
328
        # Weave.get doesn't trap this anymore
324
 
        return 
 
329
        return
325
330
 
326
331
 
327
332
        self.assertRaises(WeaveFormatError,
399
404
                          '  added in version 1',
400
405
                          '  also from v1',
401
406
                          '}'])
402
 
                       
 
407
 
403
408
        self.assertEqual(k.get_lines(2),
404
409
                         ['foo {',
405
410
                          '  added in v2',
411
416
                          '  added in v2',
412
417
                          '  also from v1',
413
418
                          '}'])
414
 
                         
 
419
 
415
420
 
416
421
class DeleteLines2(TestBase):
417
422
    """Test recording revisions that delete lines.
493
498
                ('}', 1),
494
499
                ('{', 2),
495
500
                "alternative second line",
496
 
                ('}', 2),                
 
501
                ('}', 2),
497
502
                ]
498
503
 
499
504
        k._sha1s = [sha_string('first line')
521
526
 
522
527
        text0 = ['cheddar', 'stilton', 'gruyere']
523
528
        text1 = ['cheddar', 'blue vein', 'neufchatel', 'chevre']
524
 
        
 
529
 
525
530
        k.add_lines('text0', [], text0)
526
531
        k.add_lines('text1', ['text0'], text1)
527
532
 
533
538
 
534
539
class Merge(TestBase):
535
540
    """Storage of versions that merge diverged parents"""
 
541
 
536
542
    def runTest(self):
537
543
        k = Weave()
538
544
 
609
615
            A Jug of Wine, a Loaf of Bread, -- and Thou
610
616
            Beside me singing in the Wilderness --
611
617
            Oh, Wilderness were Paradise enow!""",
612
 
            
 
618
 
613
619
            """A Book of Verses underneath the Bough,
614
620
            A Jug of Wine, a Loaf of Bread, -- and Thou
615
621
            Beside me singing in the Wilderness --
649
655
 
650
656
 
651
657
class JoinWeavesTests(TestBase):
 
658
 
652
659
    def setUp(self):
653
660
        super(JoinWeavesTests, self).setUp()
654
661
        self.weave1 = Weave()
724
731
 
725
732
class InstrumentedWeave(Weave):
726
733
    """Keep track of how many times functions are called."""
727
 
    
 
734
 
728
735
    def __init__(self, weave_name=None):
729
736
        self._extract_count = 0
730
737
        Weave.__init__(self, weave_name=weave_name)
753
760
 
754
761
 
755
762
class TestWeaveFile(TestCaseInTempDir):
756
 
    
 
763
 
757
764
    def test_empty_file(self):
758
765
        f = open('empty.weave', 'wb+')
759
766
        try: