/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_transport_implementations.py

  • Committer: Andrew Bennetts
  • Date: 2007-03-29 08:46:23 UTC
  • mto: (2018.18.6 hpss-faster-copy)
  • mto: This revision was merged to the branch mainline in revision 2435.
  • Revision ID: andrew.bennetts@canonical.com-20070329084623-ruqx0po8q3lxw0b7
Be strict about unicode passed to transport.put_{bytes,file} and SmartClient.call_with_body_bytes, fixing part of TestLockableFiles_RemoteLockDir.test_read_write.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
import os
24
24
from cStringIO import StringIO
 
25
from StringIO import StringIO as pyStringIO
25
26
import stat
26
27
import sys
27
28
 
378
379
                              dir_mode=0777, create_parent_dir=True)
379
380
        self.assertTransportMode(t, 'dir777', 0777)
380
381
 
 
382
    def test_put_bytes_unicode(self):
 
383
        # Expect put_bytes to raise AssertionError or UnicodeEncodeError if
 
384
        # given unicode "bytes".  UnicodeEncodeError doesn't really make sense
 
385
        # (we don't want to encode unicode here at all, callers should be
 
386
        # strictly passing bytes to put_bytes), but we allow it for backwards
 
387
        # compatibility.  At some point we should use a specific exception.
 
388
        t = self.get_transport()
 
389
        if t.is_readonly():
 
390
            return
 
391
        unicode_string = u'\u1234'
 
392
        self.assertRaises(
 
393
            (AssertionError, UnicodeEncodeError),
 
394
            t.put_bytes, 'foo', unicode_string)
 
395
 
 
396
    def test_put_file_unicode(self):
 
397
        # Like put_bytes, except with a StringIO.StringIO of a unicode string.
 
398
        # This situation can happen (and has) if code is careless about the type
 
399
        # of "string" they initialise/write to a StringIO with.  We cannot use
 
400
        # cStringIO, because it never returns unicode from read.
 
401
        # Like put_bytes, UnicodeEncodeError isn't quite the right exception to
 
402
        # raise, but we raise it for hysterical raisins.
 
403
        t = self.get_transport()
 
404
        if t.is_readonly():
 
405
            return
 
406
        unicode_file = pyStringIO(u'\u1234')
 
407
        self.assertRaises(UnicodeEncodeError, t.put_file, 'foo', unicode_file)
 
408
 
381
409
    def test_put_multi(self):
382
410
        t = self.get_transport()
383
411