-
-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Un-unicode output for Windows CMD #120
Conversation
@@ -23,3 +23,6 @@ def test_colorOutput(self): | |||
self.assertTrue(issubclass(type(gs.stream), | |||
colorama.ansitowin32.StreamWrapper)) | |||
|
|||
def test_unicode_override(self): | |||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking pretty good, except for this poor test here. ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a poor, sad test :(
I couldn't figure out how to get green
to run a unittest
testcase, and then validate what gets printed out. The actual testcase is nearly trivial...
class UnicodeTest(unittest.TestCase):
def test1(self):
print('\u03BB') # lambda
self.assertTrue(True)
Suggestions on how to go about this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The true test is to spawn subprocess of green running that test method, and check the output.
https://github.com/wikimedia/pywikibot-core/blob/master/tests/pwb_tests.py#L71
There all sorts of gotchas, especially when doing this on Windows, and only Python versions, resulting a mess like
https://github.com/wikimedia/pywikibot-core/blob/master/tests/utils.py#L771
However I suspect you'll only need to set PYTHONIOENCODING
to utf-8 for the subprocess
All of these "on_appveyor" conditions look like handling only the simple case of Appveyor, and dont really test using green on Windows because there is special logic for Appveyor only. e.g. I expect that This is just a general comment, as I realise that this changeset isnt introducing "on_appveyor", but it is making it more "normal" by exposing it as an attribute. |
# Ironically, AppVeyor doesn't support windows win32 system calls for | ||
# colors, but it WILL interpret posix ansi escape codes! | ||
on_windows = platform.system() == 'Windows' | ||
on_appveyor = os.environ.get('APPVEYOR', False) | ||
self.on_windows = platform.system() == 'Windows' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this shouldnt be an instance variable. it should be a package level constant.
Created a unit test for MinchinWeb's pull request
@jayvdb I've reworked the 'flags' inside the module a little to try and make things more explicit. The test failed on Travis because The test failed on Appvoyor on a test where colorama is supposed to strip ANSI codes. But the issue is something gets fed a In any case, the tests do pass on my local machine. |
@@ -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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay. I have been just absolutely swamped.
I suggest just changing line 176 to read:
text = unidecode(unicode(text))
That may be work and we could be done with this and merge it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, wait. Python 3 doesn't have the unicode() function anymore.
Since it's a Python 2-specific fix, I suppose we should make that condition:
if self._ascii_only_output:
if platform.python_version_tuple()[0] == '2': # pragma: no cover
text = unicode(text)
text = unidecode(text)
Explicitely convert to Unicode for Python 2
@CleanCut: I've made the changes you suggested |
Included in the 2.4.2 release. Which was just released. |
Fixes #119