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

Bitbucket commits-noreply at bitbucket.org
Wed Oct 24 22:23:12 CEST 2012


2 new commits in py:


https://bitbucket.org/hpk42/py/changeset/c35f6441aa26/
changeset:   c35f6441aa26
user:        hpk42
date:        2012-10-24 22:16:49
summary:     simplify and improve unicode handling in terminalwriter
affected #:  5 files

diff -r 4316a23e130da1edcd9fd7c422030fd6e237a486 -r c35f6441aa262da4e136812f94b55339016c9b2f py/__init__.py
--- a/py/__init__.py
+++ b/py/__init__.py
@@ -8,7 +8,7 @@
 
 (c) Holger Krekel and others, 2004-2010
 """
-__version__ = '1.4.11.dev1'
+__version__ = '1.4.11.dev2'
 
 from py import _apipkg
 


diff -r 4316a23e130da1edcd9fd7c422030fd6e237a486 -r c35f6441aa262da4e136812f94b55339016c9b2f py/_io/terminalwriter.py
--- a/py/_io/terminalwriter.py
+++ b/py/_io/terminalwriter.py
@@ -7,6 +7,7 @@
 
 import sys, os
 import py
+py3k = sys.version_info[0] >= 3
 
 win32_and_ctypes = False
 if sys.platform == "win32":
@@ -160,26 +161,19 @@
 
         self.line(line, **kw)
 
-    def write(self, s, **kw):
-        if s:
-            if not isinstance(self._file, WriteFile) and not getattr(self._file, "encoding", None):
-                s = self._getbytestring(s)
-                if self.hasmarkup and kw:
-                    s = self.markup(s, **kw)
-            self._file.write(s)
+    def write(self, msg, **kw):
+        if msg:
+            if self.hasmarkup and kw:
+                markupmsg = self.markup(msg, **kw)
+            else:
+                markupmsg = msg
+            try:
+                self._file.write(markupmsg)
+            except UnicodeEncodeError:
+                msg = msg.encode("unicode-escape").decode("ascii")
+                self._file.write(msg)
             self._file.flush()
 
-    def _getbytestring(self, s):
-        # XXX review this and the whole logic
-        if sys.version_info[0] < 3 and isinstance(s, unicode):
-            return s.encode(self.encoding or "utf8", "replace")
-        elif not isinstance(s, str):
-            try:
-                return str(s)
-            except UnicodeEncodeError:
-                return "<print-error '%s' object>" % type(s).__name__
-        return s
-
     def line(self, s='', **kw):
         self.write(s, **kw)
         self._checkfill(s)


diff -r 4316a23e130da1edcd9fd7c422030fd6e237a486 -r c35f6441aa262da4e136812f94b55339016c9b2f setup.py
--- a/setup.py
+++ b/setup.py
@@ -12,7 +12,7 @@
         name='py',
         description='library with cross-python path, ini-parsing, io, code, log facilities',
         long_description = open('README.txt').read(),
-        version='1.4.11.dev1',
+        version='1.4.11.dev2',
         url='http://pylib.org',
         license='MIT license',
         platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],


diff -r 4316a23e130da1edcd9fd7c422030fd6e237a486 -r c35f6441aa262da4e136812f94b55339016c9b2f testing/io_/test_terminalwriter.py
--- a/testing/io_/test_terminalwriter.py
+++ b/testing/io_/test_terminalwriter.py
@@ -1,4 +1,3 @@
-# coding=utf8
 
 import py
 import os, sys
@@ -78,24 +77,18 @@
         tw.line(msg)
         assert l[0].strip() == msg.encode(encoding)
 
- at pytest.mark.parametrize("encoding", [None, "ascii"])
-def test_unicode_on_file_with_no_encoding(tmpdir, monkeypatch, encoding):
-    try:
-        bytes
-    except NameError:
-        bytes = str
-    msg = py.builtin._totext('öl', "utf8")
+ at pytest.mark.parametrize("encoding", ["ascii"])
+def test_unicode_on_file_with_ascii_encoding(tmpdir, monkeypatch, encoding):
+    msg = py.builtin._totext('hell\xf6', "latin1")
     #pytest.raises(UnicodeEncodeError, lambda: bytes(msg))
-    f = py.std.codecs.open(str(tmpdir.join("x")), "w", encoding, errors="replace")
-    tw = py.io.TerminalWriter(f, encoding=None)
-    tw.encoding = None
+    f = py.std.codecs.open(str(tmpdir.join("x")), "w", encoding)
+    tw = py.io.TerminalWriter(f)
     tw.line(msg)
     f.close()
     s = tmpdir.join("x").open("rb").read().strip()
-    if encoding is None:
-        assert s == msg.encode(f.encoding or "utf-8")
-    else:
-        assert s.decode(encoding) == '?l'
+    assert encoding == "ascii"
+    assert s == msg.encode("unicode-escape")
+
 
 class TestTerminalWriter:
     def pytest_generate_tests(self, metafunc):


diff -r 4316a23e130da1edcd9fd7c422030fd6e237a486 -r c35f6441aa262da4e136812f94b55339016c9b2f tox.ini
--- a/tox.ini
+++ b/tox.ini
@@ -1,5 +1,5 @@
 [tox]
-envlist=py26,py27,py31,py32,py27-xdist,py25
+envlist=py26,py27,py31,py32,py33,py27-xdist,py25
 #indexserver=
 #    default=http://pypi.testrun.org
 



https://bitbucket.org/hpk42/py/changeset/7e29aba2f979/
changeset:   7e29aba2f979
user:        hpk42
date:        2012-10-24 22:16:50
summary:     remove test_sources and helper whose tests are now covered by tox
affected #:  3 files

diff -r c35f6441aa262da4e136812f94b55339016c9b2f -r 7e29aba2f9791e942b87149cbb0c4812a7bf2f0a CHANGELOG
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -2,11 +2,10 @@
 ==================================================
 
 - fix an internal test to not use class-denoted pytest_funcarg__
-- fix a link to bug tracker
+- fix a doc link to bug tracker
 - try to make terminal.write() printing more robust against
   unicodeencode/decode problems, amend according test
 
-
 Changes between 1.4.9 and 1.4.10
 ==================================================
 


diff -r c35f6441aa262da4e136812f94b55339016c9b2f -r 7e29aba2f9791e942b87149cbb0c4812a7bf2f0a testing/root/check_compile.py
--- a/testing/root/check_compile.py
+++ /dev/null
@@ -1,13 +0,0 @@
-import sys
-
-def main(fn):
-    print("Testing %s" % (fn,))
-    fp = open(fn, "rb")
-    try:
-        source = fp.read()
-    finally:
-        fp.close()
-    compile(source, fn, "exec")
-
-if __name__ == "__main__":
-    main(sys.argv[1])


diff -r c35f6441aa262da4e136812f94b55339016c9b2f -r 7e29aba2f9791e942b87149cbb0c4812a7bf2f0a testing/root/test_sources.py
--- a/testing/root/test_sources.py
+++ /dev/null
@@ -1,19 +0,0 @@
-import os
-import py
-
-
-this_dir = py.path.local(__file__).dirpath()
-_compile_checker = this_dir.join("check_compile.py")
-_py_root = this_dir.join("..")
-del this_dir
-
- at py.test.mark.multi(pyversion=("2.4", "2.5", "2.6", "3.1"))
-def test_syntax(pyversion):
-    executable = py.path.local.sysfind("python" + pyversion)
-    if executable is None:
-        py.test.skip("no python%s found" % (pyversion,))
-    for path, dirs, filenames in os.walk(str(_py_root)):
-        for fn in filenames:
-            if fn.endswith(".py"):
-                full = os.path.join(path, fn)
-                executable.sysexec(_compile_checker, full)

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