~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/testtestament.py

- refactor handling of short option names

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.tests import TestCaseWithTransport
 
25
from bzrlib.selftest import TestCaseInTempDir
 
26
from bzrlib.selftest.treeshape import build_tree_contents
26
27
from bzrlib.branch import Branch
27
28
from bzrlib.testament import Testament
28
29
from bzrlib.trace import mutter
29
30
from bzrlib.osutils import has_symlinks
30
31
 
31
 
 
32
 
class TestamentTests(TestCaseWithTransport):
33
 
 
 
32
class TestamentTests(TestCaseInTempDir):
34
33
    def setUp(self):
35
34
        super(TestamentTests, self).setUp()
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',
 
35
        b = self.b = Branch.initialize('.')
 
36
        b.commit(message='initial null commit',
40
37
                 committer='test@user',
41
38
                 timestamp=1129025423, # 'Tue Oct 11 20:10:23 2005'
42
39
                 timezone=0,
43
40
                 rev_id='test@user-1')
44
 
        self.build_tree_contents([('hello', 'contents of hello file'),
 
41
        build_tree_contents([('hello', 'contents of hello file'),
45
42
                             ('src/', ),
46
43
                             ('src/foo.c', 'int main()\n{\n}\n')])
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',
 
44
        b.add(['hello', 'src', 'src/foo.c'],
 
45
              ['hello-id', 'src-id', 'foo.c-id'])
 
46
        b.commit(message='add files and directories',
50
47
                 timestamp=1129025483,
51
48
                 timezone=36000,
52
49
                 rev_id='test@user-2',
54
51
 
55
52
    def test_null_testament(self):
56
53
        """Testament for a revision with no contents."""
57
 
        t = Testament.from_revision(self.b.repository, 'test@user-1')
 
54
        t = Testament.from_revision(self.b, 'test@user-1')
58
55
        ass = self.assertTrue
59
56
        eq = self.assertEqual
60
57
        ass(isinstance(t, Testament))
65
62
 
66
63
    def test_testment_text_form(self):
67
64
        """Conversion of testament to canonical text form."""
68
 
        t = Testament.from_revision(self.b.repository, 'test@user-1')
 
65
        t = Testament.from_revision(self.b, 'test@user-1')
69
66
        text_form = t.as_text()
70
67
        self.log('testament text form:\n' + text_form)
71
68
        self.assertEqual(text_form, REV_1_TESTAMENT)
72
69
 
73
70
    def test_testament_with_contents(self):
74
71
        """Testament containing a file and a directory."""
75
 
        t = Testament.from_revision(self.b.repository, 'test@user-2')
 
72
        t = Testament.from_revision(self.b, 'test@user-2')
76
73
        text_form = t.as_text()
77
74
        self.log('testament text form:\n' + text_form)
78
75
        self.assertEqualDiff(text_form, REV_2_TESTAMENT)
96
93
        if not has_symlinks():
97
94
            return
98
95
        os.symlink('wibble/linktarget', 'link')
99
 
        self.wt.add(['link'], ['link-id'])
100
 
        self.wt.commit(message='add symlink',
 
96
        self.b.add(['link'], ['link-id'])
 
97
        self.b.commit(message='add symlink',
101
98
                 timestamp=1129025493,
102
99
                 timezone=36000,
103
100
                 rev_id='test@user-3',
104
101
                 committer='test@user')
105
 
        t = Testament.from_revision(self.b.repository, 'test@user-3')
 
102
        t = Testament.from_revision(self.b, 'test@user-3')
106
103
        self.assertEqualDiff(t.as_text(), REV_3_TESTAMENT)
107
104
 
108
 
    def test_testament_revprops(self):
109
 
        """Testament to revision with extra properties"""
110
 
        props = dict(flavor='sour cherry\ncream cheese',
111
 
                     size='medium')
112
 
        self.wt.commit(message='revision with properties',
113
 
                      timestamp=1129025493,
114
 
                      timezone=36000,
115
 
                      rev_id='test@user-3',
116
 
                      committer='test@user',
117
 
                      revprops=props)
118
 
        t = Testament.from_revision(self.b.repository, 'test@user-3')
119
 
        self.assertEqualDiff(t.as_text(), REV_PROPS_TESTAMENT)
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
 
 
132
 
    def test___init__(self):
133
 
        revision = self.b.repository.get_revision('test@user-2')
134
 
        inventory = self.b.repository.get_inventory('test@user-2')
135
 
        testament_1 = Testament(revision, inventory).as_short_text()
136
 
        testament_2 = Testament.from_revision(self.b.repository, 
137
 
                                              'test@user-2').as_short_text()
138
 
        self.assertEqual(testament_1, testament_2)
139
 
                    
140
105
 
141
106
REV_1_TESTAMENT = """\
142
107
bazaar-ng testament version 1
148
113
message:
149
114
  initial null commit
150
115
inventory:
151
 
properties:
152
 
  branch-nick:
153
 
    test branch
154
116
"""
155
117
 
156
118
REV_1_SHORT = """\
174
136
  file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
175
137
  directory src src-id
176
138
  file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
177
 
properties:
178
 
  branch-nick:
179
 
    test branch
180
139
"""
181
140
 
182
141
 
187
146
""" % sha(REV_2_TESTAMENT).hexdigest()
188
147
 
189
148
 
190
 
REV_PROPS_TESTAMENT = """\
191
 
bazaar-ng testament version 1
192
 
revision-id: test@user-3
193
 
committer: test@user
194
 
timestamp: 1129025493
195
 
timezone: 36000
196
 
parents:
197
 
  test@user-2
198
 
message:
199
 
  revision with properties
200
 
inventory:
201
 
  file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
202
 
  directory src src-id
203
 
  file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
204
 
properties:
205
 
  branch-nick:
206
 
    test branch
207
 
  flavor:
208
 
    sour cherry
209
 
    cream cheese
210
 
  size:
211
 
    medium
212
 
"""
213
 
 
214
 
 
215
149
REV_3_TESTAMENT = """\
216
150
bazaar-ng testament version 1
217
151
revision-id: test@user-3
227
161
  symlink link link-id wibble/linktarget
228
162
  directory src src-id
229
163
  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
253
164
"""