/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.64.281 by Jelmer Vernooij
Add tests for _get_source_stream.
1
# Copyright (C) 2010 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
0.64.334 by Jelmer Vernooij
Remove old FSF address. Thanks Dan Callaghan.
14
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
0.64.281 by Jelmer Vernooij
Add tests for _get_source_stream.
15
16
"""Test the command implementations."""
17
18
import os
19
import tempfile
20
import gzip
21
22
from bzrlib import tests
0.64.309 by Jelmer Vernooij
Add some blackbox tests for 'bzr fast-export'.
23
from bzrlib.tests.blackbox import ExternalBase
0.64.281 by Jelmer Vernooij
Add tests for _get_source_stream.
24
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
25
from bzrlib.plugins.fastimport.cmds import (
0.64.281 by Jelmer Vernooij
Add tests for _get_source_stream.
26
    _get_source_stream,
27
    )
28
29
from bzrlib.plugins.fastimport.tests import (
30
    FastimportFeature,
31
    )
32
33
34
class TestSourceStream(tests.TestCase):
35
36
    _test_needs_features = [FastimportFeature]
37
38
    def test_get_source_stream_stdin(self):
39
        # - returns standard in
40
        self.assertIsNot(None, _get_source_stream("-"))
41
42
    def test_get_source_gz(self):
43
        # files ending in .gz are automatically decompressed.
44
        fd, filename = tempfile.mkstemp(suffix=".gz")
45
        f = gzip.GzipFile(fileobj=os.fdopen(fd, "w"), mode='w')
46
        f.write("bla")
47
        f.close()
48
        stream = _get_source_stream(filename)
49
        self.assertIsNot("bla", stream.read())
50
51
    def test_get_source_file(self):
52
        # other files are opened as regular files.
53
        fd, filename = tempfile.mkstemp()
54
        f = os.fdopen(fd, 'w')
55
        f.write("bla")
56
        f.close()
57
        stream = _get_source_stream(filename)
58
        self.assertIsNot("bla", stream.read())
0.64.309 by Jelmer Vernooij
Add some blackbox tests for 'bzr fast-export'.
59
60
61
class TestFastExport(ExternalBase):
62
63
    def test_empty(self):
64
        self.make_branch_and_tree("br")
65
        self.assertEquals("", self.run_bzr("fast-export br")[0])
66
67
    def test_pointless(self):
68
        tree = self.make_branch_and_tree("br")
69
        tree.commit("pointless")
70
        data = self.run_bzr("fast-export br")[0]
71
        self.assertTrue(data.startswith('commit refs/heads/master\nmark :1\ncommitter'))
72
73
    def test_file(self):
74
        tree = self.make_branch_and_tree("br")
75
        tree.commit("pointless")
76
        data = self.run_bzr("fast-export br br.fi")[0]
77
        self.assertEquals("", data)
0.64.314 by Jelmer Vernooij
Use TestCase.assertPathExists if available (fix deprecation warning with bzr 2.4)
78
        try:
79
            self.assertPathExists("br.fi")
80
        except AttributeError: # bzr < 2.4
81
            self.failUnlessExists("br.fi")
0.64.310 by Jelmer Vernooij
Fix fast-import-info.
82
0.133.3 by Oleksandr Usov
Implement comments from patch review:
83
    def test_tag_rewriting(self):
84
        tree = self.make_branch_and_tree("br")
85
        tree.commit("pointless")
86
        self.assertTrue(tree.branch.supports_tags())
87
        rev_id = tree.branch.dotted_revno_to_revision_id((1,))
88
        tree.branch.tags.set_tag("goodTag", rev_id)
89
        tree.branch.tags.set_tag("bad Tag", rev_id)
90
        
91
        # first check --no-rewrite-tag-names
92
        data = self.run_bzr("fast-export --plain --no-rewrite-tag-names br")[0]
93
        self.assertNotEqual(-1, data.find("reset refs/tags/goodTag"))
94
        self.assertEqual(data.find("reset refs/tags/"), data.rfind("reset refs/tags/"))
95
        
96
        # and now with --rewrite-tag-names
97
        data = self.run_bzr("fast-export --plain --rewrite-tag-names br")[0]
98
        self.assertNotEqual(-1, data.find("reset refs/tags/goodTag"))
99
        # "bad Tag" should be exported as bad_Tag
100
        self.assertNotEqual(-1, data.find("reset refs/tags/bad_Tag"))
101
0.64.310 by Jelmer Vernooij
Fix fast-import-info.
102
103
simple_fast_import_stream = """commit refs/heads/master
104
mark :1
105
committer Jelmer Vernooij <jelmer@samba.org> 1299718135 +0100
106
data 7
107
initial
108
109
"""
110
111
class TestFastImportInfo(ExternalBase):
112
113
    def test_simple(self):
114
        self.build_tree_contents([('simple.fi', simple_fast_import_stream)])
115
        output = self.run_bzr("fast-import-info simple.fi")[0]
116
        self.assertEquals(output, """Command counts:
117
\t0\tblob
118
\t0\tcheckpoint
119
\t1\tcommit
120
\t0\tfeature
121
\t0\tprogress
122
\t0\treset
123
\t0\ttag
124
File command counts:
125
\t0\tfilemodify
126
\t0\tfiledelete
127
\t0\tfilecopy
128
\t0\tfilerename
129
\t0\tfiledeleteall
130
Parent counts:
131
\t1\tparents-0
132
\t0\ttotal revisions merged
133
Commit analysis:
134
\tno\texecutables
135
\tno\tseparate authors found
136
\tno\tsymlinks
137
\tno\tblobs referenced by SHA
138
Head analysis:
139
\t[':1']\trefs/heads/master
140
Merges:
141
""")
0.131.1 by Jelmer Vernooij
Add blackbox tests for 'bzr fast-import'.
142
143
144
class TestFastImport(ExternalBase):
145
146
    def test_empty(self):
147
        self.build_tree_contents([('empty.fi', "")])
148
        self.make_branch_and_tree("br")
149
        self.assertEquals("", self.run_bzr("fast-import empty.fi br")[0])
150
151
    def test_file(self):
152
        tree = self.make_branch_and_tree("br")
153
        self.build_tree_contents([('file.fi', simple_fast_import_stream)])
154
        data = self.run_bzr("fast-import file.fi br")[0]
0.131.2 by Jelmer Vernooij
Fix 'bzr fast-import' bzrdir argument and add a blackbox test.
155
        self.assertEquals(1, tree.branch.revno())
0.64.321 by Jelmer Vernooij
Allow fast-import-filter to be used without first argument.
156
157
158
class TestFastImportFilter(ExternalBase):
159
160
    def test_empty(self):
161
        self.build_tree_contents([('empty.fi', "")])
162
        self.make_branch_and_tree("br")
163
        self.assertEquals("", self.run_bzr("fast-import-filter -")[0])
164
165
    def test_default_stdin(self):
166
        self.build_tree_contents([('empty.fi', "")])
167
        self.make_branch_and_tree("br")
168
        self.assertEquals("", self.run_bzr("fast-import-filter")[0])