[Python-modules-commits] [python-click-log] 01/05: Import python-click-log_0.1.8.orig.tar.gz

Ondřej Nový onovy at moszumanska.debian.org
Wed Dec 28 21:50:44 UTC 2016


This is an automated email from the git hooks/post-receive script.

onovy pushed a commit to branch master
in repository python-click-log.

commit f5d575527b24fe51899b9cfb40602ab4c7e62bfa
Author: Ondřej Nový <onovy at debian.org>
Date:   Wed Dec 28 22:47:07 2016 +0100

    Import python-click-log_0.1.8.orig.tar.gz
---
 click_log/__init__.py |  2 +-
 click_log/core.py     | 19 +++++++++++++++++--
 tests/test_basic.py   | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 tox.ini               |  2 +-
 4 files changed, 69 insertions(+), 4 deletions(-)

diff --git a/click_log/__init__.py b/click_log/__init__.py
index 51ac26a..fd96638 100644
--- a/click_log/__init__.py
+++ b/click_log/__init__.py
@@ -3,7 +3,7 @@
 
 import click
 
-__version__ = '0.1.4'
+__version__ = '0.1.8'
 
 
 if not hasattr(click, 'get_current_context'):
diff --git a/click_log/core.py b/click_log/core.py
index 12efa6b..5098296 100644
--- a/click_log/core.py
+++ b/click_log/core.py
@@ -1,5 +1,7 @@
 # -*- coding: utf-8 -*-
 
+import sys
+
 import functools
 import logging
 
@@ -10,6 +12,13 @@ _ctx = click.get_current_context
 LOGGER_KEY = __name__ + '.logger'
 DEFAULT_LEVEL = logging.INFO
 
+PY2 = sys.version_info[0] == 2
+
+if PY2:
+    text_type = unicode  # noqa
+else:
+    text_type = str
+
 
 def _meta():
     return _ctx().meta.setdefault(LOGGER_KEY, {})
@@ -30,8 +39,14 @@ class ColorFormatter(logging.Formatter):
             if level in self.colors:
                 prefix = click.style('{}: '.format(level),
                                      **self.colors[level])
-                record.msg = '\n'.join(prefix + x
-                                       for x in str(record.msg).splitlines())
+
+                msg = record.msg
+                if not PY2 and isinstance(msg, bytes):
+                    msg = msg.decode(sys.getfilesystemencoding(),
+                                     'replace')
+                elif not isinstance(msg, (text_type, bytes)):
+                    msg = str(msg)
+                record.msg = '\n'.join(prefix + x for x in msg.splitlines())
 
         return logging.Formatter.format(self, record)
 
diff --git a/tests/test_basic.py b/tests/test_basic.py
index d82c533..0628ffd 100644
--- a/tests/test_basic.py
+++ b/tests/test_basic.py
@@ -1,3 +1,5 @@
+# -*- coding: utf-8 -*-
+
 import logging
 
 import click
@@ -26,3 +28,51 @@ def test_basic(runner):
     result = runner.invoke(cli, catch_exceptions=False)
     assert not result.exception
     assert result.output == 'hey\nerror: damn\n'
+
+
+def test_multilines(runner):
+    @click.command()
+    @click_log.init()
+    def cli():
+        test_logger.warning("""
+            Lorem ipsum dolor sit amet,
+            consectetur adipiscing elit,
+            sed do eiusmod tempor incididunt""")
+
+    result = runner.invoke(cli, catch_exceptions=False)
+    assert not result.exception
+    assert result.output == (
+        'warning: \n'
+        'warning:             Lorem ipsum dolor sit amet,\n'
+        'warning:             consectetur adipiscing elit,\n'
+        'warning:             sed do eiusmod tempor incididunt\n')
+
+
+def test_unicode(runner):
+    @click.command()
+    @click_log.init()
+    def cli():
+        test_logger.error(u"""
+            ❤️ 💔 💌 💕 💞 💓 💗 💖 💘
+            💝 💟 💜 💛 💚 💙""")
+
+    result = runner.invoke(cli, catch_exceptions=False)
+    assert not result.exception
+    assert result.output == (
+        'error: \n'
+        u'error:             ❤️ 💔 💌 💕 💞 💓 💗 💖 💘\n'
+        u'error:             💝 💟 💜 💛 💚 💙\n')
+
+
+def test_weird_types_log(runner):
+    @click.command()
+    @click_log.init()
+    def cli():
+        test_logger.error(42)
+        test_logger.error('42')
+        test_logger.error(b'42')
+        test_logger.error(u'42')
+
+    result = runner.invoke(cli, catch_exceptions=False)
+    assert not result.exception
+    assert result.output == 'error: 42\n' * 4
diff --git a/tox.ini b/tox.ini
index 131e0fe..9c2d2ac 100644
--- a/tox.ini
+++ b/tox.ini
@@ -3,4 +3,4 @@ passenv = LANG
 deps =
     pytest
     git+https://github.com/mitsuhiko/click
-commands = py.test
+commands = py.test []

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-click-log.git



More information about the Python-modules-commits mailing list