-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Allow IOErrors when attempting to retrieve default client encoding. #21531
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
Changes from 4 commits
6c2987d
c31b914
510f4b1
1afda5f
b37cb75
0b1ca1d
bf26adb
77a95d2
2598595
59e0993
8b51b34
984da5c
4790e10
6156825
fb1dc2e
7cedfdc
35c0b3b
49ee7b5
40b3588
5e3c8af
f485223
ab67024
81547da
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import pytest | ||
from functools import partial | ||
|
||
from pandas.io.formats.console import detect_console_encoding, locale | ||
|
||
|
||
def mock_raises_exception(error=Exception): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is this for? |
||
raise error | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current LINT error is because you are missing a blank line here |
||
def test_detect_console_encoding_stdout(monkeypatch): | ||
monkeypatch.setattr('sys.stdin.encoding', '') | ||
monkeypatch.setattr('sys.stdout.encoding', 'foo') | ||
assert detect_console_encoding() == 'foo' | ||
|
||
|
||
def test_detect_console_encoding_stdin(monkeypatch): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you add some comments on what is being tested here. |
||
monkeypatch.setattr('sys.stdout.encoding', '') | ||
monkeypatch.setattr('sys.stdin.encoding', 'foo') | ||
assert detect_console_encoding() == 'foo' | ||
|
||
|
||
@pytest.mark.parametrize('error', [AttributeError, IOError]) | ||
def test_detect_console_encoding_stdout_error_uses_locale(monkeypatch, error): | ||
monkeypatch.setattr('locale.getpreferredencoding', lambda: 'foo') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can put this in the context manager, no? |
||
monkeypatch.setattr('sys.stdout', partial(mock_raises_exception, error)) | ||
assert detect_console_encoding() == 'foo' | ||
|
||
|
||
def test_detect_console_encoding_sys_default_encoding(monkeypatch): | ||
monkeypatch.setattr('locale.getpreferredencoding', mock_raises_exception) | ||
monkeypatch.setattr('sys.stdout', mock_raises_exception) | ||
monkeypatch.setattr('sys.getdefaultencoding', lambda: 'sysDefaultEncoding') | ||
assert detect_console_encoding() == 'sysDefaultEncoding' |
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.
double backticks on IOError