~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/test_weave.py

  • Committer: Martin Pool
  • Date: 2005-09-30 00:58:02 UTC
  • mto: (1185.14.2)
  • mto: This revision was merged to the branch mainline in revision 1396.
  • Revision ID: mbp@sourcefrog.net-20050930005802-721cfc318e393817
- copy_branch creates destination if it doesn't exist

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 
24
24
"""test suite for weave algorithm"""
25
25
 
 
26
from pprint import pformat
26
27
 
27
 
import testsweet
28
 
from bzrlib.weave import Weave, WeaveFormatError
 
28
from bzrlib.weave import Weave, WeaveFormatError, WeaveError
29
29
from bzrlib.weavefile import write_weave, read_weave
30
 
from pprint import pformat
31
 
 
32
 
 
33
 
try:
34
 
    set
35
 
    frozenset
36
 
except NameError:
37
 
    from sets import Set, ImmutableSet
38
 
    set = Set
39
 
    frozenset = ImmutableSet
40
 
    del Set, ImmutableSet
41
 
 
 
30
from bzrlib.selftest import TestCase
 
31
from bzrlib.osutils import sha_string
42
32
 
43
33
 
44
34
# texts for use in testing
48
38
 
49
39
 
50
40
 
51
 
class TestBase(testsweet.TestBase):
 
41
class TestBase(TestCase):
52
42
    def check_read_write(self, k):
53
43
        """Check the weave k can be written & re-read."""
54
44
        from tempfile import TemporaryFile
111
101
        self.assertEqual(k.get(0), TEXT_0)
112
102
        self.assertEqual(k.get(1), TEXT_1)
113
103
 
114
 
        k.dump(self.TEST_LOG)
 
104
 
 
105
 
 
106
class AddWithGivenSha(TestBase):
 
107
    def runTest(self):
 
108
        """Add with caller-supplied SHA-1"""
 
109
        k = Weave()
 
110
 
 
111
        t = 'text0'
 
112
        k.add('text0', [], [t], sha1=sha_string(t))
115
113
 
116
114
 
117
115
 
127
125
                          ['new text!'])
128
126
 
129
127
 
 
128
class RepeatedAdd(TestBase):
 
129
    """Add the same version twice; harmless."""
 
130
    def runTest(self):
 
131
        k = Weave()
 
132
        idx = k.add('text0', [], TEXT_0)
 
133
        idx2 = k.add('text0', [], TEXT_0)
 
134
        self.assertEqual(idx, idx2)
 
135
 
 
136
 
 
137
 
 
138
class InvalidRepeatedAdd(TestBase):
 
139
    def runTest(self):
 
140
        k = Weave()
 
141
        idx = k.add('text0', [], TEXT_0)
 
142
        self.assertRaises(WeaveError,
 
143
                          k.add,
 
144
                          'text0',
 
145
                          [],
 
146
                          ['not the same text'])
 
147
        self.assertRaises(WeaveError,
 
148
                          k.add,
 
149
                          'text0',
 
150
                          [12],         # not the right parents
 
151
                          TEXT_0)
 
152
        
 
153
 
 
154
 
130
155
class InsertLines(TestBase):
131
156
    """Store a revision that adds one line to the original.
132
157
 
470
495
        self.assertEqual(k.get(0),
471
496
                         ["first line"])
472
497
 
473
 
        k.dump(self.TEST_LOG)
474
 
 
475
498
 
476
499
class DivergedIncludes(TestBase):
477
500
    """Weave with two diverged texts based on version 0.
771
794
    
772
795
 
773
796
 
774
 
def testweave():
775
 
    import testsweet
776
 
    from unittest import TestSuite, TestLoader
777
 
    import testweave
778
 
 
779
 
    tl = TestLoader()
780
 
    suite = TestSuite()
781
 
    suite.addTest(tl.loadTestsFromModule(testweave))
782
 
    
783
 
    return int(not testsweet.run_suite(suite)) # for shell 0=true
784
 
 
785
 
 
786
797
if __name__ == '__main__':
787
798
    import sys
788
 
    sys.exit(testweave())
 
799
    import unittest
 
800
    sys.exit(unittest.main())
789
801