/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test__rio.py

  • Committer: Marius Kruger
  • Date: 2010-07-10 21:28:56 UTC
  • mto: (5384.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 5385.
  • Revision ID: marius.kruger@enerweb.co.za-20100710212856-uq4ji3go0u5se7hx
* Update documentation
* add NEWS

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009, 2010, 2016 Canonical Ltd
 
1
# Copyright (C) 2009, 2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
16
16
 
17
17
"""Tests for _rio_*."""
18
18
 
19
 
from __future__ import absolute_import
20
 
 
21
 
from .. import (
 
19
from bzrlib import (
22
20
    rio,
23
21
    tests,
24
22
    )
25
 
from ..sixish import (
26
 
    text_type,
27
 
    )
28
 
 
29
 
 
30
 
def load_tests(loader, standard_tests, pattern):
 
23
 
 
24
 
 
25
def load_tests(standard_tests, module, loader):
31
26
    suite, _ = tests.permute_tests_for_extension(standard_tests, loader,
32
 
                                                 'breezy._rio_py', 'breezy._rio_pyx')
 
27
        'bzrlib._rio_py', 'bzrlib._rio_pyx')
33
28
    return suite
34
29
 
35
30
 
36
31
class TestValidTag(tests.TestCase):
37
32
 
38
 
    module = None  # Filled in by test parameterization
 
33
    module = None # Filled in by test parameterization
39
34
 
40
35
    def test_ok(self):
41
36
        self.assertTrue(self.module._valid_tag("foo"))
48
43
 
49
44
    def test_no_colon(self):
50
45
        self.assertFalse(self.module._valid_tag("foo:bla"))
51
 
 
 
46
    
52
47
    def test_type_error(self):
53
48
        self.assertRaises(TypeError, self.module._valid_tag, 423)
54
49
 
56
51
        self.assertFalse(self.module._valid_tag(""))
57
52
 
58
53
    def test_unicode(self):
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")
 
54
        self.assertRaises(TypeError, self.module._valid_tag, u"foo")
64
55
 
65
56
    def test_non_ascii_char(self):
66
57
        self.assertFalse(self.module._valid_tag("\xb5"))
68
59
 
69
60
class TestReadUTF8Stanza(tests.TestCase):
70
61
 
71
 
    module = None  # Filled in by test parameterization
 
62
    module = None # Filled in by test parameterization
72
63
 
73
64
    def assertReadStanza(self, result, line_iter):
74
65
        s = self.module._read_stanza_utf8(line_iter)
75
 
        self.assertEqual(result, s)
 
66
        self.assertEquals(result, s)
76
67
        if s is not None:
77
68
            for tag, value in s.iter_pairs():
78
69
                self.assertIsInstance(tag, str)
79
 
                self.assertIsInstance(value, text_type)
 
70
                self.assertIsInstance(value, unicode)
80
71
 
81
72
    def assertReadStanzaRaises(self, exception, line_iter):
82
73
        self.assertRaises(exception, self.module._read_stanza_utf8, line_iter)
88
79
        self.assertReadStanza(None, [])
89
80
 
90
81
    def test_none(self):
91
 
        self.assertReadStanza(None, [b""])
 
82
        self.assertReadStanza(None, [""])
92
83
 
93
84
    def test_simple(self):
94
 
        self.assertReadStanza(rio.Stanza(foo="bar"), [b"foo: bar\n", b""])
 
85
        self.assertReadStanza(rio.Stanza(foo="bar"), ["foo: bar\n", ""])
95
86
 
96
87
    def test_multi_line(self):
97
 
        self.assertReadStanza(
98
 
            rio.Stanza(foo="bar\nbla"), [b"foo: bar\n", b"\tbla\n"])
 
88
        self.assertReadStanza(rio.Stanza(foo="bar\nbla"), 
 
89
                ["foo: bar\n", "\tbla\n"])
99
90
 
100
91
    def test_repeated(self):
101
92
        s = rio.Stanza()
102
93
        s.add("foo", "bar")
103
94
        s.add("foo", "foo")
104
 
        self.assertReadStanza(s, [b"foo: bar\n", b"foo: foo\n"])
 
95
        self.assertReadStanza(s, ["foo: bar\n", "foo: foo\n"])
105
96
 
106
97
    def test_invalid_early_colon(self):
107
 
        self.assertReadStanzaRaises(ValueError, [b"f:oo: bar\n"])
 
98
        self.assertReadStanzaRaises(ValueError, ["f:oo: bar\n"])
108
99
 
109
100
    def test_invalid_tag(self):
110
 
        self.assertReadStanzaRaises(ValueError, [b"f%oo: bar\n"])
 
101
        self.assertReadStanzaRaises(ValueError, ["f%oo: bar\n"])
111
102
 
112
103
    def test_continuation_too_early(self):
113
 
        self.assertReadStanzaRaises(ValueError, [b"\tbar\n"])
 
104
        self.assertReadStanzaRaises(ValueError, ["\tbar\n"])
114
105
 
115
106
    def test_large(self):
116
 
        value = b"bla" * 9000
 
107
        value = "bla" * 9000
117
108
        self.assertReadStanza(rio.Stanza(foo=value),
118
 
                              [b"foo: %s\n" % value])
 
109
            ["foo: %s\n" % value])
119
110
 
120
111
    def test_non_ascii_char(self):
121
112
        self.assertReadStanza(rio.Stanza(foo=u"n\xe5me"),
122
 
                              [u"foo: n\xe5me\n".encode("utf-8")])
 
113
            [u"foo: n\xe5me\n".encode("utf-8")])
123
114
 
124
115
 
125
116
class TestReadUnicodeStanza(tests.TestCase):
126
117
 
127
 
    module = None  # Filled in by test parameterization
 
118
    module = None # Filled in by test parameterization
128
119
 
129
120
    def assertReadStanza(self, result, line_iter):
130
121
        s = self.module._read_stanza_unicode(line_iter)
131
 
        self.assertEqual(result, s)
 
122
        self.assertEquals(result, s)
132
123
        if s is not None:
133
124
            for tag, value in s.iter_pairs():
134
125
                self.assertIsInstance(tag, str)
135
 
                self.assertIsInstance(value, text_type)
 
126
                self.assertIsInstance(value, unicode)
136
127
 
137
128
    def assertReadStanzaRaises(self, exception, line_iter):
138
129
        self.assertRaises(exception, self.module._read_stanza_unicode,
151
142
        self.assertReadStanza(rio.Stanza(foo="bar"), [u"foo: bar\n", u""])
152
143
 
153
144
    def test_multi_line(self):
154
 
        self.assertReadStanza(rio.Stanza(foo="bar\nbla"),
155
 
                              [u"foo: bar\n", u"\tbla\n"])
 
145
        self.assertReadStanza(rio.Stanza(foo="bar\nbla"), 
 
146
                [u"foo: bar\n", u"\tbla\n"])
156
147
 
157
148
    def test_repeated(self):
158
149
        s = rio.Stanza()
172
163
    def test_large(self):
173
164
        value = u"bla" * 9000
174
165
        self.assertReadStanza(rio.Stanza(foo=value),
175
 
                              [u"foo: %s\n" % value])
 
166
            [u"foo: %s\n" % value])
176
167
 
177
168
    def test_non_ascii_char(self):
178
169
        self.assertReadStanza(rio.Stanza(foo=u"n\xe5me"), [u"foo: n\xe5me\n"])