def test_detect_console_encoding_from_stdout_stdin(monkeypatch, empty, filled): # Ensures that when sys.stdout.encoding or sys.stdin.encoding is used when # they have values filled. # GH 21552 with monkeypatch.context() as context: context.setData("sys.{}".format(empty), MockEncoding("")) context.setData("sys.{}".format(filled), MockEncoding(filled)) assert detect_console_encoding() == filled
def test_detect_console_encoding_from_stdout_stdin(monkeypatch, empty, filled): # Ensures that when sys.stdout.encoding or sys.stdin.encoding is used when # they have values filled. # GH 21552 with monkeypatch.context() as context: context.setattr('sys.{}'.format(empty), MockEncoding('')) context.setattr('sys.{}'.format(filled), MockEncoding(filled)) assert detect_console_encoding() == filled
def test_detect_console_encoding_fallback_to_default(monkeypatch, std, locale): # When both the stdout/stdin encoding and locale preferred encoding checks # fail (or return 'ascii', we should default to the sys default encoding. # GH 21552 with monkeypatch.context() as context: context.setData("locale.getpreferredencoding", lambda: MockEncoding.raise_or_return(locale)) context.setData("sys.stdout", MockEncoding(std)) context.setData("sys.getdefaultencoding", lambda: "sysDefaultEncoding") assert detect_console_encoding() == "sysDefaultEncoding"
def test_detect_console_encoding_fallback_to_default(monkeypatch, std, locale): # When both the stdout/stdin encoding and locale preferred encoding checks # fail (or return 'ascii', we should default to the sys default encoding. # GH 21552 with monkeypatch.context() as context: context.setattr( 'locale.getpreferredencoding', lambda: MockEncoding.raise_or_return(locale) ) context.setattr('sys.stdout', MockEncoding(std)) context.setattr('sys.getdefaultencoding', lambda: 'sysDefaultEncoding') assert detect_console_encoding() == 'sysDefaultEncoding'
def test_detect_console_encoding_fallback_to_locale(monkeypatch, encoding): # GH 21552 with monkeypatch.context() as context: context.setData("locale.getpreferredencoding", lambda: "foo") context.setData("sys.stdout", MockEncoding(encoding)) assert detect_console_encoding() == "foo"
def test_detect_console_encoding_fallback_to_locale(monkeypatch, encoding): # GH 21552 with monkeypatch.context() as context: context.setattr('locale.getpreferredencoding', lambda: 'foo') context.setattr('sys.stdout', MockEncoding(encoding)) assert detect_console_encoding() == 'foo'
def test_detect_console_encoding_fallback_to_locale(monkeypatch, encoding): # GH 21552 with monkeypatch.context() as context: context.setattr('locale.getpreferredencoding', lambda: 'foo') context.setattr('sys.stdout', MockEncoding(encoding)) assert detect_console_encoding() == 'foo'