/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/selftest/testtestament.py

  • Committer: Robert Collins
  • Date: 2005-10-16 00:22:17 UTC
  • mto: This revision was merged to the branch mainline in revision 1457.
  • Revision ID: robertc@lifelesslap.robertcollins.net-20051016002217-aa38f9c1eb13ee48
Plugins are now loaded under bzrlib.plugins, not bzrlib.plugin.

Plugins are also made available for other plugins to use by making them 
accessible via import bzrlib.plugins.NAME. You should not import other
plugins during the __init__ of your plugin though, as no ordering is
guaranteed, and the plugins directory is not on the python path.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005 by Canonical Ltd
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
 
 
17
"""Test testaments for gpg signing."""
 
18
 
 
19
# TODO: Testaments with x-bits
 
20
 
 
21
import os
 
22
from sha import sha
 
23
import sys
 
24
 
 
25
from bzrlib.selftest import TestCaseInTempDir
 
26
from bzrlib.selftest.treeshape import build_tree_contents
 
27
from bzrlib.branch import Branch
 
28
from bzrlib.testament import Testament
 
29
from bzrlib.trace import mutter
 
30
from bzrlib.osutils import has_symlinks
 
31
 
 
32
class TestamentTests(TestCaseInTempDir):
 
33
    def setUp(self):
 
34
        super(TestamentTests, self).setUp()
 
35
        b = self.b = Branch.initialize('.')
 
36
        b.commit(message='initial null commit',
 
37
                 committer='test@user',
 
38
                 timestamp=1129025423, # 'Tue Oct 11 20:10:23 2005'
 
39
                 timezone=0,
 
40
                 rev_id='test@user-1')
 
41
        build_tree_contents([('hello', 'contents of hello file'),
 
42
                             ('src/', ),
 
43
                             ('src/foo.c', 'int main()\n{\n}\n')])
 
44
        b.add(['hello', 'src', 'src/foo.c'],
 
45
              ['hello-id', 'src-id', 'foo.c-id'])
 
46
        b.commit(message='add files and directories',
 
47
                 timestamp=1129025483,
 
48
                 timezone=36000,
 
49
                 rev_id='test@user-2',
 
50
                 committer='test@user')
 
51
 
 
52
    def test_null_testament(self):
 
53
        """Testament for a revision with no contents."""
 
54
        t = Testament.from_revision(self.b, 'test@user-1')
 
55
        ass = self.assertTrue
 
56
        eq = self.assertEqual
 
57
        ass(isinstance(t, Testament))
 
58
        eq(t.revision_id, 'test@user-1')
 
59
        eq(t.committer, 'test@user')
 
60
        eq(t.timestamp, 1129025423)
 
61
        eq(t.timezone, 0)
 
62
 
 
63
    def test_testment_text_form(self):
 
64
        """Conversion of testament to canonical text form."""
 
65
        t = Testament.from_revision(self.b, 'test@user-1')
 
66
        text_form = t.as_text()
 
67
        self.log('testament text form:\n' + text_form)
 
68
        self.assertEqual(text_form, REV_1_TESTAMENT)
 
69
 
 
70
    def test_testament_with_contents(self):
 
71
        """Testament containing a file and a directory."""
 
72
        t = Testament.from_revision(self.b, 'test@user-2')
 
73
        text_form = t.as_text()
 
74
        self.log('testament text form:\n' + text_form)
 
75
        self.assertEqualDiff(text_form, REV_2_TESTAMENT)
 
76
        actual_short = t.as_short_text()
 
77
        self.assertEqualDiff(actual_short, REV_2_SHORT)
 
78
 
 
79
    def test_testament_command(self):
 
80
        """Testament containing a file and a directory."""
 
81
        out, err = self.run_bzr_captured(['testament', '--long'])
 
82
        self.assertEqualDiff(err, '')
 
83
        self.assertEqualDiff(out, REV_2_TESTAMENT)
 
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
 
 
124
 
 
125
REV_2_TESTAMENT = """\
 
126
bazaar-ng testament version 1
 
127
revision-id: test@user-2
 
128
committer: test@user
 
129
timestamp: 1129025483
 
130
timezone: 36000
 
131
parents:
 
132
  test@user-1
 
133
message:
 
134
  add files and directories
 
135
inventory:
 
136
  file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
 
137
  directory src src-id
 
138
  file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
 
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
"""