~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_testament.py

  • Committer: John Arbash Meinel
  • Date: 2005-11-30 15:43:57 UTC
  • mto: (1185.50.1 jam-integration)
  • mto: This revision was merged to the branch mainline in revision 1518.
  • Revision ID: john@arbash-meinel.com-20051130154357-614206b3a7b83cd0
Refactored bzrlib/ui.py into a module with the possibility for multiple ui forms.

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.tests import TestCaseInTempDir
26
26
from bzrlib.branch import Branch
27
27
from bzrlib.testament import Testament
28
28
from bzrlib.trace import mutter
29
29
from bzrlib.osutils import has_symlinks
30
30
 
31
31
 
32
 
class TestamentTests(TestCaseWithTransport):
 
32
class TestamentTests(TestCaseInTempDir):
33
33
 
34
34
    def setUp(self):
35
35
        super(TestamentTests, self).setUp()
36
 
        self.wt = self.make_branch_and_tree('.')
37
 
        b = self.b = self.wt.branch
 
36
        b = self.b = Branch.initialize(u'.')
38
37
        b.nick = "test branch"
39
 
        self.wt.commit(message='initial null commit',
 
38
        b.working_tree().commit(message='initial null commit',
40
39
                 committer='test@user',
41
40
                 timestamp=1129025423, # 'Tue Oct 11 20:10:23 2005'
42
41
                 timezone=0,
44
43
        self.build_tree_contents([('hello', 'contents of hello file'),
45
44
                             ('src/', ),
46
45
                             ('src/foo.c', 'int main()\n{\n}\n')])
47
 
        self.wt.add(['hello', 'src', 'src/foo.c'],
 
46
        b.working_tree().add(['hello', 'src', 'src/foo.c'],
48
47
                             ['hello-id', 'src-id', 'foo.c-id'])
49
 
        self.wt.commit(message='add files and directories',
 
48
        b.working_tree().commit(message='add files and directories',
50
49
                 timestamp=1129025483,
51
50
                 timezone=36000,
52
51
                 rev_id='test@user-2',
54
53
 
55
54
    def test_null_testament(self):
56
55
        """Testament for a revision with no contents."""
57
 
        t = Testament.from_revision(self.b.repository, 'test@user-1')
 
56
        t = Testament.from_revision(self.b, 'test@user-1')
58
57
        ass = self.assertTrue
59
58
        eq = self.assertEqual
60
59
        ass(isinstance(t, Testament))
65
64
 
66
65
    def test_testment_text_form(self):
67
66
        """Conversion of testament to canonical text form."""
68
 
        t = Testament.from_revision(self.b.repository, 'test@user-1')
 
67
        t = Testament.from_revision(self.b, 'test@user-1')
69
68
        text_form = t.as_text()
70
69
        self.log('testament text form:\n' + text_form)
71
70
        self.assertEqual(text_form, REV_1_TESTAMENT)
72
71
 
73
72
    def test_testament_with_contents(self):
74
73
        """Testament containing a file and a directory."""
75
 
        t = Testament.from_revision(self.b.repository, 'test@user-2')
 
74
        t = Testament.from_revision(self.b, 'test@user-2')
76
75
        text_form = t.as_text()
77
76
        self.log('testament text form:\n' + text_form)
78
77
        self.assertEqualDiff(text_form, REV_2_TESTAMENT)
96
95
        if not has_symlinks():
97
96
            return
98
97
        os.symlink('wibble/linktarget', 'link')
99
 
        self.wt.add(['link'], ['link-id'])
100
 
        self.wt.commit(message='add symlink',
 
98
        self.b.working_tree().add(['link'], ['link-id'])
 
99
        self.b.working_tree().commit(message='add symlink',
101
100
                 timestamp=1129025493,
102
101
                 timezone=36000,
103
102
                 rev_id='test@user-3',
104
103
                 committer='test@user')
105
 
        t = Testament.from_revision(self.b.repository, 'test@user-3')
 
104
        t = Testament.from_revision(self.b, 'test@user-3')
106
105
        self.assertEqualDiff(t.as_text(), REV_3_TESTAMENT)
107
106
 
108
107
    def test_testament_revprops(self):
109
108
        """Testament to revision with extra properties"""
110
109
        props = dict(flavor='sour cherry\ncream cheese',
111
110
                     size='medium')
112
 
        self.wt.commit(message='revision with properties',
 
111
        self.b.working_tree().commit(message='revision with properties',
113
112
                      timestamp=1129025493,
114
113
                      timezone=36000,
115
114
                      rev_id='test@user-3',
116
115
                      committer='test@user',
117
116
                      revprops=props)
118
 
        t = Testament.from_revision(self.b.repository, 'test@user-3')
 
117
        t = Testament.from_revision(self.b, 'test@user-3')
119
118
        self.assertEqualDiff(t.as_text(), REV_PROPS_TESTAMENT)
120
119
 
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
120
    def test___init__(self):
133
 
        revision = self.b.repository.get_revision('test@user-2')
134
 
        inventory = self.b.repository.get_inventory('test@user-2')
 
121
        revision = self.b.get_revision('test@user-2')
 
122
        inventory = self.b.get_inventory('test@user-2')
135
123
        testament_1 = Testament(revision, inventory).as_short_text()
136
 
        testament_2 = Testament.from_revision(self.b.repository, 
 
124
        testament_2 = Testament.from_revision(self.b, 
137
125
                                              'test@user-2').as_short_text()
138
126
        self.assertEqual(testament_1, testament_2)
139
127
                    
231
219
  branch-nick:
232
220
    test branch
233
221
"""
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
 
"""