[pypy-svn] pypy default: Fun failing test, baesd on one from CPython.
alex_gaynor
commits-noreply at bitbucket.org
Mon Jan 31 05:48:45 CET 2011
Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch:
Changeset: r41486:1af0530d24ab
Date: 2011-01-30 23:48 -0500
http://bitbucket.org/pypy/pypy/changeset/1af0530d24ab/
Log: Fun failing test, baesd on one from CPython.
diff --git a/pypy/module/_io/test/test_io.py b/pypy/module/_io/test/test_io.py
--- a/pypy/module/_io/test/test_io.py
+++ b/pypy/module/_io/test/test_io.py
@@ -297,3 +297,43 @@
with _io.open(self.tmpfile, "rb") as f:
res = f.read()
assert res == "aaaxxx".encode(charset)
+
+ def test_custom_decoder(self):
+ import codecs
+ import _io
+
+ class WeirdDecoder(codecs.IncrementalDecoder):
+ def decode(self, input, final=False):
+ return u".".join(input)
+
+ def weird_decoder(name):
+ if name == "test_decoder":
+ latin1 = codecs.lookup("latin-1")
+ return codecs.CodecInfo(
+ name = "test_decoder",
+ encode =latin1.encode,
+ decode = None,
+ incrementalencoder = None,
+ streamreader = None,
+ streamwriter = None,
+ incrementaldecoder=WeirdDecoder
+ )
+
+ codecs.register(weird_decoder)
+
+ with _io.open(self.tmpfile, "wb") as f:
+ f.write("abcd")
+
+ with _io.open(self.tmpfile, encoding="test_decoder") as f:
+ decoded = f.read()
+
+ assert decoded == "a.b.c.d"
+ with _io.open(self.tmpfile, encoding="test_decoder") as f:
+ res = f.read(1)
+ assert res == "a"
+ cookie = f.tell()
+ res = f.read(1)
+ assert res == "."
+ f.seek(cookie)
+ res = f.read()
+ assert res == ".b.c.d"
More information about the Pypy-commit
mailing list