/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
24
25
from bzrlib.plugins.fastimport import (
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())