~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_rio.py

  • Committer: Robert Collins
  • Date: 2007-04-19 02:27:44 UTC
  • mto: This revision was merged to the branch mainline in revision 2426.
  • Revision ID: robertc@robertcollins.net-20070419022744-pfdqz42kp1wizh43
``make docs`` now creates a man page at ``man1/bzr.1`` fixing bug 107388.
(Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007, 2009, 2010 Canonical Ltd
 
1
# Copyright (C) 2005, 2006 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
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
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
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
"""Tests for rio serialization
18
18
 
54
54
        # these aren't enforced at construction time
55
55
        ## self.assertRaises(ValueError,
56
56
        ##        Stanza, complex=42 + 3j)
57
 
        ## self.assertRaises(ValueError,
 
57
        ## self.assertRaises(ValueError, 
58
58
        ##        Stanza, several=range(10))
59
59
 
60
60
    def test_empty_value(self):
123
123
    def test_repeated_field(self):
124
124
        """Repeated field in rio"""
125
125
        s = Stanza()
126
 
        for k, v in [('a', '10'), ('b', '20'), ('a', '100'), ('b', '200'),
 
126
        for k, v in [('a', '10'), ('b', '20'), ('a', '100'), ('b', '200'), 
127
127
                     ('a', '1000'), ('b', '2000')]:
128
128
            s.add(k, v)
129
129
        s2 = read_stanza(s.to_lines())
141
141
    def test_blank_line(self):
142
142
        s = Stanza(none='', one='\n', two='\n\n')
143
143
        self.assertEqualDiff(s.to_string(), """\
144
 
none:\x20
145
 
one:\x20
 
144
none: 
 
145
one: 
146
146
\t
147
 
two:\x20
 
147
two: 
148
148
\t
149
149
\t
150
150
""")
154
154
    def test_whitespace_value(self):
155
155
        s = Stanza(space=' ', tabs='\t\t\t', combo='\n\t\t\n')
156
156
        self.assertEqualDiff(s.to_string(), """\
157
 
combo:\x20
 
157
combo: 
158
158
\t\t\t
159
159
\t
160
 
space:\x20\x20
 
160
space:  
161
161
tabs: \t\t\t
162
162
""")
163
163
        s2 = read_stanza(s.to_lines())
166
166
 
167
167
    def test_quoted(self):
168
168
        """rio quoted string cases"""
169
 
        s = Stanza(q1='"hello"',
170
 
                   q2=' "for',
 
169
        s = Stanza(q1='"hello"', 
 
170
                   q2=' "for', 
171
171
                   q3='\n\n"for"\n',
172
172
                   q4='for\n"\nfor',
173
173
                   q5='\n',
174
 
                   q6='"',
 
174
                   q6='"', 
175
175
                   q7='""',
176
176
                   q8='\\',
177
177
                   q9='\\"\\"',
187
187
        s = read_stanza([])
188
188
        self.assertEqual(s, None)
189
189
        self.assertTrue(s is None)
190
 
 
191
 
    def test_read_nul_byte(self):
192
 
        """File consisting of a nul byte causes an error."""
193
 
        self.assertRaises(ValueError, read_stanza, ['\0'])
194
 
 
195
 
    def test_read_nul_bytes(self):
196
 
        """File consisting of many nul bytes causes an error."""
197
 
        self.assertRaises(ValueError, read_stanza, ['\0' * 100])
198
 
 
 
190
        
199
191
    def test_read_iter(self):
200
192
        """Read several stanzas from file"""
201
193
        tmpf = TemporaryFile()
212
204
        reader = read_stanzas(tmpf)
213
205
        read_iter = iter(reader)
214
206
        stuff = list(reader)
215
 
        self.assertEqual(stuff,
 
207
        self.assertEqual(stuff, 
216
208
                [ Stanza(version_header='1'),
217
209
                  Stanza(name="foo", val='123'),
218
210
                  Stanza(name="bar", val='129319'), ])
267
259
        tmpf.write('''\
268
260
s: "one"
269
261
 
270
 
s:\x20
 
262
s: 
271
263
\t"one"
272
264
\t
273
265
 
277
269
 
278
270
s: """
279
271
 
280
 
s:\x20
 
272
s: 
281
273
\t
282
274
 
283
275
s: \\
284
276
 
285
 
s:\x20
 
277
s: 
286
278
\t\\
287
279
\t\\\\
288
280
\t