~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-16 07:38:10 UTC
  • Revision ID: mbp@sourcefrog.net-20050916073810-1f358be198c9ed91
- fix bug in committing files that are renamed but not modified

- add test for this

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 
26
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 bzrlib.selftest import TestCase
30
31
from pprint import pformat
31
32
 
32
33
 
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
115
 
117
116
 
118
117
class InvalidAdd(TestBase):
127
126
                          ['new text!'])
128
127
 
129
128
 
 
129
class RepeatedAdd(TestBase):
 
130
    """Add the same version twice; harmless."""
 
131
    def runTest(self):
 
132
        k = Weave()
 
133
        idx = k.add('text0', [], TEXT_0)
 
134
        idx2 = k.add('text0', [], TEXT_0)
 
135
        self.assertEqual(idx, idx2)
 
136
 
 
137
 
 
138
 
 
139
class InvalidRepeatedAdd(TestBase):
 
140
    def runTest(self):
 
141
        k = Weave()
 
142
        idx = k.add('text0', [], TEXT_0)
 
143
        self.assertRaises(WeaveError,
 
144
                          k.add,
 
145
                          'text0',
 
146
                          [],
 
147
                          ['not the same text'])
 
148
        self.assertRaises(WeaveError,
 
149
                          k.add,
 
150
                          'text0',
 
151
                          [12],         # not the right parents
 
152
                          TEXT_0)
 
153
        
 
154
 
 
155
 
130
156
class InsertLines(TestBase):
131
157
    """Store a revision that adds one line to the original.
132
158
 
470
496
        self.assertEqual(k.get(0),
471
497
                         ["first line"])
472
498
 
473
 
        k.dump(self.TEST_LOG)
474
 
 
475
499
 
476
500
class DivergedIncludes(TestBase):
477
501
    """Weave with two diverged texts based on version 0.
771
795
    
772
796
 
773
797
 
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
798
if __name__ == '__main__':
787
799
    import sys
788
 
    sys.exit(testweave())
 
800
    import unittest
 
801
    sys.exit(unittest.main())
789
802