~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/test_weave.py

  • Committer: Robert Collins
  • Date: 2005-09-30 02:54:51 UTC
  • mfrom: (1395)
  • mto: This revision was merged to the branch mainline in revision 1397.
  • Revision ID: robertc@robertcollins.net-20050930025451-47b9e412202be44b
symlink and weaves, whaddya know

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
28
import testsweet
28
 
from bzrlib.weave import Weave, WeaveFormatError
 
29
from bzrlib.weave import Weave, WeaveFormatError, WeaveError
29
30
from bzrlib.weavefile import write_weave, read_weave
30
 
from pprint import pformat
31
 
 
 
31
from bzrlib.selftest import TestCase
 
32
from bzrlib.osutils import sha_string
32
33
 
33
34
try:
34
35
    set
48
49
 
49
50
 
50
51
 
51
 
class TestBase(testsweet.TestBase):
 
52
class TestBase(TestCase):
52
53
    def check_read_write(self, k):
53
54
        """Check the weave k can be written & re-read."""
54
55
        from tempfile import TemporaryFile
111
112
        self.assertEqual(k.get(0), TEXT_0)
112
113
        self.assertEqual(k.get(1), TEXT_1)
113
114
 
114
 
        k.dump(self.TEST_LOG)
 
115
 
 
116
 
 
117
class AddWithGivenSha(TestBase):
 
118
    def runTest(self):
 
119
        """Add with caller-supplied SHA-1"""
 
120
        k = Weave()
 
121
 
 
122
        t = 'text0'
 
123
        k.add('text0', [], [t], sha1=sha_string(t))
115
124
 
116
125
 
117
126
 
127
136
                          ['new text!'])
128
137
 
129
138
 
 
139
class RepeatedAdd(TestBase):
 
140
    """Add the same version twice; harmless."""
 
141
    def runTest(self):
 
142
        k = Weave()
 
143
        idx = k.add('text0', [], TEXT_0)
 
144
        idx2 = k.add('text0', [], TEXT_0)
 
145
        self.assertEqual(idx, idx2)
 
146
 
 
147
 
 
148
 
 
149
class InvalidRepeatedAdd(TestBase):
 
150
    def runTest(self):
 
151
        k = Weave()
 
152
        idx = k.add('text0', [], TEXT_0)
 
153
        self.assertRaises(WeaveError,
 
154
                          k.add,
 
155
                          'text0',
 
156
                          [],
 
157
                          ['not the same text'])
 
158
        self.assertRaises(WeaveError,
 
159
                          k.add,
 
160
                          'text0',
 
161
                          [12],         # not the right parents
 
162
                          TEXT_0)
 
163
        
 
164
 
 
165
 
130
166
class InsertLines(TestBase):
131
167
    """Store a revision that adds one line to the original.
132
168
 
470
506
        self.assertEqual(k.get(0),
471
507
                         ["first line"])
472
508
 
473
 
        k.dump(self.TEST_LOG)
474
 
 
475
509
 
476
510
class DivergedIncludes(TestBase):
477
511
    """Weave with two diverged texts based on version 0.
771
805
    
772
806
 
773
807
 
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
808
if __name__ == '__main__':
787
809
    import sys
788
 
    sys.exit(testweave())
 
810
    import unittest
 
811
    sys.exit(unittest.main())
789
812