Show More
@@ -1,3 +1,4 b'' | |||||
|
1 | # coding: utf-8 | |||
1 | """test the IPython Kernel""" |
|
2 | """test the IPython Kernel""" | |
2 |
|
3 | |||
3 | #------------------------------------------------------------------------------- |
|
4 | #------------------------------------------------------------------------------- | |
@@ -11,6 +12,8 b'' | |||||
11 | # Imports |
|
12 | # Imports | |
12 | #------------------------------------------------------------------------------- |
|
13 | #------------------------------------------------------------------------------- | |
13 |
|
14 | |||
|
15 | import io | |||
|
16 | import os.path | |||
14 | import sys |
|
17 | import sys | |
15 |
|
18 | |||
16 | import nose.tools as nt |
|
19 | import nose.tools as nt | |
@@ -18,8 +21,10 b' import nose.tools as nt' | |||||
18 | from IPython.testing import decorators as dec, tools as tt |
|
21 | from IPython.testing import decorators as dec, tools as tt | |
19 | from IPython.utils import py3compat |
|
22 | from IPython.utils import py3compat | |
20 | from IPython.utils.path import locate_profile |
|
23 | from IPython.utils.path import locate_profile | |
|
24 | from IPython.utils.tempdir import TemporaryDirectory | |||
21 |
|
25 | |||
22 |
from .utils import new_kernel, kernel, TIMEOUT, assemble_output, execute, |
|
26 | from .utils import (new_kernel, kernel, TIMEOUT, assemble_output, execute, | |
|
27 | flush_channels, wait_for_idle) | |||
23 |
|
28 | |||
24 | #------------------------------------------------------------------------------- |
|
29 | #------------------------------------------------------------------------------- | |
25 | # Tests |
|
30 | # Tests | |
@@ -180,6 +185,22 b' def test_eval_input():' | |||||
180 | nt.assert_equal(stdout, "2\n") |
|
185 | nt.assert_equal(stdout, "2\n") | |
181 |
|
186 | |||
182 |
|
187 | |||
|
188 | def test_save_history(): | |||
|
189 | # Saving history from the kernel with %hist -f was failing because of | |||
|
190 | # unicode problems on Python 2. | |||
|
191 | with kernel() as kc, TemporaryDirectory() as td: | |||
|
192 | file = os.path.join(td, 'hist.out') | |||
|
193 | execute(u'a=1', kc=kc) | |||
|
194 | wait_for_idle(kc) | |||
|
195 | execute(u'b=u"abcþ"', kc=kc) | |||
|
196 | wait_for_idle(kc) | |||
|
197 | _, reply = execute("%hist -f " + file, kc=kc) | |||
|
198 | nt.assert_equal(reply['status'], 'ok') | |||
|
199 | with io.open(file, encoding='utf-8') as f: | |||
|
200 | content = f.read() | |||
|
201 | nt.assert_in(u'a=1', content) | |||
|
202 | nt.assert_in(u'b=u"abcþ"', content) | |||
|
203 | ||||
183 | def test_help_output(): |
|
204 | def test_help_output(): | |
184 | """ipython kernel --help-all works""" |
|
205 | """ipython kernel --help-all works""" | |
185 | tt.help_all_output_test('kernel') |
|
206 | tt.help_all_output_test('kernel') |
@@ -170,5 +170,10 b' def assemble_output(iopub):' | |||||
170 | pass |
|
170 | pass | |
171 | return stdout, stderr |
|
171 | return stdout, stderr | |
172 |
|
172 | |||
173 |
|
173 | def wait_for_idle(kc): | ||
174 |
|
174 | while True: | ||
|
175 | msg = kc.iopub_channel.get_msg(block=True, timeout=1) | |||
|
176 | msg_type = msg['msg_type'] | |||
|
177 | content = msg['content'] | |||
|
178 | if msg_type == 'status' and content['execution_state'] == 'idle': | |||
|
179 | break |
@@ -341,7 +341,7 b' class Kernel(Configurable):' | |||||
341 |
|
341 | |||
342 | try: |
|
342 | try: | |
343 | content = parent[u'content'] |
|
343 | content = parent[u'content'] | |
344 | code = content[u'code'] |
|
344 | code = py3compat.cast_unicode_py2(content[u'code']) | |
345 | silent = content[u'silent'] |
|
345 | silent = content[u'silent'] | |
346 | store_history = content.get(u'store_history', not silent) |
|
346 | store_history = content.get(u'store_history', not silent) | |
347 | except: |
|
347 | except: |
@@ -83,6 +83,7 b' if sys.version_info[0] >= 3:' | |||||
83 | str_to_bytes = encode |
|
83 | str_to_bytes = encode | |
84 | bytes_to_str = decode |
|
84 | bytes_to_str = decode | |
85 | cast_bytes_py2 = no_code |
|
85 | cast_bytes_py2 = no_code | |
|
86 | cast_unicode_py2 = no_code | |||
86 |
|
87 | |||
87 | string_types = (str,) |
|
88 | string_types = (str,) | |
88 | unicode_type = str |
|
89 | unicode_type = str | |
@@ -139,6 +140,7 b' else:' | |||||
139 | str_to_bytes = no_code |
|
140 | str_to_bytes = no_code | |
140 | bytes_to_str = no_code |
|
141 | bytes_to_str = no_code | |
141 | cast_bytes_py2 = cast_bytes |
|
142 | cast_bytes_py2 = cast_bytes | |
|
143 | cast_unicode_py2 = cast_unicode | |||
142 |
|
144 | |||
143 | string_types = (str, unicode) |
|
145 | string_types = (str, unicode) | |
144 | unicode_type = unicode |
|
146 | unicode_type = unicode |
General Comments 0
You need to be logged in to leave comments.
Login now