Show More
@@ -1,29 +1,25 b'' | |||
|
1 | 1 | """Test NotebookApp""" |
|
2 | 2 | |
|
3 | 3 | #----------------------------------------------------------------------------- |
|
4 | 4 | # Copyright (C) 2013 The IPython Development Team |
|
5 | 5 | # |
|
6 | 6 | # Distributed under the terms of the BSD License. The full license is in |
|
7 | 7 | # the file COPYING, distributed as part of this software. |
|
8 | 8 | #----------------------------------------------------------------------------- |
|
9 | 9 | |
|
10 | 10 | #----------------------------------------------------------------------------- |
|
11 | 11 | # Imports |
|
12 | 12 | #----------------------------------------------------------------------------- |
|
13 | 13 | |
|
14 | 14 | import nose.tools as nt |
|
15 | 15 | |
|
16 | 16 | import IPython.testing.tools as tt |
|
17 | 17 | |
|
18 | 18 | #----------------------------------------------------------------------------- |
|
19 | 19 | # Test functions |
|
20 | 20 | #----------------------------------------------------------------------------- |
|
21 | 21 | |
|
22 | 22 | def test_help_output(): |
|
23 | """ipython notebook -h works""" | |
|
24 | tt.help_output_test('notebook') | |
|
25 | ||
|
26 | def test_help_all_output(): | |
|
27 | 23 | """ipython notebook --help-all works""" |
|
28 | 24 | tt.help_all_output_test('notebook') |
|
29 | 25 |
@@ -1,252 +1,256 b'' | |||
|
1 | 1 | """test the IPython Kernel""" |
|
2 | 2 | |
|
3 | 3 | #------------------------------------------------------------------------------- |
|
4 | 4 | # Copyright (C) 2013 The IPython Development Team |
|
5 | 5 | # |
|
6 | 6 | # Distributed under the terms of the BSD License. The full license is in |
|
7 | 7 | # the file COPYING, distributed as part of this software. |
|
8 | 8 | #------------------------------------------------------------------------------- |
|
9 | 9 | |
|
10 | 10 | #------------------------------------------------------------------------------- |
|
11 | 11 | # Imports |
|
12 | 12 | #------------------------------------------------------------------------------- |
|
13 | 13 | |
|
14 | 14 | import os |
|
15 | 15 | import shutil |
|
16 | 16 | import sys |
|
17 | 17 | import tempfile |
|
18 | 18 | |
|
19 | 19 | from contextlib import contextmanager |
|
20 | 20 | from subprocess import PIPE |
|
21 | 21 | |
|
22 | 22 | import nose.tools as nt |
|
23 | 23 | |
|
24 | 24 | from IPython.kernel import KernelManager |
|
25 | 25 | from IPython.kernel.tests.test_message_spec import execute, flush_channels |
|
26 | from IPython.testing import decorators as dec | |
|
26 | from IPython.testing import decorators as dec, tools as tt | |
|
27 | 27 | from IPython.utils import path, py3compat |
|
28 | 28 | |
|
29 | 29 | #------------------------------------------------------------------------------- |
|
30 | 30 | # Tests |
|
31 | 31 | #------------------------------------------------------------------------------- |
|
32 | 32 | IPYTHONDIR = None |
|
33 | 33 | save_env = None |
|
34 | 34 | save_get_ipython_dir = None |
|
35 | 35 | |
|
36 | 36 | STARTUP_TIMEOUT = 60 |
|
37 | 37 | TIMEOUT = 15 |
|
38 | 38 | |
|
39 | 39 | def setup(): |
|
40 | 40 | """setup temporary IPYTHONDIR for tests""" |
|
41 | 41 | global IPYTHONDIR |
|
42 | 42 | global save_env |
|
43 | 43 | global save_get_ipython_dir |
|
44 | 44 | |
|
45 | 45 | IPYTHONDIR = tempfile.mkdtemp() |
|
46 | 46 | |
|
47 | 47 | save_env = os.environ.copy() |
|
48 | 48 | os.environ["IPYTHONDIR"] = IPYTHONDIR |
|
49 | 49 | |
|
50 | 50 | save_get_ipython_dir = path.get_ipython_dir |
|
51 | 51 | path.get_ipython_dir = lambda : IPYTHONDIR |
|
52 | 52 | |
|
53 | 53 | |
|
54 | 54 | def teardown(): |
|
55 | 55 | path.get_ipython_dir = save_get_ipython_dir |
|
56 | 56 | os.environ = save_env |
|
57 | 57 | |
|
58 | 58 | try: |
|
59 | 59 | shutil.rmtree(IPYTHONDIR) |
|
60 | 60 | except (OSError, IOError): |
|
61 | 61 | # no such file |
|
62 | 62 | pass |
|
63 | 63 | |
|
64 | 64 | |
|
65 | 65 | @contextmanager |
|
66 | 66 | def new_kernel(): |
|
67 | 67 | """start a kernel in a subprocess, and wait for it to be ready |
|
68 | 68 | |
|
69 | 69 | Returns |
|
70 | 70 | ------- |
|
71 | 71 | kernel_manager: connected KernelManager instance |
|
72 | 72 | """ |
|
73 | 73 | KM = KernelManager() |
|
74 | 74 | |
|
75 | 75 | KM.start_kernel(stdout=PIPE, stderr=PIPE) |
|
76 | 76 | KC = KM.client() |
|
77 | 77 | KC.start_channels() |
|
78 | 78 | |
|
79 | 79 | # wait for kernel to be ready |
|
80 | 80 | KC.shell_channel.execute("import sys") |
|
81 | 81 | KC.shell_channel.get_msg(block=True, timeout=STARTUP_TIMEOUT) |
|
82 | 82 | flush_channels(KC) |
|
83 | 83 | try: |
|
84 | 84 | yield KC |
|
85 | 85 | finally: |
|
86 | 86 | KC.stop_channels() |
|
87 | 87 | KM.shutdown_kernel() |
|
88 | 88 | |
|
89 | 89 | |
|
90 | 90 | def assemble_output(iopub): |
|
91 | 91 | """assemble stdout/err from an execution""" |
|
92 | 92 | stdout = '' |
|
93 | 93 | stderr = '' |
|
94 | 94 | while True: |
|
95 | 95 | msg = iopub.get_msg(block=True, timeout=1) |
|
96 | 96 | msg_type = msg['msg_type'] |
|
97 | 97 | content = msg['content'] |
|
98 | 98 | if msg_type == 'status' and content['execution_state'] == 'idle': |
|
99 | 99 | # idle message signals end of output |
|
100 | 100 | break |
|
101 | 101 | elif msg['msg_type'] == 'stream': |
|
102 | 102 | if content['name'] == 'stdout': |
|
103 | 103 | stdout = stdout + content['data'] |
|
104 | 104 | elif content['name'] == 'stderr': |
|
105 | 105 | stderr = stderr + content['data'] |
|
106 | 106 | else: |
|
107 | 107 | raise KeyError("bad stream: %r" % content['name']) |
|
108 | 108 | else: |
|
109 | 109 | # other output, ignored |
|
110 | 110 | pass |
|
111 | 111 | return stdout, stderr |
|
112 | 112 | |
|
113 | 113 | |
|
114 | 114 | def _check_mp_mode(kc, expected=False, stream="stdout"): |
|
115 | 115 | execute(kc=kc, code="import sys") |
|
116 | 116 | flush_channels(kc) |
|
117 | 117 | msg_id, content = execute(kc=kc, code="print (sys.%s._check_mp_mode())" % stream) |
|
118 | 118 | stdout, stderr = assemble_output(kc.iopub_channel) |
|
119 | 119 | nt.assert_equal(eval(stdout.strip()), expected) |
|
120 | 120 | |
|
121 | 121 | |
|
122 | 122 | # printing tests |
|
123 | 123 | |
|
124 | 124 | def test_simple_print(): |
|
125 | 125 | """simple print statement in kernel""" |
|
126 | 126 | with new_kernel() as kc: |
|
127 | 127 | iopub = kc.iopub_channel |
|
128 | 128 | msg_id, content = execute(kc=kc, code="print ('hi')") |
|
129 | 129 | stdout, stderr = assemble_output(iopub) |
|
130 | 130 | nt.assert_equal(stdout, 'hi\n') |
|
131 | 131 | nt.assert_equal(stderr, '') |
|
132 | 132 | _check_mp_mode(kc, expected=False) |
|
133 | 133 | |
|
134 | 134 | |
|
135 | 135 | @dec.knownfailureif(sys.platform == 'win32', "subprocess prints fail on Windows") |
|
136 | 136 | def test_subprocess_print(): |
|
137 | 137 | """printing from forked mp.Process""" |
|
138 | 138 | with new_kernel() as kc: |
|
139 | 139 | iopub = kc.iopub_channel |
|
140 | 140 | |
|
141 | 141 | _check_mp_mode(kc, expected=False) |
|
142 | 142 | flush_channels(kc) |
|
143 | 143 | np = 5 |
|
144 | 144 | code = '\n'.join([ |
|
145 | 145 | "from __future__ import print_function", |
|
146 | 146 | "import multiprocessing as mp", |
|
147 | 147 | "pool = [mp.Process(target=print, args=('hello', i,)) for i in range(%i)]" % np, |
|
148 | 148 | "for p in pool: p.start()", |
|
149 | 149 | "for p in pool: p.join()" |
|
150 | 150 | ]) |
|
151 | 151 | |
|
152 | 152 | expected = '\n'.join([ |
|
153 | 153 | "hello %s" % i for i in range(np) |
|
154 | 154 | ]) + '\n' |
|
155 | 155 | |
|
156 | 156 | msg_id, content = execute(kc=kc, code=code) |
|
157 | 157 | stdout, stderr = assemble_output(iopub) |
|
158 | 158 | nt.assert_equal(stdout.count("hello"), np, stdout) |
|
159 | 159 | for n in range(np): |
|
160 | 160 | nt.assert_equal(stdout.count(str(n)), 1, stdout) |
|
161 | 161 | nt.assert_equal(stderr, '') |
|
162 | 162 | _check_mp_mode(kc, expected=False) |
|
163 | 163 | _check_mp_mode(kc, expected=False, stream="stderr") |
|
164 | 164 | |
|
165 | 165 | |
|
166 | 166 | def test_subprocess_noprint(): |
|
167 | 167 | """mp.Process without print doesn't trigger iostream mp_mode""" |
|
168 | 168 | with new_kernel() as kc: |
|
169 | 169 | iopub = kc.iopub_channel |
|
170 | 170 | |
|
171 | 171 | np = 5 |
|
172 | 172 | code = '\n'.join([ |
|
173 | 173 | "import multiprocessing as mp", |
|
174 | 174 | "pool = [mp.Process(target=range, args=(i,)) for i in range(%i)]" % np, |
|
175 | 175 | "for p in pool: p.start()", |
|
176 | 176 | "for p in pool: p.join()" |
|
177 | 177 | ]) |
|
178 | 178 | |
|
179 | 179 | msg_id, content = execute(kc=kc, code=code) |
|
180 | 180 | stdout, stderr = assemble_output(iopub) |
|
181 | 181 | nt.assert_equal(stdout, '') |
|
182 | 182 | nt.assert_equal(stderr, '') |
|
183 | 183 | |
|
184 | 184 | _check_mp_mode(kc, expected=False) |
|
185 | 185 | _check_mp_mode(kc, expected=False, stream="stderr") |
|
186 | 186 | |
|
187 | 187 | |
|
188 | 188 | @dec.knownfailureif(sys.platform == 'win32', "subprocess prints fail on Windows") |
|
189 | 189 | def test_subprocess_error(): |
|
190 | 190 | """error in mp.Process doesn't crash""" |
|
191 | 191 | with new_kernel() as kc: |
|
192 | 192 | iopub = kc.iopub_channel |
|
193 | 193 | |
|
194 | 194 | code = '\n'.join([ |
|
195 | 195 | "import multiprocessing as mp", |
|
196 | 196 | "p = mp.Process(target=int, args=('hi',))", |
|
197 | 197 | "p.start()", |
|
198 | 198 | "p.join()", |
|
199 | 199 | ]) |
|
200 | 200 | |
|
201 | 201 | msg_id, content = execute(kc=kc, code=code) |
|
202 | 202 | stdout, stderr = assemble_output(iopub) |
|
203 | 203 | nt.assert_equal(stdout, '') |
|
204 | 204 | nt.assert_true("ValueError" in stderr, stderr) |
|
205 | 205 | |
|
206 | 206 | _check_mp_mode(kc, expected=False) |
|
207 | 207 | _check_mp_mode(kc, expected=False, stream="stderr") |
|
208 | 208 | |
|
209 | ||
|
210 | 209 | # raw_input tests |
|
211 | 210 | |
|
212 | 211 | def test_raw_input(): |
|
213 | 212 | """test [raw_]input""" |
|
214 | 213 | with new_kernel() as kc: |
|
215 | 214 | iopub = kc.iopub_channel |
|
216 | 215 | |
|
217 | 216 | input_f = "input" if py3compat.PY3 else "raw_input" |
|
218 | 217 | theprompt = "prompt> " |
|
219 | 218 | code = 'print({input_f}("{theprompt}"))'.format(**locals()) |
|
220 | 219 | msg_id = kc.execute(code, allow_stdin=True) |
|
221 | 220 | msg = kc.get_stdin_msg(block=True, timeout=TIMEOUT) |
|
222 | 221 | nt.assert_equal(msg['header']['msg_type'], u'input_request') |
|
223 | 222 | content = msg['content'] |
|
224 | 223 | nt.assert_equal(content['prompt'], theprompt) |
|
225 | 224 | text = "some text" |
|
226 | 225 | kc.input(text) |
|
227 | 226 | reply = kc.get_shell_msg(block=True, timeout=TIMEOUT) |
|
228 | 227 | nt.assert_equal(reply['content']['status'], 'ok') |
|
229 | 228 | stdout, stderr = assemble_output(iopub) |
|
230 | 229 | nt.assert_equal(stdout, text + "\n") |
|
231 | 230 | |
|
232 | 231 | |
|
233 | 232 | @dec.skipif(py3compat.PY3) |
|
234 | 233 | def test_eval_input(): |
|
235 | 234 | """test input() on Python 2""" |
|
236 | 235 | with new_kernel() as kc: |
|
237 | 236 | iopub = kc.iopub_channel |
|
238 | 237 | |
|
239 | 238 | input_f = "input" if py3compat.PY3 else "raw_input" |
|
240 | 239 | theprompt = "prompt> " |
|
241 | 240 | code = 'print(input("{theprompt}"))'.format(**locals()) |
|
242 | 241 | msg_id = kc.execute(code, allow_stdin=True) |
|
243 | 242 | msg = kc.get_stdin_msg(block=True, timeout=TIMEOUT) |
|
244 | 243 | nt.assert_equal(msg['header']['msg_type'], u'input_request') |
|
245 | 244 | content = msg['content'] |
|
246 | 245 | nt.assert_equal(content['prompt'], theprompt) |
|
247 | 246 | kc.input("1+1") |
|
248 | 247 | reply = kc.get_shell_msg(block=True, timeout=TIMEOUT) |
|
249 | 248 | nt.assert_equal(reply['content']['status'], 'ok') |
|
250 | 249 | stdout, stderr = assemble_output(iopub) |
|
251 | 250 | nt.assert_equal(stdout, "2\n") |
|
252 | 251 | |
|
252 | ||
|
253 | def test_help_output(): | |
|
254 | """ipython kernel --help-all works""" | |
|
255 | tt.help_all_output_test('kernel') | |
|
256 |
@@ -1,164 +1,160 b'' | |||
|
1 | 1 | """Test NbConvertApp""" |
|
2 | 2 | |
|
3 | 3 | #----------------------------------------------------------------------------- |
|
4 | 4 | # Copyright (C) 2013 The IPython Development Team |
|
5 | 5 | # |
|
6 | 6 | # Distributed under the terms of the BSD License. The full license is in |
|
7 | 7 | # the file COPYING, distributed as part of this software. |
|
8 | 8 | #----------------------------------------------------------------------------- |
|
9 | 9 | |
|
10 | 10 | #----------------------------------------------------------------------------- |
|
11 | 11 | # Imports |
|
12 | 12 | #----------------------------------------------------------------------------- |
|
13 | 13 | |
|
14 | 14 | import os |
|
15 | 15 | import glob |
|
16 | 16 | |
|
17 | 17 | from .base import TestsBase |
|
18 | 18 | |
|
19 | 19 | import IPython.testing.tools as tt |
|
20 | 20 | from IPython.testing import decorators as dec |
|
21 | 21 | |
|
22 | 22 | |
|
23 | 23 | #----------------------------------------------------------------------------- |
|
24 | 24 | # Constants |
|
25 | 25 | #----------------------------------------------------------------------------- |
|
26 | 26 | |
|
27 | 27 | |
|
28 | 28 | #----------------------------------------------------------------------------- |
|
29 | 29 | # Classes and functions |
|
30 | 30 | #----------------------------------------------------------------------------- |
|
31 | 31 | |
|
32 | 32 | class TestNbConvertApp(TestsBase): |
|
33 | 33 | """Collection of NbConvertApp tests""" |
|
34 | 34 | |
|
35 | 35 | |
|
36 | 36 | def test_notebook_help(self): |
|
37 | 37 | """Will help show if no notebooks are specified?""" |
|
38 | 38 | with self.create_temp_cwd(): |
|
39 | 39 | out, err = self.call('nbconvert --log-level 0', ignore_return_code=True) |
|
40 | 40 | self.assertIn("see '--help-all'", out) |
|
41 | 41 | |
|
42 | 42 | def test_help_output(self): |
|
43 | """ipython nbconvert -h works""" | |
|
44 | tt.help_output_test('nbconvert') | |
|
45 | ||
|
46 | def test_help_all_output(self): | |
|
47 | 43 | """ipython nbconvert --help-all works""" |
|
48 | 44 | tt.help_all_output_test('nbconvert') |
|
49 | 45 | |
|
50 | 46 | def test_glob(self): |
|
51 | 47 | """ |
|
52 | 48 | Do search patterns work for notebook names? |
|
53 | 49 | """ |
|
54 | 50 | with self.create_temp_cwd(['notebook*.ipynb']): |
|
55 | 51 | self.call('nbconvert --to python *.ipynb --log-level 0') |
|
56 | 52 | assert os.path.isfile('notebook1.py') |
|
57 | 53 | assert os.path.isfile('notebook2.py') |
|
58 | 54 | |
|
59 | 55 | |
|
60 | 56 | def test_glob_subdir(self): |
|
61 | 57 | """ |
|
62 | 58 | Do search patterns work for subdirectory notebook names? |
|
63 | 59 | """ |
|
64 | 60 | with self.create_temp_cwd(): |
|
65 | 61 | self.copy_files_to(['notebook*.ipynb'], 'subdir/') |
|
66 | 62 | self.call('nbconvert --to python --log-level 0 ' + |
|
67 | 63 | os.path.join('subdir', '*.ipynb')) |
|
68 | 64 | assert os.path.isfile('notebook1.py') |
|
69 | 65 | assert os.path.isfile('notebook2.py') |
|
70 | 66 | |
|
71 | 67 | |
|
72 | 68 | def test_explicit(self): |
|
73 | 69 | """ |
|
74 | 70 | Do explicit notebook names work? |
|
75 | 71 | """ |
|
76 | 72 | with self.create_temp_cwd(['notebook*.ipynb']): |
|
77 | 73 | self.call('nbconvert --log-level 0 --to python notebook2') |
|
78 | 74 | assert not os.path.isfile('notebook1.py') |
|
79 | 75 | assert os.path.isfile('notebook2.py') |
|
80 | 76 | |
|
81 | 77 | |
|
82 | 78 | @dec.onlyif_cmds_exist('pdflatex') |
|
83 | 79 | @dec.onlyif_cmds_exist('pandoc') |
|
84 | 80 | def test_filename_spaces(self): |
|
85 | 81 | """ |
|
86 | 82 | Generate PDFs with graphics if notebooks have spaces in the name? |
|
87 | 83 | """ |
|
88 | 84 | with self.create_temp_cwd(['notebook2.ipynb']): |
|
89 | 85 | os.rename('notebook2.ipynb', 'notebook with spaces.ipynb') |
|
90 | 86 | o,e = self.call('nbconvert --log-level 0 --to latex ' |
|
91 | 87 | '"notebook with spaces" --post PDF ' |
|
92 | 88 | '--PDFPostProcessor.verbose=True') |
|
93 | 89 | assert os.path.isfile('notebook with spaces.tex') |
|
94 | 90 | assert os.path.isdir('notebook with spaces_files') |
|
95 | 91 | assert os.path.isfile('notebook with spaces.pdf') |
|
96 | 92 | |
|
97 | 93 | @dec.onlyif_cmds_exist('pdflatex') |
|
98 | 94 | @dec.onlyif_cmds_exist('pandoc') |
|
99 | 95 | def test_post_processor(self): |
|
100 | 96 | """ |
|
101 | 97 | Do post processors work? |
|
102 | 98 | """ |
|
103 | 99 | with self.create_temp_cwd(['notebook1.ipynb']): |
|
104 | 100 | self.call('nbconvert --log-level 0 --to latex notebook1 ' |
|
105 | 101 | '--post PDF --PDFPostProcessor.verbose=True') |
|
106 | 102 | assert os.path.isfile('notebook1.tex') |
|
107 | 103 | assert os.path.isfile('notebook1.pdf') |
|
108 | 104 | |
|
109 | 105 | |
|
110 | 106 | @dec.onlyif_cmds_exist('pandoc') |
|
111 | 107 | def test_template(self): |
|
112 | 108 | """ |
|
113 | 109 | Do export templates work? |
|
114 | 110 | """ |
|
115 | 111 | with self.create_temp_cwd(['notebook2.ipynb']): |
|
116 | 112 | self.call('nbconvert --log-level 0 --to slides ' |
|
117 | 113 | 'notebook2.ipynb --template reveal') |
|
118 | 114 | assert os.path.isfile('notebook2.slides.html') |
|
119 | 115 | with open('notebook2.slides.html') as f: |
|
120 | 116 | assert '/reveal.css' in f.read() |
|
121 | 117 | |
|
122 | 118 | |
|
123 | 119 | def test_glob_explicit(self): |
|
124 | 120 | """ |
|
125 | 121 | Can a search pattern be used along with matching explicit notebook names? |
|
126 | 122 | """ |
|
127 | 123 | with self.create_temp_cwd(['notebook*.ipynb']): |
|
128 | 124 | self.call('nbconvert --log-level 0 --to python ' |
|
129 | 125 | '*.ipynb notebook1.ipynb notebook2.ipynb') |
|
130 | 126 | assert os.path.isfile('notebook1.py') |
|
131 | 127 | assert os.path.isfile('notebook2.py') |
|
132 | 128 | |
|
133 | 129 | |
|
134 | 130 | def test_explicit_glob(self): |
|
135 | 131 | """ |
|
136 | 132 | Can explicit notebook names be used and then a matching search pattern? |
|
137 | 133 | """ |
|
138 | 134 | with self.create_temp_cwd(['notebook*.ipynb']): |
|
139 | 135 | self.call('nbconvert --log-level 0 --to=python ' |
|
140 | 136 | 'notebook1.ipynb notebook2.ipynb *.ipynb') |
|
141 | 137 | assert os.path.isfile('notebook1.py') |
|
142 | 138 | assert os.path.isfile('notebook2.py') |
|
143 | 139 | |
|
144 | 140 | |
|
145 | 141 | def test_default_config(self): |
|
146 | 142 | """ |
|
147 | 143 | Does the default config work? |
|
148 | 144 | """ |
|
149 | 145 | with self.create_temp_cwd(['notebook*.ipynb', 'ipython_nbconvert_config.py']): |
|
150 | 146 | self.call('nbconvert --log-level 0') |
|
151 | 147 | assert os.path.isfile('notebook1.py') |
|
152 | 148 | assert not os.path.isfile('notebook2.py') |
|
153 | 149 | |
|
154 | 150 | |
|
155 | 151 | def test_override_config(self): |
|
156 | 152 | """ |
|
157 | 153 | Can the default config be overriden? |
|
158 | 154 | """ |
|
159 | 155 | with self.create_temp_cwd(['notebook*.ipynb', |
|
160 | 156 | 'ipython_nbconvert_config.py', |
|
161 | 157 | 'override.py']): |
|
162 | 158 | self.call('nbconvert --log-level 0 --config="override.py"') |
|
163 | 159 | assert not os.path.isfile('notebook1.py') |
|
164 | 160 | assert os.path.isfile('notebook2.py') |
@@ -1,29 +1,25 b'' | |||
|
1 | 1 | """Test QtConsoleApp""" |
|
2 | 2 | |
|
3 | 3 | #----------------------------------------------------------------------------- |
|
4 | 4 | # Copyright (C) 2013 The IPython Development Team |
|
5 | 5 | # |
|
6 | 6 | # Distributed under the terms of the BSD License. The full license is in |
|
7 | 7 | # the file COPYING, distributed as part of this software. |
|
8 | 8 | #----------------------------------------------------------------------------- |
|
9 | 9 | |
|
10 | 10 | #----------------------------------------------------------------------------- |
|
11 | 11 | # Imports |
|
12 | 12 | #----------------------------------------------------------------------------- |
|
13 | 13 | |
|
14 | 14 | import nose.tools as nt |
|
15 | 15 | |
|
16 | 16 | import IPython.testing.tools as tt |
|
17 | 17 | |
|
18 | 18 | #----------------------------------------------------------------------------- |
|
19 | 19 | # Test functions |
|
20 | 20 | #----------------------------------------------------------------------------- |
|
21 | 21 | |
|
22 | 22 | def test_help_output(): |
|
23 | """ipython qtconsole -h works""" | |
|
24 | tt.help_output_test('qtconsole') | |
|
25 | ||
|
26 | def test_help_all_output(): | |
|
27 | 23 | """ipython qtconsole --help-all works""" |
|
28 | 24 | tt.help_all_output_test('qtconsole') |
|
29 | 25 |
@@ -1,67 +1,63 b'' | |||
|
1 | 1 | """Tests for two-process terminal frontend |
|
2 | 2 | |
|
3 | 3 | Currently only has the most simple test possible, starting a console and running |
|
4 | 4 | a single command. |
|
5 | 5 | |
|
6 | 6 | Authors: |
|
7 | 7 | |
|
8 | 8 | * Min RK |
|
9 | 9 | """ |
|
10 | 10 | |
|
11 | 11 | #----------------------------------------------------------------------------- |
|
12 | 12 | # Imports |
|
13 | 13 | #----------------------------------------------------------------------------- |
|
14 | 14 | |
|
15 | 15 | import sys |
|
16 | 16 | import time |
|
17 | 17 | |
|
18 | 18 | import nose.tools as nt |
|
19 | 19 | from nose import SkipTest |
|
20 | 20 | |
|
21 | 21 | import IPython.testing.tools as tt |
|
22 | 22 | from IPython.testing import decorators as dec |
|
23 | 23 | from IPython.utils import py3compat |
|
24 | 24 | |
|
25 | 25 | #----------------------------------------------------------------------------- |
|
26 | 26 | # Tests |
|
27 | 27 | #----------------------------------------------------------------------------- |
|
28 | 28 | |
|
29 | 29 | @dec.skip_win32 |
|
30 | 30 | def test_console_starts(): |
|
31 | 31 | """test that `ipython console` starts a terminal""" |
|
32 | 32 | from IPython.external import pexpect |
|
33 | 33 | |
|
34 | 34 | args = ['console', '--colors=NoColor'] |
|
35 | 35 | # FIXME: remove workaround for 2.6 support |
|
36 | 36 | if sys.version_info[:2] > (2,6): |
|
37 | 37 | args = ['-m', 'IPython'] + args |
|
38 | 38 | cmd = sys.executable |
|
39 | 39 | else: |
|
40 | 40 | cmd = 'ipython' |
|
41 | 41 | |
|
42 | 42 | try: |
|
43 | 43 | p = pexpect.spawn(cmd, args=args) |
|
44 | 44 | except IOError: |
|
45 | 45 | raise SkipTest("Couldn't find command %s" % cmd) |
|
46 | 46 | |
|
47 | 47 | # timeout after one minute |
|
48 | 48 | t = 60 |
|
49 | 49 | idx = p.expect([r'In \[\d+\]', pexpect.EOF], timeout=t) |
|
50 | 50 | p.sendline('5') |
|
51 | 51 | idx = p.expect([r'Out\[\d+\]: 5', pexpect.EOF], timeout=t) |
|
52 | 52 | idx = p.expect([r'In \[\d+\]', pexpect.EOF], timeout=t) |
|
53 | 53 | # send ctrl-D;ctrl-D to exit |
|
54 | 54 | p.sendeof() |
|
55 | 55 | p.sendeof() |
|
56 | 56 | p.expect([pexpect.EOF, pexpect.TIMEOUT], timeout=t) |
|
57 | 57 | if p.isalive(): |
|
58 | 58 | p.terminate() |
|
59 | 59 | |
|
60 | 60 | def test_help_output(): |
|
61 | """ipython console -h works""" | |
|
62 | tt.help_output_test('console') | |
|
63 | ||
|
64 | def test_help_all_output(): | |
|
65 | 61 | """ipython console --help-all works""" |
|
66 | 62 | tt.help_all_output_test('console') |
|
67 | 63 |
@@ -1,55 +1,37 b'' | |||
|
1 | 1 | """Test help output of various IPython entry points""" |
|
2 | 2 | |
|
3 | 3 | #----------------------------------------------------------------------------- |
|
4 | 4 | # Copyright (C) 2013 The IPython Development Team |
|
5 | 5 | # |
|
6 | 6 | # Distributed under the terms of the BSD License. The full license is in |
|
7 | 7 | # the file COPYING, distributed as part of this software. |
|
8 | 8 | #----------------------------------------------------------------------------- |
|
9 | 9 | |
|
10 | 10 | #----------------------------------------------------------------------------- |
|
11 | 11 | # Imports |
|
12 | 12 | #----------------------------------------------------------------------------- |
|
13 | 13 | |
|
14 | 14 | import IPython.testing.tools as tt |
|
15 | 15 | |
|
16 | 16 | #----------------------------------------------------------------------------- |
|
17 | 17 | # Tests |
|
18 | 18 | #----------------------------------------------------------------------------- |
|
19 | 19 | |
|
20 | 20 | |
|
21 | 21 | def test_ipython_help(): |
|
22 | tt.help_output_test() | |
|
23 | ||
|
24 | def test_ipython_help_all(): | |
|
25 | 22 | tt.help_all_output_test() |
|
26 | 23 | |
|
27 | 24 | def test_profile_help(): |
|
28 | tt.help_output_test("profile") | |
|
29 | ||
|
30 | def test_profile_help_all(): | |
|
31 | 25 | tt.help_all_output_test("profile") |
|
32 | 26 | |
|
33 | 27 | def test_profile_list_help(): |
|
34 | tt.help_output_test("profile list") | |
|
35 | ||
|
36 | def test_profile_list_help_all(): | |
|
37 | 28 | tt.help_all_output_test("profile list") |
|
38 | 29 | |
|
39 | 30 | def test_profile_create_help(): |
|
40 | tt.help_output_test("profile create") | |
|
41 | ||
|
42 | def test_profile_create_help_all(): | |
|
43 | 31 | tt.help_all_output_test("profile create") |
|
44 | 32 | |
|
45 | 33 | def test_locate_help(): |
|
46 | tt.help_output_test("locate") | |
|
47 | ||
|
48 | def test_locate_help_all(): | |
|
49 | 34 | tt.help_all_output_test("locate") |
|
50 | 35 | |
|
51 | 36 | def test_locate_profile_help(): |
|
52 | tt.help_output_test("locate profile") | |
|
53 | ||
|
54 | def test_locate_profile_all(): | |
|
55 | 37 | tt.help_all_output_test("locate profile") |
General Comments 0
You need to be logged in to leave comments.
Login now