bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
6614.1.3
by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual. |
1 |
# Copyright (C) 2009, 2010, 2016 Canonical Ltd
|
|
4354.3.12
by Jelmer Vernooij
Add tests for _valid_tag. |
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
16 |
||
17 |
"""Tests for _rio_*."""
|
|
18 |
||
|
6684.1.8
by Martin
Make test__rio pass on Python 3 |
19 |
from __future__ import absolute_import |
20 |
||
21 |
from .. import ( |
|
|
4354.3.12
by Jelmer Vernooij
Add tests for _valid_tag. |
22 |
rio, |
23 |
tests, |
|
24 |
)
|
|
|
6684.1.8
by Martin
Make test__rio pass on Python 3 |
25 |
from ..sixish import ( |
26 |
text_type, |
|
27 |
)
|
|
|
4354.3.12
by Jelmer Vernooij
Add tests for _valid_tag. |
28 |
|
29 |
||
|
6625.1.5
by Martin
Drop custom load_tests implementation and use unittest signature |
30 |
def load_tests(loader, standard_tests, pattern): |
|
4913.3.1
by John Arbash Meinel
Implement a permute_for_extension helper. |
31 |
suite, _ = tests.permute_tests_for_extension(standard_tests, loader, |
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
32 |
'breezy._rio_py', 'breezy._rio_pyx') |
|
4354.3.12
by Jelmer Vernooij
Add tests for _valid_tag. |
33 |
return suite |
34 |
||
35 |
||
36 |
class TestValidTag(tests.TestCase): |
|
37 |
||
38 |
module = None # Filled in by test parameterization |
|
39 |
||
40 |
def test_ok(self): |
|
41 |
self.assertTrue(self.module._valid_tag("foo")) |
|
42 |
||
43 |
def test_no_spaces(self): |
|
44 |
self.assertFalse(self.module._valid_tag("foo bla")) |
|
45 |
||
|
4354.3.13
by Jelmer Vernooij
Add more RIO tests, fix bugs in pyrex implementation. |
46 |
def test_numeric(self): |
47 |
self.assertTrue(self.module._valid_tag("3foo423")) |
|
48 |
||
|
4354.3.12
by Jelmer Vernooij
Add tests for _valid_tag. |
49 |
def test_no_colon(self): |
50 |
self.assertFalse(self.module._valid_tag("foo:bla")) |
|
|
6684.1.8
by Martin
Make test__rio pass on Python 3 |
51 |
|
|
4354.3.12
by Jelmer Vernooij
Add tests for _valid_tag. |
52 |
def test_type_error(self): |
53 |
self.assertRaises(TypeError, self.module._valid_tag, 423) |
|
54 |
||
55 |
def test_empty(self): |
|
56 |
self.assertFalse(self.module._valid_tag("")) |
|
|
4354.3.13
by Jelmer Vernooij
Add more RIO tests, fix bugs in pyrex implementation. |
57 |
|
|
4354.3.15
by Jelmer Vernooij
Extend valid_tags tests a bit, test that stanza pairs contain the right types. |
58 |
def test_unicode(self): |
|
6684.1.8
by Martin
Make test__rio pass on Python 3 |
59 |
if text_type is str: |
60 |
# When str is a unicode type, it is valid for a tag
|
|
61 |
self.assertTrue(self.module._valid_tag(u"foo")) |
|
62 |
else: |
|
63 |
self.assertRaises(TypeError, self.module._valid_tag, u"foo") |
|
|
4354.3.15
by Jelmer Vernooij
Extend valid_tags tests a bit, test that stanza pairs contain the right types. |
64 |
|
65 |
def test_non_ascii_char(self): |
|
66 |
self.assertFalse(self.module._valid_tag("\xb5")) |
|
67 |
||
|
4354.3.13
by Jelmer Vernooij
Add more RIO tests, fix bugs in pyrex implementation. |
68 |
|
69 |
class TestReadUTF8Stanza(tests.TestCase): |
|
70 |
||
71 |
module = None # Filled in by test parameterization |
|
72 |
||
73 |
def assertReadStanza(self, result, line_iter): |
|
|
4354.3.15
by Jelmer Vernooij
Extend valid_tags tests a bit, test that stanza pairs contain the right types. |
74 |
s = self.module._read_stanza_utf8(line_iter) |
|
6614.1.3
by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual. |
75 |
self.assertEqual(result, s) |
|
4354.3.15
by Jelmer Vernooij
Extend valid_tags tests a bit, test that stanza pairs contain the right types. |
76 |
if s is not None: |
77 |
for tag, value in s.iter_pairs(): |
|
78 |
self.assertIsInstance(tag, str) |
|
|
6684.1.8
by Martin
Make test__rio pass on Python 3 |
79 |
self.assertIsInstance(value, text_type) |
|
4354.3.13
by Jelmer Vernooij
Add more RIO tests, fix bugs in pyrex implementation. |
80 |
|
81 |
def assertReadStanzaRaises(self, exception, line_iter): |
|
82 |
self.assertRaises(exception, self.module._read_stanza_utf8, line_iter) |
|
83 |
||
84 |
def test_no_string(self): |
|
85 |
self.assertReadStanzaRaises(TypeError, [21323]) |
|
86 |
||
87 |
def test_empty(self): |
|
88 |
self.assertReadStanza(None, []) |
|
89 |
||
90 |
def test_none(self): |
|
|
6684.1.8
by Martin
Make test__rio pass on Python 3 |
91 |
self.assertReadStanza(None, [b""]) |
|
4354.3.13
by Jelmer Vernooij
Add more RIO tests, fix bugs in pyrex implementation. |
92 |
|
93 |
def test_simple(self): |
|
|
6684.1.8
by Martin
Make test__rio pass on Python 3 |
94 |
self.assertReadStanza(rio.Stanza(foo="bar"), [b"foo: bar\n", b""]) |
|
4354.3.13
by Jelmer Vernooij
Add more RIO tests, fix bugs in pyrex implementation. |
95 |
|
96 |
def test_multi_line(self): |
|
|
6684.1.8
by Martin
Make test__rio pass on Python 3 |
97 |
self.assertReadStanza( |
98 |
rio.Stanza(foo="bar\nbla"), [b"foo: bar\n", b"\tbla\n"]) |
|
|
4354.3.13
by Jelmer Vernooij
Add more RIO tests, fix bugs in pyrex implementation. |
99 |
|
100 |
def test_repeated(self): |
|
101 |
s = rio.Stanza() |
|
102 |
s.add("foo", "bar") |
|
103 |
s.add("foo", "foo") |
|
|
6684.1.8
by Martin
Make test__rio pass on Python 3 |
104 |
self.assertReadStanza(s, [b"foo: bar\n", b"foo: foo\n"]) |
|
4354.3.13
by Jelmer Vernooij
Add more RIO tests, fix bugs in pyrex implementation. |
105 |
|
106 |
def test_invalid_early_colon(self): |
|
|
6684.1.8
by Martin
Make test__rio pass on Python 3 |
107 |
self.assertReadStanzaRaises(ValueError, [b"f:oo: bar\n"]) |
|
4354.3.13
by Jelmer Vernooij
Add more RIO tests, fix bugs in pyrex implementation. |
108 |
|
109 |
def test_invalid_tag(self): |
|
|
6684.1.8
by Martin
Make test__rio pass on Python 3 |
110 |
self.assertReadStanzaRaises(ValueError, [b"f%oo: bar\n"]) |
|
4354.3.13
by Jelmer Vernooij
Add more RIO tests, fix bugs in pyrex implementation. |
111 |
|
112 |
def test_continuation_too_early(self): |
|
|
6684.1.8
by Martin
Make test__rio pass on Python 3 |
113 |
self.assertReadStanzaRaises(ValueError, [b"\tbar\n"]) |
|
4354.3.13
by Jelmer Vernooij
Add more RIO tests, fix bugs in pyrex implementation. |
114 |
|
115 |
def test_large(self): |
|
|
6684.1.8
by Martin
Make test__rio pass on Python 3 |
116 |
value = b"bla" * 9000 |
|
4354.3.13
by Jelmer Vernooij
Add more RIO tests, fix bugs in pyrex implementation. |
117 |
self.assertReadStanza(rio.Stanza(foo=value), |
|
6684.1.8
by Martin
Make test__rio pass on Python 3 |
118 |
[b"foo: %s\n" % value]) |
|
4354.3.13
by Jelmer Vernooij
Add more RIO tests, fix bugs in pyrex implementation. |
119 |
|
120 |
def test_non_ascii_char(self): |
|
121 |
self.assertReadStanza(rio.Stanza(foo=u"n\xe5me"), |
|
122 |
[u"foo: n\xe5me\n".encode("utf-8")]) |
|
123 |
||
124 |
||
125 |
class TestReadUnicodeStanza(tests.TestCase): |
|
126 |
||
127 |
module = None # Filled in by test parameterization |
|
128 |
||
129 |
def assertReadStanza(self, result, line_iter): |
|
|
4354.3.15
by Jelmer Vernooij
Extend valid_tags tests a bit, test that stanza pairs contain the right types. |
130 |
s = self.module._read_stanza_unicode(line_iter) |
|
6614.1.3
by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual. |
131 |
self.assertEqual(result, s) |
|
4354.3.15
by Jelmer Vernooij
Extend valid_tags tests a bit, test that stanza pairs contain the right types. |
132 |
if s is not None: |
133 |
for tag, value in s.iter_pairs(): |
|
134 |
self.assertIsInstance(tag, str) |
|
|
6684.1.8
by Martin
Make test__rio pass on Python 3 |
135 |
self.assertIsInstance(value, text_type) |
|
4354.3.13
by Jelmer Vernooij
Add more RIO tests, fix bugs in pyrex implementation. |
136 |
|
137 |
def assertReadStanzaRaises(self, exception, line_iter): |
|
138 |
self.assertRaises(exception, self.module._read_stanza_unicode, |
|
139 |
line_iter) |
|
140 |
||
141 |
def test_no_string(self): |
|
142 |
self.assertReadStanzaRaises(TypeError, [21323]) |
|
143 |
||
144 |
def test_empty(self): |
|
145 |
self.assertReadStanza(None, []) |
|
146 |
||
147 |
def test_none(self): |
|
148 |
self.assertReadStanza(None, [u""]) |
|
149 |
||
150 |
def test_simple(self): |
|
151 |
self.assertReadStanza(rio.Stanza(foo="bar"), [u"foo: bar\n", u""]) |
|
152 |
||
153 |
def test_multi_line(self): |
|
154 |
self.assertReadStanza(rio.Stanza(foo="bar\nbla"), |
|
155 |
[u"foo: bar\n", u"\tbla\n"]) |
|
156 |
||
157 |
def test_repeated(self): |
|
158 |
s = rio.Stanza() |
|
159 |
s.add("foo", "bar") |
|
160 |
s.add("foo", "foo") |
|
161 |
self.assertReadStanza(s, [u"foo: bar\n", u"foo: foo\n"]) |
|
162 |
||
163 |
def test_invalid_early_colon(self): |
|
164 |
self.assertReadStanzaRaises(ValueError, [u"f:oo: bar\n"]) |
|
165 |
||
166 |
def test_invalid_tag(self): |
|
167 |
self.assertReadStanzaRaises(ValueError, [u"f%oo: bar\n"]) |
|
168 |
||
169 |
def test_continuation_too_early(self): |
|
170 |
self.assertReadStanzaRaises(ValueError, [u"\tbar\n"]) |
|
171 |
||
172 |
def test_large(self): |
|
173 |
value = u"bla" * 9000 |
|
174 |
self.assertReadStanza(rio.Stanza(foo=value), |
|
175 |
[u"foo: %s\n" % value]) |
|
176 |
||
177 |
def test_non_ascii_char(self): |
|
178 |
self.assertReadStanza(rio.Stanza(foo=u"n\xe5me"), [u"foo: n\xe5me\n"]) |