Barry Warsaw | 04f357c | 2002-07-23 19:04:11 +0000 | [diff] [blame] | 1 | from test import test_support |
| 2 | import unittest |
Marc-André Lemburg | a37171d | 2001-06-19 20:09:28 +0000 | [diff] [blame] | 3 | import codecs |
| 4 | import StringIO |
| 5 | |
| 6 | class UTF16Test(unittest.TestCase): |
| 7 | |
| 8 | spamle = '\xff\xfes\x00p\x00a\x00m\x00s\x00p\x00a\x00m\x00' |
| 9 | spambe = '\xfe\xff\x00s\x00p\x00a\x00m\x00s\x00p\x00a\x00m' |
| 10 | |
| 11 | def test_only_one_bom(self): |
| 12 | _,_,reader,writer = codecs.lookup("utf-16") |
| 13 | # encode some stream |
| 14 | s = StringIO.StringIO() |
| 15 | f = writer(s) |
| 16 | f.write(u"spam") |
| 17 | f.write(u"spam") |
| 18 | d = s.getvalue() |
| 19 | # check whether there is exactly one BOM in it |
| 20 | self.assert_(d == self.spamle or d == self.spambe) |
| 21 | # try to read it back |
| 22 | s = StringIO.StringIO(d) |
| 23 | f = reader(s) |
| 24 | self.assertEquals(f.read(), u"spamspam") |
| 25 | |
Fred Drake | 2e2be37 | 2001-09-20 21:33:42 +0000 | [diff] [blame] | 26 | |
| 27 | def test_main(): |
| 28 | test_support.run_unittest(UTF16Test) |
| 29 | |
| 30 | |
| 31 | if __name__ == "__main__": |
| 32 | test_main() |