~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/testtestament.py

Tags: bzr-0.1
- testament symlink support

- more testament tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Test testaments for gpg signing."""
18
18
 
19
 
# TODO: Testaments with symlinks, x-bits
 
19
# TODO: Testaments with x-bits
20
20
 
21
21
import os
22
22
from sha import sha
27
27
from bzrlib.branch import Branch
28
28
from bzrlib.testament import Testament
29
29
from bzrlib.trace import mutter
 
30
from bzrlib.osutils import has_symlinks
30
31
 
31
32
class TestamentTests(TestCaseInTempDir):
32
33
    def setUp(self):
64
65
        t = Testament.from_revision(self.b, 'test@user-1')
65
66
        text_form = t.as_text()
66
67
        self.log('testament text form:\n' + text_form)
67
 
        expect = """\
68
 
bazaar-ng testament version 1
69
 
revision-id: test@user-1
70
 
committer: test@user
71
 
timestamp: 1129025423
72
 
timezone: 0
73
 
parents:
74
 
message:
75
 
  initial null commit
76
 
inventory:
77
 
"""
78
 
        self.assertEqual(text_form, expect)
 
68
        self.assertEqual(text_form, REV_1_TESTAMENT)
79
69
 
80
70
    def test_testament_with_contents(self):
81
71
        """Testament containing a file and a directory."""
84
74
        self.log('testament text form:\n' + text_form)
85
75
        self.assertEqualDiff(text_form, REV_2_TESTAMENT)
86
76
        actual_short = t.as_short_text()
87
 
        self.assertEqualDiff(actual_short, """\
88
 
bazaar-ng testament short form 1
89
 
revision test@user-2
90
 
sha1 %s
91
 
""" % sha(REV_2_TESTAMENT).hexdigest())
 
77
        self.assertEqualDiff(actual_short, REV_2_SHORT)
92
78
 
93
79
    def test_testament_command(self):
94
80
        """Testament containing a file and a directory."""
96
82
        self.assertEqualDiff(err, '')
97
83
        self.assertEqualDiff(out, REV_2_TESTAMENT)
98
84
 
 
85
    def test_testament_command_2(self):
 
86
        """Command getting short testament of previous version."""
 
87
        out, err = self.run_bzr_captured(['testament', '-r1'])
 
88
        self.assertEqualDiff(err, '')
 
89
        self.assertEqualDiff(out, REV_1_SHORT)
 
90
 
 
91
    def test_testament_symlinks(self):
 
92
        """Testament containing symlink (where possible)"""
 
93
        if not has_symlinks():
 
94
            return
 
95
        os.symlink('wibble/linktarget', 'link')
 
96
        self.b.add(['link'], ['link-id'])
 
97
        self.b.commit(message='add symlink',
 
98
                 timestamp=1129025493,
 
99
                 timezone=36000,
 
100
                 rev_id='test@user-3',
 
101
                 committer='test@user')
 
102
        t = Testament.from_revision(self.b, 'test@user-3')
 
103
        self.assertEqualDiff(t.as_text(), REV_3_TESTAMENT)
 
104
 
 
105
 
 
106
REV_1_TESTAMENT = """\
 
107
bazaar-ng testament version 1
 
108
revision-id: test@user-1
 
109
committer: test@user
 
110
timestamp: 1129025423
 
111
timezone: 0
 
112
parents:
 
113
message:
 
114
  initial null commit
 
115
inventory:
 
116
"""
 
117
 
 
118
REV_1_SHORT = """\
 
119
bazaar-ng testament short form 1
 
120
revision-id: test@user-1
 
121
sha1: %s
 
122
""" % sha(REV_1_TESTAMENT).hexdigest()
 
123
 
99
124
 
100
125
REV_2_TESTAMENT = """\
101
126
bazaar-ng testament version 1
112
137
  directory src src-id
113
138
  file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
114
139
"""
 
140
 
 
141
 
 
142
REV_2_SHORT = """\
 
143
bazaar-ng testament short form 1
 
144
revision-id: test@user-2
 
145
sha1: %s
 
146
""" % sha(REV_2_TESTAMENT).hexdigest()
 
147
 
 
148
 
 
149
REV_3_TESTAMENT = """\
 
150
bazaar-ng testament version 1
 
151
revision-id: test@user-3
 
152
committer: test@user
 
153
timestamp: 1129025493
 
154
timezone: 36000
 
155
parents:
 
156
  test@user-2
 
157
message:
 
158
  add symlink
 
159
inventory:
 
160
  file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
 
161
  symlink link link-id wibble/linktarget
 
162
  directory src src-id
 
163
  file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
 
164
"""