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, see <http://www.gnu.org/licenses/>.
16 """Test the exporter."""
22 from bzrlib
import tests
24 from bzrlib
.plugins
.fastimport
.exporter
import (
27 sanitize_ref_name_for_git
30 from bzrlib
.plugins
.fastimport
.tests
import (
35 class TestOutputStream(tests
.TestCase
):
37 _test_needs_features
= [FastimportFeature
]
39 def test_get_output_stream_stdout(self
):
40 # - returns standard out
41 self
.assertIsNot(None, _get_output_stream("-"))
43 def test_get_source_gz(self
):
44 fd
, filename
= tempfile
.mkstemp(suffix
=".gz")
46 stream
= _get_output_stream(filename
)
49 # files ending in .gz are automatically decompressed.
50 f
= gzip
.GzipFile(filename
)
51 self
.assertEquals("bla", f
.read())
54 def test_get_source_file(self
):
55 # other files are opened as regular files.
56 fd
, filename
= tempfile
.mkstemp()
58 stream
= _get_output_stream(filename
)
61 f
= open(filename
, 'r')
62 self
.assertEquals("foo", f
.read())
66 # from dulwich.tests.test_repository:
67 class CheckRefFormatTests(tests
.TestCase
):
68 """Tests for the check_ref_format function.
70 These are the same tests as in the git test suite.
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'))
81 def test_invalid(self
):
82 self
.assertFalse(check_ref_format('foo'))
83 self
.assertFalse(check_ref_format('foo/.bar'))
84 self
.assertFalse(check_ref_format('heads/foo/'))
85 self
.assertFalse(check_ref_format('heads/foo.'))
86 self
.assertFalse(check_ref_format('./foo'))
87 self
.assertFalse(check_ref_format('.refs/foo'))
88 self
.assertFalse(check_ref_format('heads/foo..bar'))
89 self
.assertFalse(check_ref_format('heads/foo?bar'))
90 self
.assertFalse(check_ref_format('heads/foo.lock'))
91 self
.assertFalse(check_ref_format('heads/v@{ation'))
92 self
.assertFalse(check_ref_format('heads/foo\\bar'))
93 self
.assertFalse(check_ref_format('heads/foo\bar'))
94 self
.assertFalse(check_ref_format('heads/foo bar'))
95 self
.assertFalse(check_ref_format('heads/foo\020bar'))
96 self
.assertFalse(check_ref_format('heads/foo\177bar'))
99 class CheckRefnameRewriting(tests
.TestCase
):
100 """Tests for sanitize_ref_name_for_git function"""
102 def test_passthrough_valid(self
):
103 self
.assertEqual(sanitize_ref_name_for_git('heads/foo'), 'heads/foo')
104 self
.assertEqual(sanitize_ref_name_for_git('foo/bar/baz'), 'foo/bar/baz')
105 self
.assertEqual(sanitize_ref_name_for_git('refs///heads/foo'), 'refs///heads/foo')
106 self
.assertEqual(sanitize_ref_name_for_git('foo./bar'), 'foo./bar')
107 self
.assertEqual(sanitize_ref_name_for_git('heads/foo@bar'), 'heads/foo@bar')
108 self
.assertEqual(sanitize_ref_name_for_git('heads/fix.lock.error'), 'heads/fix.lock.error')
110 def test_rewrite_invalid(self
):
111 self
.assertTrue(check_ref_format(sanitize_ref_name_for_git('foo./bar')))
112 self
.assertTrue(check_ref_format(sanitize_ref_name_for_git('heads/foo/')))
113 self
.assertTrue(check_ref_format(sanitize_ref_name_for_git('heads/foo.')))
114 self
.assertTrue(check_ref_format(sanitize_ref_name_for_git('./foo')))
115 self
.assertTrue(check_ref_format(sanitize_ref_name_for_git('.refs/foo')))
116 self
.assertTrue(check_ref_format(sanitize_ref_name_for_git('heads/foo..bar')))
117 self
.assertTrue(check_ref_format(sanitize_ref_name_for_git('heads/foo?bar')))
118 self
.assertTrue(check_ref_format(sanitize_ref_name_for_git('heads/foo.lock')))
119 self
.assertTrue(check_ref_format(sanitize_ref_name_for_git('heads/v@{ation')))
120 self
.assertTrue(check_ref_format(sanitize_ref_name_for_git('heads/foo\bar')))
121 self
.assertTrue(check_ref_format(sanitize_ref_name_for_git('heads/foo\\bar')))
122 self
.assertTrue(check_ref_format(sanitize_ref_name_for_git('heads/foo bar')))
123 self
.assertTrue(check_ref_format(sanitize_ref_name_for_git('heads/foo\020bar')))
124 self
.assertTrue(check_ref_format(sanitize_ref_name_for_git('heads/foo\177bar')))