~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_testament.py

Late bind to PatienceSequenceMatcher to allow plugin to override.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
from sha import sha
23
23
import sys
24
24
 
25
 
from bzrlib.selftest import TestCaseInTempDir
26
 
from bzrlib.selftest.treeshape import build_tree_contents
 
25
from bzrlib.tests import TestCaseWithTransport
27
26
from bzrlib.branch import Branch
28
27
from bzrlib.testament import Testament
29
28
from bzrlib.trace import mutter
30
29
from bzrlib.osutils import has_symlinks
31
30
 
32
31
 
33
 
class TestamentTests(TestCaseInTempDir):
 
32
class TestamentTests(TestCaseWithTransport):
34
33
 
35
34
    def setUp(self):
36
35
        super(TestamentTests, self).setUp()
37
 
        b = self.b = Branch.initialize('.')
38
 
        b.commit(message='initial null commit',
 
36
        self.wt = self.make_branch_and_tree('.')
 
37
        b = self.b = self.wt.branch
 
38
        b.nick = "test branch"
 
39
        self.wt.commit(message='initial null commit',
39
40
                 committer='test@user',
40
41
                 timestamp=1129025423, # 'Tue Oct 11 20:10:23 2005'
41
42
                 timezone=0,
42
43
                 rev_id='test@user-1')
43
 
        build_tree_contents([('hello', 'contents of hello file'),
 
44
        self.build_tree_contents([('hello', 'contents of hello file'),
44
45
                             ('src/', ),
45
46
                             ('src/foo.c', 'int main()\n{\n}\n')])
46
 
        b.add(['hello', 'src', 'src/foo.c'],
47
 
              ['hello-id', 'src-id', 'foo.c-id'])
48
 
        b.commit(message='add files and directories',
 
47
        self.wt.add(['hello', 'src', 'src/foo.c'],
 
48
                             ['hello-id', 'src-id', 'foo.c-id'])
 
49
        self.wt.commit(message='add files and directories',
49
50
                 timestamp=1129025483,
50
51
                 timezone=36000,
51
52
                 rev_id='test@user-2',
53
54
 
54
55
    def test_null_testament(self):
55
56
        """Testament for a revision with no contents."""
56
 
        t = Testament.from_revision(self.b, 'test@user-1')
 
57
        t = Testament.from_revision(self.b.repository, 'test@user-1')
57
58
        ass = self.assertTrue
58
59
        eq = self.assertEqual
59
60
        ass(isinstance(t, Testament))
64
65
 
65
66
    def test_testment_text_form(self):
66
67
        """Conversion of testament to canonical text form."""
67
 
        t = Testament.from_revision(self.b, 'test@user-1')
 
68
        t = Testament.from_revision(self.b.repository, 'test@user-1')
68
69
        text_form = t.as_text()
69
70
        self.log('testament text form:\n' + text_form)
70
71
        self.assertEqual(text_form, REV_1_TESTAMENT)
71
72
 
72
73
    def test_testament_with_contents(self):
73
74
        """Testament containing a file and a directory."""
74
 
        t = Testament.from_revision(self.b, 'test@user-2')
 
75
        t = Testament.from_revision(self.b.repository, 'test@user-2')
75
76
        text_form = t.as_text()
76
77
        self.log('testament text form:\n' + text_form)
77
78
        self.assertEqualDiff(text_form, REV_2_TESTAMENT)
95
96
        if not has_symlinks():
96
97
            return
97
98
        os.symlink('wibble/linktarget', 'link')
98
 
        self.b.add(['link'], ['link-id'])
99
 
        self.b.commit(message='add symlink',
 
99
        self.wt.add(['link'], ['link-id'])
 
100
        self.wt.commit(message='add symlink',
100
101
                 timestamp=1129025493,
101
102
                 timezone=36000,
102
103
                 rev_id='test@user-3',
103
104
                 committer='test@user')
104
 
        t = Testament.from_revision(self.b, 'test@user-3')
 
105
        t = Testament.from_revision(self.b.repository, 'test@user-3')
105
106
        self.assertEqualDiff(t.as_text(), REV_3_TESTAMENT)
106
107
 
107
108
    def test_testament_revprops(self):
108
109
        """Testament to revision with extra properties"""
109
110
        props = dict(flavor='sour cherry\ncream cheese',
110
111
                     size='medium')
111
 
        self.b.commit(message='revision with properties',
 
112
        self.wt.commit(message='revision with properties',
112
113
                      timestamp=1129025493,
113
114
                      timezone=36000,
114
115
                      rev_id='test@user-3',
115
116
                      committer='test@user',
116
117
                      revprops=props)
117
 
        t = Testament.from_revision(self.b, 'test@user-3')
 
118
        t = Testament.from_revision(self.b.repository, 'test@user-3')
118
119
        self.assertEqualDiff(t.as_text(), REV_PROPS_TESTAMENT)
119
120
 
 
121
    def test_testament_unicode_commit_message(self):
 
122
        self.wt.commit(
 
123
            message=u'non-ascii commit \N{COPYRIGHT SIGN} me',
 
124
            timestamp=1129025493,
 
125
            timezone=36000,
 
126
            rev_id='test@user-3',
 
127
            committer='test@user')
 
128
        t = Testament.from_revision(self.b.repository, 'test@user-3')
 
129
        self.assertEqualDiff(
 
130
            SAMPLE_UNICODE_TESTAMENT.encode('utf-8'), t.as_text())
 
131
 
120
132
    def test___init__(self):
121
 
        revision = self.b.get_revision('test@user-2')
122
 
        inventory = self.b.get_inventory('test@user-2')
 
133
        revision = self.b.repository.get_revision('test@user-2')
 
134
        inventory = self.b.repository.get_inventory('test@user-2')
123
135
        testament_1 = Testament(revision, inventory).as_short_text()
124
 
        testament_2 = Testament.from_revision(self.b, 
 
136
        testament_2 = Testament.from_revision(self.b.repository, 
125
137
                                              'test@user-2').as_short_text()
126
138
        self.assertEqual(testament_1, testament_2)
127
139
                    
136
148
message:
137
149
  initial null commit
138
150
inventory:
 
151
properties:
 
152
  branch-nick:
 
153
    test branch
139
154
"""
140
155
 
141
156
REV_1_SHORT = """\
159
174
  file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
160
175
  directory src src-id
161
176
  file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
 
177
properties:
 
178
  branch-nick:
 
179
    test branch
162
180
"""
163
181
 
164
182
 
184
202
  directory src src-id
185
203
  file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
186
204
properties:
 
205
  branch-nick:
 
206
    test branch
187
207
  flavor:
188
208
    sour cherry
189
209
    cream cheese
207
227
  symlink link link-id wibble/linktarget
208
228
  directory src src-id
209
229
  file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
 
230
properties:
 
231
  branch-nick:
 
232
    test branch
 
233
"""
 
234
 
 
235
 
 
236
SAMPLE_UNICODE_TESTAMENT = u"""\
 
237
bazaar-ng testament version 1
 
238
revision-id: test@user-3
 
239
committer: test@user
 
240
timestamp: 1129025493
 
241
timezone: 36000
 
242
parents:
 
243
  test@user-2
 
244
message:
 
245
  non-ascii commit \N{COPYRIGHT SIGN} me
 
246
inventory:
 
247
  file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
 
248
  directory src src-id
 
249
  file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
 
250
properties:
 
251
  branch-nick:
 
252
    test branch
210
253
"""