Show More
@@ -74,7 +74,9 b' def remove_comments(src):' | |||||
74 |
|
74 | |||
75 |
|
75 | |||
76 | def get_input_encoding(): |
|
76 | def get_input_encoding(): | |
77 |
"""Return the default standard input encoding. |
|
77 | """Return the default standard input encoding. | |
|
78 | ||||
|
79 | If sys.stdin has no encoding, 'ascii' is returned.""" | |||
78 | # There are strange environments for which sys.stdin.encoding is None. We |
|
80 | # There are strange environments for which sys.stdin.encoding is None. We | |
79 | # ensure that a valid encoding is returned. |
|
81 | # ensure that a valid encoding is returned. | |
80 | encoding = getattr(sys.stdin, 'encoding', None) |
|
82 | encoding = getattr(sys.stdin, 'encoding', None) |
@@ -12,6 +12,7 b'' | |||||
12 | #----------------------------------------------------------------------------- |
|
12 | #----------------------------------------------------------------------------- | |
13 | # stdlib |
|
13 | # stdlib | |
14 | import unittest |
|
14 | import unittest | |
|
15 | import sys | |||
15 |
|
16 | |||
16 | # Third party |
|
17 | # Third party | |
17 | import nose.tools as nt |
|
18 | import nose.tools as nt | |
@@ -108,6 +109,23 b' def test_get_input_encoding():' | |||||
108 | nt.assert_equal('test'.encode(encoding), 'test') |
|
109 | nt.assert_equal('test'.encode(encoding), 'test') | |
109 |
|
110 | |||
110 |
|
111 | |||
|
112 | class NoInputEncodingTestCase(unittest.TestCase): | |||
|
113 | def setUp(self): | |||
|
114 | self.old_stdin = sys.stdin | |||
|
115 | class X: pass | |||
|
116 | fake_stdin = X() | |||
|
117 | sys.stdin = fake_stdin | |||
|
118 | ||||
|
119 | def test(self): | |||
|
120 | # Verify that if sys.stdin has no 'encoding' attribute we do the right | |||
|
121 | # thing | |||
|
122 | enc = isp.get_input_encoding() | |||
|
123 | self.assertEqual(enc, 'ascii') | |||
|
124 | ||||
|
125 | def tearDown(self): | |||
|
126 | sys.stdin = self.old_stdin | |||
|
127 | ||||
|
128 | ||||
111 | class InputSplitterTestCase(unittest.TestCase): |
|
129 | class InputSplitterTestCase(unittest.TestCase): | |
112 | def setUp(self): |
|
130 | def setUp(self): | |
113 | self.isp = isp.InputSplitter() |
|
131 | self.isp = isp.InputSplitter() |
General Comments 0
You need to be logged in to leave comments.
Login now