~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/test_weave.py

  • Committer: Aaron Bentley
  • Date: 2005-09-29 21:07:17 UTC
  • mfrom: (1393.1.6)
  • mto: (1185.25.1)
  • mto: This revision was merged to the branch mainline in revision 1419.
  • Revision ID: abentley@panoramicfeedback.com-20050929210717-cd73981590f17017
Merged the weave changes

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