[py-svn] commit/py: 2 new changesets

Bitbucket commits-noreply at bitbucket.org
Sat Apr 7 14:24:50 CEST 2012


2 new commits in py:


https://bitbucket.org/hpk42/py/changeset/fda157fda4c4/
changeset:   fda157fda4c4
user:        RonnyPfannschmidt
date:        2012-04-05 16:10:01
summary:     support passing error handler names to py.builtin._totext
affected #:  2 files

diff -r 2c042feb5b3b1acebc7ceb565cac0a3b72d2a732 -r fda157fda4c4d9f9fa3754805cc141b999efe7f0 py/_builtin.py
--- a/py/_builtin.py
+++ b/py/_builtin.py
@@ -113,9 +113,9 @@
 
     # some backward compatibility helpers
     _basestring = str
-    def _totext(obj, encoding=None):
+    def _totext(obj, encoding=None, errors=None):
         if isinstance(obj, bytes):
-            obj = obj.decode(encoding)
+            obj = obj.decode(encoding, errors)
         elif not isinstance(obj, str):
             obj = str(obj)
         return obj


diff -r 2c042feb5b3b1acebc7ceb565cac0a3b72d2a732 -r fda157fda4c4d9f9fa3754805cc141b999efe7f0 testing/root/test_builtin.py
--- a/testing/root/test_builtin.py
+++ b/testing/root/test_builtin.py
@@ -133,6 +133,15 @@
 def test_totext():
     py.builtin._totext("hello", "UTF-8")
 
+def test_totext_badutf8():
+    # this was in printouts within the pytest testsuite
+    # totext would fail
+    if sys.version_info >= (3,):
+        errors = 'surrogateescape'
+    else: # old python has crappy error handlers
+        errors = 'replace'
+    py.builtin._totext("\xa6", "UTF-8", errors)
+
 def test_reraise():
     from py.builtin import _reraise
     try:



https://bitbucket.org/hpk42/py/changeset/c909e2794057/
changeset:   c909e2794057
user:        RonnyPfannschmidt
date:        2012-04-05 16:53:42
summary:     use the replace handler for stray bytes on stdout/err capture
affected #:  2 files

diff -r fda157fda4c4d9f9fa3754805cc141b999efe7f0 -r c909e27940574490119488ac0e94daebaa37e1bc py/_io/capture.py
--- a/py/_io/capture.py
+++ b/py/_io/capture.py
@@ -12,7 +12,7 @@
     class TextIO(StringIO):
         def write(self, data):
             if not isinstance(data, unicode):
-                data = unicode(data, getattr(self, '_encoding', 'UTF-8'))
+                data = unicode(data, getattr(self, '_encoding', 'UTF-8'), 'replace')
             StringIO.write(self, data)
 else:
     TextIO = StringIO
@@ -260,7 +260,7 @@
                 res = f.read()
                 enc = getattr(f, 'encoding', None)
                 if enc:
-                    res = py.builtin._totext(res, enc)
+                    res = py.builtin._totext(res, enc, 'replace')
                 f.truncate(0)
                 f.seek(0)
             l.append(res)


diff -r fda157fda4c4d9f9fa3754805cc141b999efe7f0 -r c909e27940574490119488ac0e94daebaa37e1bc testing/io_/test_capture.py
--- a/testing/io_/test_capture.py
+++ b/testing/io_/test_capture.py
@@ -219,6 +219,15 @@
         out, err = cap.readouterr()
         assert out == py.builtin._totext("hx\xc4\x85\xc4\x87\n", "utf8")
 
+    @py.test.mark.skipif('sys.version_info >= (3,)',
+                      reason='text output different for bytes on python3')
+    def test_capturing_readouterr_decode_error_handling(self):
+        cap = self.getcapture()
+        # triggered a internal error in pytest
+        print('\xa6')
+        out, err = cap.readouterr()
+        assert out == py.builtin._totext('\ufffd\n', 'unicode-escape')
+
     def test_capturing_mixed(self):
         cap = self.getcapture(mixed=True)
         sys.stdout.write("hello ")

Repository URL: https://bitbucket.org/hpk42/py/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.



More information about the pytest-commit mailing list