[Python-checkins] CVS: python/dist/src/Lib/test test_codecs.py,NONE,1.1
M.-A. Lemburg
lemburg@users.sourceforge.net
Tue, 19 Jun 2001 13:09:30 -0700
Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv28211/Lib/test
Added Files:
test_codecs.py
Log Message:
Test by Martin v. Loewis for the new UTF-16 codec handling of BOM
marks.
--- NEW FILE: test_codecs.py ---
import test_support,unittest
import codecs
import StringIO
class UTF16Test(unittest.TestCase):
spamle = '\xff\xfes\x00p\x00a\x00m\x00s\x00p\x00a\x00m\x00'
spambe = '\xfe\xff\x00s\x00p\x00a\x00m\x00s\x00p\x00a\x00m'
def test_only_one_bom(self):
_,_,reader,writer = codecs.lookup("utf-16")
# encode some stream
s = StringIO.StringIO()
f = writer(s)
f.write(u"spam")
f.write(u"spam")
d = s.getvalue()
# check whether there is exactly one BOM in it
self.assert_(d == self.spamle or d == self.spambe)
# try to read it back
s = StringIO.StringIO(d)
f = reader(s)
self.assertEquals(f.read(), u"spamspam")
test_support.run_unittest(UTF16Test)