home *** CD-ROM | disk | FTP | other *** search
/ Komputer for Alle 2004 #2 / K-CD-2-2004.ISO / OpenOffice Sv / f_0397 / python-core-2.2.2 / lib / test / test_codecs.py < prev    next >
Encoding:
Python Source  |  2003-07-18  |  822 b   |  32 lines

  1. import test_support,unittest
  2. import codecs
  3. import StringIO
  4.  
  5. class UTF16Test(unittest.TestCase):
  6.  
  7.     spamle = '\xff\xfes\x00p\x00a\x00m\x00s\x00p\x00a\x00m\x00'
  8.     spambe = '\xfe\xff\x00s\x00p\x00a\x00m\x00s\x00p\x00a\x00m'
  9.  
  10.     def test_only_one_bom(self):
  11.         _,_,reader,writer = codecs.lookup("utf-16")
  12.         # encode some stream
  13.         s = StringIO.StringIO()
  14.         f = writer(s)
  15.         f.write(u"spam")
  16.         f.write(u"spam")
  17.         d = s.getvalue()
  18.         # check whether there is exactly one BOM in it
  19.         self.assert_(d == self.spamle or d == self.spambe)
  20.         # try to read it back
  21.         s = StringIO.StringIO(d)
  22.         f = reader(s)
  23.         self.assertEquals(f.read(), u"spamspam")
  24.  
  25.  
  26. def test_main():
  27.     test_support.run_unittest(UTF16Test)
  28.  
  29.  
  30. if __name__ == "__main__":
  31.     test_main()
  32.