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 |
||
|
6628.1.2
by Jelmer Vernooij
Fix imports, move exporter.py, drop explorer metadata. |
22 |
from .... import tests |
|
0.64.282
by Jelmer Vernooij
Fix output stream to stdout for bzr fast-export. |
23 |
|
|
6628.1.2
by Jelmer Vernooij
Fix imports, move exporter.py, drop explorer metadata. |
24 |
from ..exporter import ( |
|
0.64.282
by Jelmer Vernooij
Fix output stream to stdout for bzr fast-export. |
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 |
||
|
6628.1.2
by Jelmer Vernooij
Fix imports, move exporter.py, drop explorer metadata. |
30 |
from . import ( |
|
0.64.282
by Jelmer Vernooij
Fix output stream to stdout for bzr fast-export. |
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) |
|
|
7027.2.1
by Jelmer Vernooij
Port fastimport to python3. |
46 |
with _get_output_stream(filename) as stream: |
47 |
stream.write(b"bla") |
|
|
0.64.282
by Jelmer Vernooij
Fix output stream to stdout for bzr fast-export. |
48 |
# files ending in .gz are automatically decompressed.
|
|
7027.2.1
by Jelmer Vernooij
Port fastimport to python3. |
49 |
with gzip.GzipFile(filename) as f: |
50 |
self.assertEquals(b"bla", f.read()) |
|
|
0.64.282
by Jelmer Vernooij
Fix output stream to stdout for bzr fast-export. |
51 |
|
52 |
def test_get_source_file(self): |
|
53 |
# other files are opened as regular files.
|
|
54 |
fd, filename = tempfile.mkstemp() |
|
55 |
os.close(fd) |
|
|
7027.2.1
by Jelmer Vernooij
Port fastimport to python3. |
56 |
with _get_output_stream(filename) as stream: |
57 |
stream.write(b"foo") |
|
58 |
with open(filename, 'r') as f: |
|
59 |
self.assertEquals("foo", f.read()) |
|
|
0.64.328
by Jelmer Vernooij
In "plain" mode, skip tags that contain characters not valid in Git. |
60 |
|
61 |
||
62 |
# from dulwich.tests.test_repository:
|
|
63 |
class CheckRefFormatTests(tests.TestCase): |
|
64 |
"""Tests for the check_ref_format function. |
|
65 |
||
66 |
These are the same tests as in the git test suite.
|
|
67 |
"""
|
|
68 |
||
69 |
def test_valid(self): |
|
|
7027.2.1
by Jelmer Vernooij
Port fastimport to python3. |
70 |
self.assertTrue(check_ref_format(b'heads/foo')) |
71 |
self.assertTrue(check_ref_format(b'foo/bar/baz')) |
|
72 |
self.assertTrue(check_ref_format(b'refs///heads/foo')) |
|
73 |
self.assertTrue(check_ref_format(b'foo./bar')) |
|
74 |
self.assertTrue(check_ref_format(b'heads/foo@bar')) |
|
75 |
self.assertTrue(check_ref_format(b'heads/fix.lock.error')) |
|
|
0.64.328
by Jelmer Vernooij
In "plain" mode, skip tags that contain characters not valid in Git. |
76 |
|
77 |
def test_invalid(self): |
|
|
7027.2.1
by Jelmer Vernooij
Port fastimport to python3. |
78 |
self.assertFalse(check_ref_format(b'foo')) |
79 |
self.assertFalse(check_ref_format(b'foo/.bar')) |
|
80 |
self.assertFalse(check_ref_format(b'heads/foo/')) |
|
81 |
self.assertFalse(check_ref_format(b'heads/foo.')) |
|
82 |
self.assertFalse(check_ref_format(b'./foo')) |
|
83 |
self.assertFalse(check_ref_format(b'.refs/foo')) |
|
84 |
self.assertFalse(check_ref_format(b'heads/foo..bar')) |
|
85 |
self.assertFalse(check_ref_format(b'heads/foo?bar')) |
|
86 |
self.assertFalse(check_ref_format(b'heads/foo.lock')) |
|
87 |
self.assertFalse(check_ref_format(b'heads/v@{ation')) |
|
88 |
self.assertFalse(check_ref_format(b'heads/foo\\bar')) |
|
89 |
self.assertFalse(check_ref_format(b'heads/foo\bar')) |
|
90 |
self.assertFalse(check_ref_format(b'heads/foo bar')) |
|
91 |
self.assertFalse(check_ref_format(b'heads/foo\020bar')) |
|
92 |
self.assertFalse(check_ref_format(b'heads/foo\177bar')) |
|
|
0.133.1
by Oleksandr Usov
Add function to rewrite refnames & tests for it |
93 |
|
|
0.133.3
by Oleksandr Usov
Implement comments from patch review: |
94 |
|
|
0.133.1
by Oleksandr Usov
Add function to rewrite refnames & tests for it |
95 |
class CheckRefnameRewriting(tests.TestCase): |
96 |
"""Tests for sanitize_ref_name_for_git function""" |
|
97 |
||
98 |
def test_passthrough_valid(self): |
|
|
7027.2.1
by Jelmer Vernooij
Port fastimport to python3. |
99 |
self.assertEqual(sanitize_ref_name_for_git(b'heads/foo'), b'heads/foo') |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
100 |
self.assertEqual(sanitize_ref_name_for_git( |
101 |
b'foo/bar/baz'), b'foo/bar/baz') |
|
102 |
self.assertEqual(sanitize_ref_name_for_git( |
|
103 |
b'refs///heads/foo'), b'refs///heads/foo') |
|
|
7027.2.1
by Jelmer Vernooij
Port fastimport to python3. |
104 |
self.assertEqual(sanitize_ref_name_for_git(b'foo./bar'), b'foo./bar') |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
105 |
self.assertEqual(sanitize_ref_name_for_git( |
106 |
b'heads/foo@bar'), b'heads/foo@bar') |
|
107 |
self.assertEqual(sanitize_ref_name_for_git( |
|
108 |
b'heads/fix.lock.error'), b'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): |
|
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
111 |
self.assertTrue(check_ref_format( |
112 |
sanitize_ref_name_for_git(b'foo./bar'))) |
|
113 |
self.assertTrue(check_ref_format( |
|
114 |
sanitize_ref_name_for_git(b'heads/foo/'))) |
|
115 |
self.assertTrue(check_ref_format( |
|
116 |
sanitize_ref_name_for_git(b'heads/foo.'))) |
|
|
7027.2.1
by Jelmer Vernooij
Port fastimport to python3. |
117 |
self.assertTrue(check_ref_format(sanitize_ref_name_for_git(b'./foo'))) |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
118 |
self.assertTrue(check_ref_format( |
119 |
sanitize_ref_name_for_git(b'.refs/foo'))) |
|
120 |
self.assertTrue(check_ref_format( |
|
121 |
sanitize_ref_name_for_git(b'heads/foo..bar'))) |
|
122 |
self.assertTrue(check_ref_format( |
|
123 |
sanitize_ref_name_for_git(b'heads/foo?bar'))) |
|
124 |
self.assertTrue(check_ref_format( |
|
125 |
sanitize_ref_name_for_git(b'heads/foo.lock'))) |
|
126 |
self.assertTrue(check_ref_format( |
|
127 |
sanitize_ref_name_for_git(b'heads/v@{ation'))) |
|
128 |
self.assertTrue(check_ref_format( |
|
129 |
sanitize_ref_name_for_git(b'heads/foo\bar'))) |
|
130 |
self.assertTrue(check_ref_format( |
|
131 |
sanitize_ref_name_for_git(b'heads/foo\\bar'))) |
|
132 |
self.assertTrue(check_ref_format( |
|
133 |
sanitize_ref_name_for_git(b'heads/foo bar'))) |
|
134 |
self.assertTrue(check_ref_format( |
|
135 |
sanitize_ref_name_for_git(b'heads/foo\020bar'))) |
|
136 |
self.assertTrue(check_ref_format( |
|
137 |
sanitize_ref_name_for_git(b'heads/foo\177bar'))) |