~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_rio.py

  • Committer: John Arbash Meinel
  • Date: 2007-03-02 01:27:53 UTC
  • mto: (2255.7.86 dirstate)
  • mto: This revision was merged to the branch mainline in revision 2322.
  • Revision ID: john@arbash-meinel.com-20070302012753-5jwb15csi4j2mi4w
Fix a small bug when we have a symlink that does not need to be re-read.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
24
24
 
25
25
import cStringIO
26
26
import os
27
 
import re
28
27
import sys
29
28
from tempfile import TemporaryFile
30
29
 
54
53
        # these aren't enforced at construction time
55
54
        ## self.assertRaises(ValueError,
56
55
        ##        Stanza, complex=42 + 3j)
57
 
        ## self.assertRaises(ValueError,
 
56
        ## self.assertRaises(ValueError, 
58
57
        ##        Stanza, several=range(10))
59
58
 
60
59
    def test_empty_value(self):
123
122
    def test_repeated_field(self):
124
123
        """Repeated field in rio"""
125
124
        s = Stanza()
126
 
        for k, v in [('a', '10'), ('b', '20'), ('a', '100'), ('b', '200'),
 
125
        for k, v in [('a', '10'), ('b', '20'), ('a', '100'), ('b', '200'), 
127
126
                     ('a', '1000'), ('b', '2000')]:
128
127
            s.add(k, v)
129
128
        s2 = read_stanza(s.to_lines())
141
140
    def test_blank_line(self):
142
141
        s = Stanza(none='', one='\n', two='\n\n')
143
142
        self.assertEqualDiff(s.to_string(), """\
144
 
none:\x20
145
 
one:\x20
 
143
none: 
 
144
one: 
146
145
\t
147
 
two:\x20
 
146
two: 
148
147
\t
149
148
\t
150
149
""")
154
153
    def test_whitespace_value(self):
155
154
        s = Stanza(space=' ', tabs='\t\t\t', combo='\n\t\t\n')
156
155
        self.assertEqualDiff(s.to_string(), """\
157
 
combo:\x20
 
156
combo: 
158
157
\t\t\t
159
158
\t
160
 
space:\x20\x20
 
159
space:  
161
160
tabs: \t\t\t
162
161
""")
163
162
        s2 = read_stanza(s.to_lines())
166
165
 
167
166
    def test_quoted(self):
168
167
        """rio quoted string cases"""
169
 
        s = Stanza(q1='"hello"',
170
 
                   q2=' "for',
 
168
        s = Stanza(q1='"hello"', 
 
169
                   q2=' "for', 
171
170
                   q3='\n\n"for"\n',
172
171
                   q4='for\n"\nfor',
173
172
                   q5='\n',
174
 
                   q6='"',
 
173
                   q6='"', 
175
174
                   q7='""',
176
175
                   q8='\\',
177
176
                   q9='\\"\\"',
187
186
        s = read_stanza([])
188
187
        self.assertEqual(s, None)
189
188
        self.assertTrue(s is None)
190
 
 
 
189
        
191
190
    def test_read_iter(self):
192
191
        """Read several stanzas from file"""
193
192
        tmpf = TemporaryFile()
204
203
        reader = read_stanzas(tmpf)
205
204
        read_iter = iter(reader)
206
205
        stuff = list(reader)
207
 
        self.assertEqual(stuff,
 
206
        self.assertEqual(stuff, 
208
207
                [ Stanza(version_header='1'),
209
208
                  Stanza(name="foo", val='123'),
210
209
                  Stanza(name="bar", val='129319'), ])
259
258
        tmpf.write('''\
260
259
s: "one"
261
260
 
262
 
s:\x20
 
261
s: 
263
262
\t"one"
264
263
\t
265
264
 
269
268
 
270
269
s: """
271
270
 
272
 
s:\x20
 
271
s: 
273
272
\t
274
273
 
275
274
s: \\
276
275
 
277
 
s:\x20
 
276
s: 
278
277
\t\\
279
278
\t\\\\
280
279
\t
354
353
        self.assertEqual(u'foo: %s\n' % uni_data, child_text)
355
354
        new_child = rio.read_stanza_unicode(child_text.splitlines(True))
356
355
        self.assertEqual(uni_data, new_child.get('foo'))
357
 
 
358
 
    def mail_munge(self, lines, dos_nl=True):
359
 
        new_lines = []
360
 
        for line in lines:
361
 
            line = re.sub(' *\n', '\n', line)
362
 
            if dos_nl:
363
 
                line = re.sub('([^\r])\n', '\\1\r\n', line)
364
 
            new_lines.append(line)
365
 
        return new_lines
366
 
 
367
 
    def test_patch_rio(self):
368
 
        stanza = Stanza(data='#\n\r\\r ', space=' ' * 255, hash='#' * 255)
369
 
        lines = rio.to_patch_lines(stanza)
370
 
        for line in lines:
371
 
            self.assertContainsRe(line, '^# ')
372
 
            self.assertTrue(72 >= len(line))
373
 
        for line in rio.to_patch_lines(stanza, max_width=12):
374
 
            self.assertTrue(12 >= len(line))
375
 
        new_stanza = rio.read_patch_stanza(self.mail_munge(lines,
376
 
                                                           dos_nl=False))
377
 
        lines = self.mail_munge(lines)
378
 
        new_stanza = rio.read_patch_stanza(lines)
379
 
        self.assertEqual('#\n\r\\r ', new_stanza.get('data'))
380
 
        self.assertEqual(' '* 255, new_stanza.get('space'))
381
 
        self.assertEqual('#'* 255, new_stanza.get('hash'))
382
 
 
383
 
    def test_patch_rio_linebreaks(self):
384
 
        stanza = Stanza(breaktest='linebreak -/'*30)
385
 
        self.assertContainsRe(rio.to_patch_lines(stanza, 71)[0],
386
 
                              'linebreak\\\\\n')
387
 
        stanza = Stanza(breaktest='linebreak-/'*30)
388
 
        self.assertContainsRe(rio.to_patch_lines(stanza, 70)[0],
389
 
                              'linebreak-\\\\\n')
390
 
        stanza = Stanza(breaktest='linebreak/'*30)
391
 
        self.assertContainsRe(rio.to_patch_lines(stanza, 70)[0],
392
 
                              'linebreak\\\\\n')