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