1 # Copyright (C) 2010 Canonical Ltd
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.
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.
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
17 """Test the command implementations."""
23 from bzrlib
import tests
24 from bzrlib
.tests
.blackbox
import ExternalBase
26 from bzrlib
.plugins
.fastimport
.cmds
import (
30 from bzrlib
.plugins
.fastimport
.tests
import (
35 class TestSourceStream(tests
.TestCase
):
37 _test_needs_features
= [FastimportFeature
]
39 def test_get_source_stream_stdin(self
):
40 # - returns standard in
41 self
.assertIsNot(None, _get_source_stream("-"))
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')
49 stream
= _get_source_stream(filename
)
50 self
.assertIsNot("bla", stream
.read())
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')
58 stream
= _get_source_stream(filename
)
59 self
.assertIsNot("bla", stream
.read())
62 class TestFastExport(ExternalBase
):
65 self
.make_branch_and_tree("br")
66 self
.assertEquals("", self
.run_bzr("fast-export br")[0])
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'))
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
)
80 self
.assertPathExists("br.fi")
81 except AttributeError: # bzr < 2.4
82 self
.failUnlessExists("br.fi")
85 simple_fast_import_stream
= """commit refs/heads/master
87 committer Jelmer Vernooij <jelmer@samba.org> 1299718135 +0100
93 class TestFastImportInfo(ExternalBase
):
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:
114 \t0\ttotal revisions merged
117 \tno\tseparate authors found
119 \tno\tblobs referenced by SHA
121 \t[':1']\trefs/heads/master
126 class TestFastImport(ExternalBase
):
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])
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]
137 self
.assertEquals(3, tree
.branch
.revno())