From 0ece560dd3fa8c7e1f9eda3359de4a8992dc3d38 2010-08-08 00:40:58 From: Fernando Perez Date: 2010-08-08 00:40:58 Subject: [PATCH] Add test for missing input encoding. Back to 100% coverage. --- diff --git a/IPython/core/inputsplitter.py b/IPython/core/inputsplitter.py index a14bf9a..daef25a 100644 --- a/IPython/core/inputsplitter.py +++ b/IPython/core/inputsplitter.py @@ -74,7 +74,9 @@ def remove_comments(src): def get_input_encoding(): - """Return the default standard input encoding.""" + """Return the default standard input encoding. + + If sys.stdin has no encoding, 'ascii' is returned.""" # There are strange environments for which sys.stdin.encoding is None. We # ensure that a valid encoding is returned. encoding = getattr(sys.stdin, 'encoding', None) diff --git a/IPython/core/tests/test_inputsplitter.py b/IPython/core/tests/test_inputsplitter.py index 5910d1f..d312c1f 100644 --- a/IPython/core/tests/test_inputsplitter.py +++ b/IPython/core/tests/test_inputsplitter.py @@ -12,6 +12,7 @@ #----------------------------------------------------------------------------- # stdlib import unittest +import sys # Third party import nose.tools as nt @@ -108,6 +109,23 @@ def test_get_input_encoding(): nt.assert_equal('test'.encode(encoding), 'test') +class NoInputEncodingTestCase(unittest.TestCase): + def setUp(self): + self.old_stdin = sys.stdin + class X: pass + fake_stdin = X() + sys.stdin = fake_stdin + + def test(self): + # Verify that if sys.stdin has no 'encoding' attribute we do the right + # thing + enc = isp.get_input_encoding() + self.assertEqual(enc, 'ascii') + + def tearDown(self): + sys.stdin = self.old_stdin + + class InputSplitterTestCase(unittest.TestCase): def setUp(self): self.isp = isp.InputSplitter()