annotate Lib/test/test_codecs.py @ 25838:8540887bcec6 2.2

Backport of 2.183: Fix memory leak in add_subclass() found by NealN with valgrind.
author Guido van Rossum <guido@python.org>
date Fri, 18 Oct 2002 13:42:21 +0000
parents e3184e46303b
children aa0d2d51fbde
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18163
f926eb1f5770 Test by Martin v. Loewis for the new UTF-16 codec handling of BOM
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
1 import test_support,unittest
f926eb1f5770 Test by Martin v. Loewis for the new UTF-16 codec handling of BOM
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
2 import codecs
f926eb1f5770 Test by Martin v. Loewis for the new UTF-16 codec handling of BOM
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
3 import StringIO
f926eb1f5770 Test by Martin v. Loewis for the new UTF-16 codec handling of BOM
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
4
f926eb1f5770 Test by Martin v. Loewis for the new UTF-16 codec handling of BOM
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
5 class UTF16Test(unittest.TestCase):
f926eb1f5770 Test by Martin v. Loewis for the new UTF-16 codec handling of BOM
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
6
f926eb1f5770 Test by Martin v. Loewis for the new UTF-16 codec handling of BOM
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
7 spamle = '\xff\xfes\x00p\x00a\x00m\x00s\x00p\x00a\x00m\x00'
f926eb1f5770 Test by Martin v. Loewis for the new UTF-16 codec handling of BOM
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
8 spambe = '\xfe\xff\x00s\x00p\x00a\x00m\x00s\x00p\x00a\x00m'
f926eb1f5770 Test by Martin v. Loewis for the new UTF-16 codec handling of BOM
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
9
f926eb1f5770 Test by Martin v. Loewis for the new UTF-16 codec handling of BOM
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
10 def test_only_one_bom(self):
f926eb1f5770 Test by Martin v. Loewis for the new UTF-16 codec handling of BOM
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
11 _,_,reader,writer = codecs.lookup("utf-16")
f926eb1f5770 Test by Martin v. Loewis for the new UTF-16 codec handling of BOM
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
12 # encode some stream
f926eb1f5770 Test by Martin v. Loewis for the new UTF-16 codec handling of BOM
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
13 s = StringIO.StringIO()
f926eb1f5770 Test by Martin v. Loewis for the new UTF-16 codec handling of BOM
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
14 f = writer(s)
f926eb1f5770 Test by Martin v. Loewis for the new UTF-16 codec handling of BOM
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
15 f.write(u"spam")
f926eb1f5770 Test by Martin v. Loewis for the new UTF-16 codec handling of BOM
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
16 f.write(u"spam")
f926eb1f5770 Test by Martin v. Loewis for the new UTF-16 codec handling of BOM
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
17 d = s.getvalue()
f926eb1f5770 Test by Martin v. Loewis for the new UTF-16 codec handling of BOM
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
18 # check whether there is exactly one BOM in it
f926eb1f5770 Test by Martin v. Loewis for the new UTF-16 codec handling of BOM
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
19 self.assert_(d == self.spamle or d == self.spambe)
f926eb1f5770 Test by Martin v. Loewis for the new UTF-16 codec handling of BOM
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
20 # try to read it back
f926eb1f5770 Test by Martin v. Loewis for the new UTF-16 codec handling of BOM
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
21 s = StringIO.StringIO(d)
f926eb1f5770 Test by Martin v. Loewis for the new UTF-16 codec handling of BOM
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
22 f = reader(s)
f926eb1f5770 Test by Martin v. Loewis for the new UTF-16 codec handling of BOM
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
23 self.assertEquals(f.read(), u"spamspam")
f926eb1f5770 Test by Martin v. Loewis for the new UTF-16 codec handling of BOM
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
24
20013
e3184e46303b Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents: 18163
diff changeset
25
e3184e46303b Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents: 18163
diff changeset
26 def test_main():
e3184e46303b Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents: 18163
diff changeset
27 test_support.run_unittest(UTF16Test)
e3184e46303b Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents: 18163
diff changeset
28
e3184e46303b Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents: 18163
diff changeset
29
e3184e46303b Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents: 18163
diff changeset
30 if __name__ == "__main__":
e3184e46303b Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents: 18163
diff changeset
31 test_main()