/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 tests/test_commands.py

  • Committer: Ian Clatworthy
  • Date: 2009-02-16 14:50:34 UTC
  • mto: (0.64.116 trunk)
  • mto: This revision was merged to the branch mainline in revision 6631.
  • Revision ID: ian.clatworthy@canonical.com-20090216145034-yw1htkfblxp1uh67
code & tests for formatting Commands as file-import stream strings

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2009 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 how Commands are displayed"""
 
18
 
 
19
from bzrlib import tests
 
20
 
 
21
from bzrlib.plugins.fastimport import (
 
22
    commands,
 
23
    )
 
24
 
 
25
 
 
26
class TestBlobDisplay(tests.TestCase):
 
27
 
 
28
    def test_blob(self):
 
29
        c = commands.BlobCommand("1", "hello world")
 
30
        self.assertEqual("blob\nmark :1\ndata 11\nhello world", repr(c))
 
31
 
 
32
    def test_blob_no_mark(self):
 
33
        c = commands.BlobCommand(None, "hello world")
 
34
        self.assertEqual("blob\ndata 11\nhello world", repr(c))
 
35
 
 
36
 
 
37
class TestCheckpointDisplay(tests.TestCase):
 
38
 
 
39
    def test_checkpoint(self):
 
40
        c = commands.CheckpointCommand()
 
41
        self.assertEqual("checkpoint", repr(c))
 
42
 
 
43
 
 
44
class TestCommitDisplay(tests.TestCase):
 
45
 
 
46
    def test_commit(self):
 
47
        # user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
 
48
        committer = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600)
 
49
        c = commands.CommitCommand("refs/heads/master", "bbb", None, committer,
 
50
            "release v1.0", "aaa", None, None)
 
51
        self.assertEqualDiff(
 
52
            "commit refs/heads/master\n"
 
53
            "mark :bbb\n"
 
54
            "committer Joe Wong <joe@example.com> 1234567890 -0600\n"
 
55
            "data 12\n"
 
56
            "release v1.0\n"
 
57
            "from :aaa",
 
58
            repr(c))
 
59
 
 
60
    def test_commit_no_mark(self):
 
61
        # user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
 
62
        committer = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600)
 
63
        c = commands.CommitCommand("refs/heads/master", None, None, committer,
 
64
            "release v1.0", "aaa", None, None)
 
65
        self.assertEqualDiff(
 
66
            "commit refs/heads/master\n"
 
67
            "committer Joe Wong <joe@example.com> 1234567890 -0600\n"
 
68
            "data 12\n"
 
69
            "release v1.0\n"
 
70
            "from :aaa",
 
71
            repr(c))
 
72
 
 
73
    def test_commit_no_from(self):
 
74
        # user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
 
75
        committer = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600)
 
76
        c = commands.CommitCommand("refs/heads/master", "bbb", None, committer,
 
77
            "release v1.0", None, None, None)
 
78
        self.assertEqualDiff(
 
79
            "commit refs/heads/master\n"
 
80
            "mark :bbb\n"
 
81
            "committer Joe Wong <joe@example.com> 1234567890 -0600\n"
 
82
            "data 12\n"
 
83
            "release v1.0",
 
84
            repr(c))
 
85
 
 
86
    def test_commit_with_author(self):
 
87
        # user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
 
88
        author = ('Sue Wong', 'sue@example.com', 1234565432, -6 * 3600)
 
89
        committer = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600)
 
90
        c = commands.CommitCommand("refs/heads/master", "bbb", author,
 
91
            committer, "release v1.0", "aaa", None, None)
 
92
        self.assertEqualDiff(
 
93
            "commit refs/heads/master\n"
 
94
            "mark :bbb\n"
 
95
            "author Sue Wong <sue@example.com> 1234565432 -0600\n"
 
96
            "committer Joe Wong <joe@example.com> 1234567890 -0600\n"
 
97
            "data 12\n"
 
98
            "release v1.0\n"
 
99
            "from :aaa",
 
100
            repr(c))
 
101
 
 
102
    def test_commit_with_merges(self):
 
103
        # user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
 
104
        committer = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600)
 
105
        c = commands.CommitCommand("refs/heads/master", "ddd", None, committer,
 
106
            "release v1.0", "aaa", ['bbb', 'ccc'], None)
 
107
        self.assertEqualDiff(
 
108
            "commit refs/heads/master\n"
 
109
            "mark :ddd\n"
 
110
            "committer Joe Wong <joe@example.com> 1234567890 -0600\n"
 
111
            "data 12\n"
 
112
            "release v1.0\n"
 
113
            "from :aaa\n"
 
114
            "merge :bbb\n"
 
115
            "merge :ccc",
 
116
            repr(c))
 
117
 
 
118
    def test_commit_with_filecommands(self):
 
119
        file_cmds = [
 
120
            commands.FileDeleteCommand('readme.txt'),
 
121
            commands.FileModifyCommand('NEWS', 'file', False, None,
 
122
                'blah blah blah'),
 
123
            ]
 
124
        # user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
 
125
        committer = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600)
 
126
        c = commands.CommitCommand("refs/heads/master", "bbb", None, committer,
 
127
            "release v1.0", "aaa", None, file_cmds)
 
128
        self.assertEqualDiff(
 
129
            "commit refs/heads/master\n"
 
130
            "mark :bbb\n"
 
131
            "committer Joe Wong <joe@example.com> 1234567890 -0600\n"
 
132
            "data 12\n"
 
133
            "release v1.0\n"
 
134
            "from :aaa\n"
 
135
            "D readme.txt\n"
 
136
            "M 644 inline NEWS\n"
 
137
            "data 14\n"
 
138
            "blah blah blah",
 
139
            repr(c))
 
140
 
 
141
 
 
142
class TestProgressDisplay(tests.TestCase):
 
143
 
 
144
    def test_progress(self):
 
145
        c = commands.ProgressCommand("doing foo")
 
146
        self.assertEqual("progress doing foo", repr(c))
 
147
 
 
148
 
 
149
class TestResetDisplay(tests.TestCase):
 
150
 
 
151
    def test_reset(self):
 
152
        c = commands.ResetCommand("refs/tags/v1.0", "xxx")
 
153
        self.assertEqual("reset refs/tags/v1.0\nfrom :xxx", repr(c))
 
154
 
 
155
    def test_reset_no_from(self):
 
156
        c = commands.ResetCommand("refs/remotes/origin/master", None)
 
157
        self.assertEqual("reset refs/remotes/origin/master", repr(c))
 
158
 
 
159
 
 
160
class TestTagDisplay(tests.TestCase):
 
161
 
 
162
    def test_tag(self):
 
163
        # tagger tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
 
164
        tagger = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600)
 
165
        c = commands.TagCommand("refs/tags/v1.0", "xxx", tagger, "create v1.0")
 
166
        self.assertEqual(
 
167
            "tag refs/tags/v1.0\n"
 
168
            "from :xxx\n"
 
169
            "tagger Joe Wong <joe@example.com> 1234567890 -0600\n"
 
170
            "data 11\n"
 
171
            "create v1.0",
 
172
            repr(c))
 
173
 
 
174
    def test_tag_no_from(self):
 
175
        tagger = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600)
 
176
        c = commands.TagCommand("refs/tags/v1.0", None, tagger, "create v1.0")
 
177
        self.assertEqualDiff(
 
178
            "tag refs/tags/v1.0\n"
 
179
            "tagger Joe Wong <joe@example.com> 1234567890 -0600\n"
 
180
            "data 11\n"
 
181
            "create v1.0",
 
182
            repr(c))
 
183
 
 
184
 
 
185
class TestFileModifyDisplay(tests.TestCase):
 
186
 
 
187
    def test_filemodify_file(self):
 
188
        c = commands.FileModifyCommand("foo/bar", "file", False, "23", None)
 
189
        self.assertEqual("M 644 :23 foo/bar", repr(c))
 
190
 
 
191
    def test_filemodify_file_executable(self):
 
192
        c = commands.FileModifyCommand("foo/bar", "file", True, "23", None)
 
193
        self.assertEqual("M 755 :23 foo/bar", repr(c))
 
194
 
 
195
    def test_filemodify_file_internal(self):
 
196
        c = commands.FileModifyCommand("foo/bar", "file", False, None,
 
197
            "hello world")
 
198
        self.assertEqual("M 644 inline foo/bar\ndata 11\nhello world", repr(c))
 
199
 
 
200
    def test_filemodify_symlink(self):
 
201
        c = commands.FileModifyCommand("foo/bar", "symlink", False, None, "baz")
 
202
        self.assertEqual("M 120000 inline foo/bar\ndata 3\nbaz", repr(c))
 
203
 
 
204
 
 
205
class TestFileDeleteDisplay(tests.TestCase):
 
206
 
 
207
    def test_filedelete(self):
 
208
        c = commands.FileDeleteCommand("foo/bar")
 
209
        self.assertEqual("D foo/bar", repr(c))
 
210
 
 
211
 
 
212
class TestFileCopyDisplay(tests.TestCase):
 
213
 
 
214
    def test_filecopy(self):
 
215
        c = commands.FileCopyCommand("foo/bar", "foo/baz")
 
216
        self.assertEqual("C foo/bar foo/baz", repr(c))
 
217
 
 
218
    def test_filecopy_quoted(self):
 
219
        # Check the first path is quoted if it contains spaces
 
220
        c = commands.FileCopyCommand("foo/b a r", "foo/b a z")
 
221
        self.assertEqual('C "foo/b a r" foo/b a z', repr(c))
 
222
 
 
223
 
 
224
class TestFileRenameDisplay(tests.TestCase):
 
225
 
 
226
    def test_filerename(self):
 
227
        c = commands.FileRenameCommand("foo/bar", "foo/baz")
 
228
        self.assertEqual("R foo/bar foo/baz", repr(c))
 
229
 
 
230
    def test_filerename_quoted(self):
 
231
        # Check the first path is quoted if it contains spaces
 
232
        c = commands.FileRenameCommand("foo/b a r", "foo/b a z")
 
233
        self.assertEqual('R "foo/b a r" foo/b a z', repr(c))
 
234
 
 
235
 
 
236
class TestFileDeleteAllDisplay(tests.TestCase):
 
237
 
 
238
    def test_filedeleteall(self):
 
239
        c = commands.FileDeleteAllCommand()
 
240
        self.assertEqual("deleteall", repr(c))