/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
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 the command implementations."""
18
19
import os
20
import tempfile
21
import gzip
22
23
from bzrlib import tests
0.64.309 by Jelmer Vernooij
Add some blackbox tests for 'bzr fast-export'.
24
from bzrlib.tests.blackbox import ExternalBase
0.64.281 by Jelmer Vernooij
Add tests for _get_source_stream.
25
0.64.286 by Jelmer Vernooij
Move command implementations into a separate cmds module.
26
from bzrlib.plugins.fastimport.cmds import (
0.64.281 by Jelmer Vernooij
Add tests for _get_source_stream.
27
    _get_source_stream,
28
    )
29
30
from bzrlib.plugins.fastimport.tests import (
31
    FastimportFeature,
32
    )
33
34
35
class TestSourceStream(tests.TestCase):
36
37
    _test_needs_features = [FastimportFeature]
38
39
    def test_get_source_stream_stdin(self):
40
        # - returns standard in
41
        self.assertIsNot(None, _get_source_stream("-"))
42
43
    def test_get_source_gz(self):
44
        # files ending in .gz are automatically decompressed.
45
        fd, filename = tempfile.mkstemp(suffix=".gz")
46
        f = gzip.GzipFile(fileobj=os.fdopen(fd, "w"), mode='w')
47
        f.write("bla")
48
        f.close()
49
        stream = _get_source_stream(filename)
50
        self.assertIsNot("bla", stream.read())
51
52
    def test_get_source_file(self):
53
        # other files are opened as regular files.
54
        fd, filename = tempfile.mkstemp()
55
        f = os.fdopen(fd, 'w')
56
        f.write("bla")
57
        f.close()
58
        stream = _get_source_stream(filename)
59
        self.assertIsNot("bla", stream.read())
0.64.309 by Jelmer Vernooij
Add some blackbox tests for 'bzr fast-export'.
60
61
62
class TestFastExport(ExternalBase):
63
64
    def test_empty(self):
65
        self.make_branch_and_tree("br")
66
        self.assertEquals("", self.run_bzr("fast-export br")[0])
67
68
    def test_pointless(self):
69
        tree = self.make_branch_and_tree("br")
70
        tree.commit("pointless")
71
        data = self.run_bzr("fast-export br")[0]
72
        self.assertTrue(data.startswith('commit refs/heads/master\nmark :1\ncommitter'))
73
74
    def test_file(self):
75
        tree = self.make_branch_and_tree("br")
76
        tree.commit("pointless")
77
        data = self.run_bzr("fast-export br br.fi")[0]
78
        self.assertEquals("", data)
0.64.314 by Jelmer Vernooij
Use TestCase.assertPathExists if available (fix deprecation warning with bzr 2.4)
79
        try:
80
            self.assertPathExists("br.fi")
81
        except AttributeError: # bzr < 2.4
82
            self.failUnlessExists("br.fi")
0.64.310 by Jelmer Vernooij
Fix fast-import-info.
83
84
85
simple_fast_import_stream = """commit refs/heads/master
86
mark :1
87
committer Jelmer Vernooij <jelmer@samba.org> 1299718135 +0100
88
data 7
89
initial
90
91
"""
92
93
class TestFastImportInfo(ExternalBase):
94
95
    def test_simple(self):
96
        self.build_tree_contents([('simple.fi', simple_fast_import_stream)])
97
        output = self.run_bzr("fast-import-info simple.fi")[0]
98
        self.assertEquals(output, """Command counts:
99
\t0\tblob
100
\t0\tcheckpoint
101
\t1\tcommit
102
\t0\tfeature
103
\t0\tprogress
104
\t0\treset
105
\t0\ttag
106
File command counts:
107
\t0\tfilemodify
108
\t0\tfiledelete
109
\t0\tfilecopy
110
\t0\tfilerename
111
\t0\tfiledeleteall
112
Parent counts:
113
\t1\tparents-0
114
\t0\ttotal revisions merged
115
Commit analysis:
116
\tno\texecutables
117
\tno\tseparate authors found
118
\tno\tsymlinks
119
\tno\tblobs referenced by SHA
120
Head analysis:
121
\t[':1']\trefs/heads/master
122
Merges:
123
""")
0.131.1 by Jelmer Vernooij
Add blackbox tests for 'bzr fast-import'.
124
125
126
class TestFastImport(ExternalBase):
127
128
    def test_empty(self):
129
        self.build_tree_contents([('empty.fi', "")])
130
        self.make_branch_and_tree("br")
131
        self.assertEquals("", self.run_bzr("fast-import empty.fi br")[0])
132
133
    def test_file(self):
134
        tree = self.make_branch_and_tree("br")
135
        self.build_tree_contents([('file.fi', simple_fast_import_stream)])
136
        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.
137
        self.assertEquals(1, tree.branch.revno())
0.64.321 by Jelmer Vernooij
Allow fast-import-filter to be used without first argument.
138
139
140
class TestFastImportFilter(ExternalBase):
141
142
    def test_empty(self):
143
        self.build_tree_contents([('empty.fi', "")])
144
        self.make_branch_and_tree("br")
145
        self.assertEquals("", self.run_bzr("fast-import-filter -")[0])
146
147
    def test_default_stdin(self):
148
        self.build_tree_contents([('empty.fi', "")])
149
        self.make_branch_and_tree("br")
150
        self.assertEquals("", self.run_bzr("fast-import-filter")[0])