/brz/remove-bazaar

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