blob: 0362d2624ff7859b0f51ab21e534bcf29fd2c970 [file] [log] [blame]
Barry Warsaw04f357c2002-07-23 19:04:11 +00001from test import test_support
2import unittest
Marc-André Lemburga37171d2001-06-19 20:09:28 +00003import codecs
4import StringIO
5
6class 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 Drake2e2be372001-09-20 21:33:42 +000026
27def test_main():
28 test_support.run_unittest(UTF16Test)
29
30
31if __name__ == "__main__":
32 test_main()