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
|
|
|
0.64.334
by Jelmer Vernooij
Remove old FSF address. Thanks Dan Callaghan. |
14 |
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
0.64.282
by Jelmer Vernooij
Fix output stream to stdout for bzr fast-export. |
15 |
|
16 |
"""Test the exporter."""
|
|
17 |
||
18 |
import os |
|
19 |
import tempfile |
|
20 |
import gzip |
|
21 |
||
22 |
from bzrlib import tests |
|
23 |
||
24 |
from bzrlib.plugins.fastimport.exporter import ( |
|
25 |
_get_output_stream, |
|
|
0.64.328
by Jelmer Vernooij
In "plain" mode, skip tags that contain characters not valid in Git. |
26 |
check_ref_format, |
|
0.133.1
by Oleksandr Usov
Add function to rewrite refnames & tests for it |
27 |
sanitize_ref_name_for_git
|
|
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')) |
|
|
0.133.1
by Oleksandr Usov
Add function to rewrite refnames & tests for it |
83 |
self.assertFalse(check_ref_format('foo/.bar')) |
|
0.64.328
by Jelmer Vernooij
In "plain" mode, skip tags that contain characters not valid in Git. |
84 |
self.assertFalse(check_ref_format('heads/foo/')) |
|
0.133.1
by Oleksandr Usov
Add function to rewrite refnames & tests for it |
85 |
self.assertFalse(check_ref_format('heads/foo.')) |
|
0.64.328
by Jelmer Vernooij
In "plain" mode, skip tags that contain characters not valid in Git. |
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')) |
|
|
0.133.1
by Oleksandr Usov
Add function to rewrite refnames & tests for it |
92 |
self.assertFalse(check_ref_format('heads/foo\\bar')) |
|
0.64.328
by Jelmer Vernooij
In "plain" mode, skip tags that contain characters not valid in Git. |
93 |
self.assertFalse(check_ref_format('heads/foo\bar')) |
|
0.133.1
by Oleksandr Usov
Add function to rewrite refnames & tests for it |
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')) |
|
97 |
||
|
0.133.3
by Oleksandr Usov
Implement comments from patch review: |
98 |
|
|
0.133.1
by Oleksandr Usov
Add function to rewrite refnames & tests for it |
99 |
class CheckRefnameRewriting(tests.TestCase): |
100 |
"""Tests for sanitize_ref_name_for_git function""" |
|
101 |
||
102 |
def test_passthrough_valid(self): |
|
|
0.133.3
by Oleksandr Usov
Implement comments from patch review: |
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') |
|
|
0.133.1
by Oleksandr Usov
Add function to rewrite refnames & tests for it |
109 |
|
110 |
def test_rewrite_invalid(self): |
|
|
0.133.3
by Oleksandr Usov
Implement comments from patch review: |
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'))) |