Skip to content

Commit

Permalink
Merge a9ebf91 into 73872d9
Browse files Browse the repository at this point in the history
  • Loading branch information
MinchinWeb committed Apr 16, 2016
2 parents 73872d9 + a9ebf91 commit f3469d9
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 1 deletion.
7 changes: 7 additions & 0 deletions green/output.py
Expand Up @@ -6,6 +6,7 @@
import platform
import sys
import termstyle
from unidecode import unidecode

global debug_level
debug_level = 0
Expand Down Expand Up @@ -141,6 +142,7 @@ class GreenStream(object):
"""

indent_spaces = 2
_ascii_only_output = False # default to printing output in unicode

def __init__(self, stream, override_appveyor=False, disable_windows=False):
self.stream = stream
Expand All @@ -153,6 +155,8 @@ def __init__(self, stream, override_appveyor=False, disable_windows=False):
or ((on_windows and not on_appveyor)
and not disable_windows)): # pragma: no cover
self.stream = wrap_stream(self.stream, None, None, None, True)
# set output is ascii-only
self._ascii_only_output = True
self.closed = False


Expand All @@ -167,6 +171,9 @@ def writeln(self, text=''):
def write(self, text):
if type(text) == bytes:
text = text.decode('utf-8')
# Compensate for windows' anti-social unicode behavior
if self._ascii_only_output:
text = unidecode(text)
self.stream.write(text)


Expand Down
17 changes: 17 additions & 0 deletions green/test/test_output.py
Expand Up @@ -8,6 +8,11 @@
except:
from StringIO import StringIO

try:
from unittest.mock import patch
except:
from mock import patch

from green.output import Colors, GreenStream, debug
import green.output

Expand Down Expand Up @@ -141,3 +146,15 @@ def testDisableWindowsFalse(self):
import colorama
self.assertTrue(issubclass(type(gs.stream),
colorama.ansitowin32.StreamWrapper))


@patch('green.output.unidecode')
def testUnidecodeAppveyor(self, mock_unidecode):
"""
When I'm on Appveyor, I run text through Unidecode
"""
mock_unidecode.return_value = 'something'
s = StringIO()
gs = GreenStream(s, override_appveyor=True)
gs.write('something')
self.assertTrue(mock_unidecode.called)
1 change: 0 additions & 1 deletion green/test/test_windows.py
Expand Up @@ -22,4 +22,3 @@ def test_colorOutput(self):
gs = GreenStream(sys.stdout, override_appveyor=True)
self.assertTrue(issubclass(type(gs.stream),
colorama.ansitowin32.StreamWrapper))

1 change: 1 addition & 0 deletions requirements.txt
@@ -1,3 +1,4 @@
colorama
mock
python-termstyle
unidecode
1 change: 1 addition & 0 deletions setup.py
Expand Up @@ -12,6 +12,7 @@
dependencies = [
'colorama',
'python-termstyle',
'unidecode',
]
if sys.version_info[0] == 2:
dependencies.append('mock')
Expand Down

0 comments on commit f3469d9

Please sign in to comment.