~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to testweave.py

  • Committer: Martin Pool
  • Date: 2005-06-30 07:58:00 UTC
  • mto: This revision was merged to the branch mainline in revision 852.
  • Revision ID: mbp@sourcefrog.net-20050630075800-9af4341e177e121a
Remove VerInfo class; just store sets directly in the list of  
versions.

Add tests for serialize/deserialize.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
"""test suite for weave algorithm"""
23
23
 
24
24
 
25
 
from testsweet import TestBase
26
 
from weave import Weave, VerInfo, WeaveFormatError
 
25
import testsweet
 
26
from weave import Weave, WeaveFormatError
27
27
from pprint import pformat
28
28
 
29
29
 
45
45
          "A second line"]
46
46
 
47
47
 
 
48
 
 
49
class TestBase(testsweet.TestBase):
 
50
    def check_read_write(self, k):
 
51
        """Check the weave k can be written & re-read."""
 
52
        from tempfile import TemporaryFile
 
53
        from weavefile import write_weave, read_weave
 
54
        tf = TemporaryFile()
 
55
 
 
56
        write_weave(k, tf)
 
57
        tf.seek(0)
 
58
        k2 = read_weave(tf)
 
59
 
 
60
        if k != k2:
 
61
            tf.seek(0)
 
62
            self.log('serialized weave:')
 
63
            self.log(tf.read())
 
64
            self.fail('read/write check failed')
 
65
        
 
66
        
 
67
 
 
68
 
48
69
class Easy(TestBase):
49
70
    def runTest(self):
50
71
        k = Weave()
114
135
        self.assertEquals(list(changes),
115
136
                          [(1, 1, ['top line'])])
116
137
 
 
138
        self.check_read_write(k)
117
139
 
118
140
 
119
141
class InvalidAdd(TestBase):
217
239
    def runTest(self):
218
240
        k = Weave()
219
241
 
220
 
        k._v = [VerInfo([]),
 
242
        k._v = [(),
221
243
                ]
222
244
        k._l = [('{', 0),
223
245
                'first line',
238
260
    def runTest(self):
239
261
        k = Weave()
240
262
 
241
 
        k._v = [VerInfo([]),
242
 
                VerInfo([0]),
 
263
        k._v = [(),
 
264
                frozenset([0]),
243
265
                ]
244
266
        k._l = [('{', 0),
245
267
                'first line',
268
290
    def runTest(self):
269
291
        k = Weave()
270
292
 
271
 
        k._v = [VerInfo([]),
272
 
                VerInfo([0]),
 
293
        k._v = [frozenset(),
 
294
                frozenset([0]),
273
295
                ]
274
296
        k._l = [('{', 0),
275
297
                'first line',
302
324
    def runTest(self):
303
325
        k = Weave()
304
326
 
305
 
        k._v = [VerInfo([]),
 
327
        k._v = [frozenset(),
306
328
                ]
307
329
        k._l = ['bad line',
308
330
                ('{', 0),
327
349
    def runTest(self):
328
350
        k = Weave()
329
351
 
330
 
        k._v = [VerInfo([]),
331
 
                VerInfo([0]),
332
 
                VerInfo([0]),
333
 
                VerInfo([0,1,2]),
 
352
        k._v = [frozenset(),
 
353
                frozenset([0]),
 
354
                frozenset([0]),
 
355
                frozenset([0,1,2]),
334
356
                ]
335
357
        k._l = [('{', 0),
336
358
                'foo {',
356
378
    def runTest(self):
357
379
        k = Weave()
358
380
 
359
 
        k._v = [VerInfo([]),
360
 
                VerInfo([0]),
361
 
                VerInfo([0]),
362
 
                VerInfo([0,1,2]),
 
381
        k._v = [frozenset(),
 
382
                frozenset([0]),
 
383
                frozenset([0]),
 
384
                frozenset([0,1,2]),
363
385
                ]
364
386
        k._l = [('{', 0),
365
387
                'foo {',
438
460
    def runTest(self):
439
461
        k = Weave()
440
462
 
441
 
        k._v = [VerInfo(), VerInfo(included=[0])]
 
463
        k._v = [frozenset(), frozenset([0])]
442
464
        k._l = [('{', 0),
443
465
                "first line",
444
466
                ('}', 0),
462
484
    def runTest(self):
463
485
        k = Weave()
464
486
 
465
 
        k._v = [VerInfo(),
466
 
                VerInfo(included=[0]),
467
 
                VerInfo(included=[0]),
 
487
        k._v = [frozenset(),
 
488
                frozenset([0]),
 
489
                frozenset([0]),
468
490
                ]
469
491
        k._l = [('{', 0),
470
492
                "first line",
536
558
 
537
559
        self.log('k._l=' + pformat(k._l))
538
560
 
539
 
        from weavefile import write_weave_v1
540
 
        self.log('weave:')
541
 
        write_weave_v1(k, self.TEST_LOG)
 
561
        self.check_read_write(k)
542
562
 
543
563
 
544
564
class AutoMerge(TestBase):
567
587
 
568
588
 
569
589
class Khayyam(TestBase):
 
590
    """Test changes to multi-line texts, and read/write"""
570
591
    def runTest(self):
571
592
        rawtexts = [
572
593
            """A Book of Verses underneath the Bough,
591
612
            A Jug of Wine, a Loaf of Bread,
592
613
            and Thou
593
614
            Beside me singing in the Wilderness --
594
 
            Oh, Wilderness were Paradise now!
595
 
            """,
 
615
            Oh, Wilderness were Paradise now!""",
596
616
            ]
597
617
        texts = [[l.strip() for l in t.split('\n')] for t in rawtexts]
598
618
 
605
625
        self.log("k._l=" + pformat(k._l))
606
626
 
607
627
        for i, t in enumerate(texts):
608
 
            self.assertEqual(k.get(i),
609
 
                             t)            
 
628
            self.assertEqual(k.get(i), t)
610
629
 
 
630
        self.check_read_write(k)
611
631
 
612
632
 
613
633
def testweave():