/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.64.282 by Jelmer Vernooij
Fix output stream to stdout for bzr fast-export.
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 exporter."""
18
19
import os
20
import tempfile
21
import gzip
22
23
from bzrlib import tests
24
25
from bzrlib.plugins.fastimport.exporter import (
26
    _get_output_stream,
0.64.328 by Jelmer Vernooij
In "plain" mode, skip tags that contain characters not valid in Git.
27
    check_ref_format,
0.64.282 by Jelmer Vernooij
Fix output stream to stdout for bzr fast-export.
28
    )
29
30
from bzrlib.plugins.fastimport.tests import (
31
    FastimportFeature,
32
    )
33
34
35
class TestOutputStream(tests.TestCase):
36
37
    _test_needs_features = [FastimportFeature]
38
39
    def test_get_output_stream_stdout(self):
40
        # - returns standard out
41
        self.assertIsNot(None, _get_output_stream("-"))
42
43
    def test_get_source_gz(self):
44
        fd, filename = tempfile.mkstemp(suffix=".gz")
45
        os.close(fd)
46
        stream = _get_output_stream(filename)
47
        stream.write("bla")
48
        stream.close()
49
        # files ending in .gz are automatically decompressed.
50
        f = gzip.GzipFile(filename)
51
        self.assertEquals("bla", f.read())
52
        f.close()
53
54
    def test_get_source_file(self):
55
        # other files are opened as regular files.
56
        fd, filename = tempfile.mkstemp()
57
        os.close(fd)
58
        stream = _get_output_stream(filename)
59
        stream.write("foo")
60
        stream.close()
61
        f = open(filename, 'r')
62
        self.assertEquals("foo", f.read())
63
        f.close()
0.64.328 by Jelmer Vernooij
In "plain" mode, skip tags that contain characters not valid in Git.
64
65
66
# from dulwich.tests.test_repository:
67
class CheckRefFormatTests(tests.TestCase):
68
    """Tests for the check_ref_format function.
69
70
    These are the same tests as in the git test suite.
71
    """
72
73
    def test_valid(self):
74
        self.assertTrue(check_ref_format('heads/foo'))
75
        self.assertTrue(check_ref_format('foo/bar/baz'))
76
        self.assertTrue(check_ref_format('refs///heads/foo'))
77
        self.assertTrue(check_ref_format('foo./bar'))
78
        self.assertTrue(check_ref_format('heads/foo@bar'))
79
        self.assertTrue(check_ref_format('heads/fix.lock.error'))
80
81
    def test_invalid(self):
82
        self.assertFalse(check_ref_format('foo'))
83
        self.assertFalse(check_ref_format('heads/foo/'))
84
        self.assertFalse(check_ref_format('./foo'))
85
        self.assertFalse(check_ref_format('.refs/foo'))
86
        self.assertFalse(check_ref_format('heads/foo..bar'))
87
        self.assertFalse(check_ref_format('heads/foo?bar'))
88
        self.assertFalse(check_ref_format('heads/foo.lock'))
89
        self.assertFalse(check_ref_format('heads/v@{ation'))
90
        self.assertFalse(check_ref_format('heads/foo\bar'))