##// END OF EJS Templates
use traitlets.tests.utils for help output tests...
Min RK -
Show More
@@ -1,74 +1,62 b''
1 1 """Test NotebookApp"""
2 2
3 #-----------------------------------------------------------------------------
4 # Copyright (C) 2013 The IPython Development Team
5 #
6 # Distributed under the terms of the BSD License. The full license is in
7 # the file COPYING, distributed as part of this software.
8 #-----------------------------------------------------------------------------
9
10 #-----------------------------------------------------------------------------
11 # Imports
12 #-----------------------------------------------------------------------------
13 3
14 4 import logging
15 5 import os
16 6 from tempfile import NamedTemporaryFile
17 7
18 8 import nose.tools as nt
19 9
10 from traitlets.tests.utils import check_help_all_output
11
20 12 from IPython.utils.tempdir import TemporaryDirectory
21 13 from IPython.utils.traitlets import TraitError
22 import IPython.testing.tools as tt
23 14 from IPython.html import notebookapp
24 15 NotebookApp = notebookapp.NotebookApp
25 16
26 #-----------------------------------------------------------------------------
27 # Test functions
28 #-----------------------------------------------------------------------------
29 17
30 18 def test_help_output():
31 19 """ipython notebook --help-all works"""
32 tt.help_all_output_test('notebook')
20 check_help_all_output('IPython.html')
33 21
34 22 def test_server_info_file():
35 23 nbapp = NotebookApp(profile='nbserver_file_test', log=logging.getLogger())
36 24 def get_servers():
37 25 return list(notebookapp.list_running_servers(profile='nbserver_file_test'))
38 26 nbapp.initialize(argv=[])
39 27 nbapp.write_server_info_file()
40 28 servers = get_servers()
41 29 nt.assert_equal(len(servers), 1)
42 30 nt.assert_equal(servers[0]['port'], nbapp.port)
43 31 nt.assert_equal(servers[0]['url'], nbapp.connection_url)
44 32 nbapp.remove_server_info_file()
45 33 nt.assert_equal(get_servers(), [])
46 34
47 35 # The ENOENT error should be silenced.
48 36 nbapp.remove_server_info_file()
49 37
50 38 def test_nb_dir():
51 39 with TemporaryDirectory() as td:
52 40 app = NotebookApp(notebook_dir=td)
53 41 nt.assert_equal(app.notebook_dir, td)
54 42
55 43 def test_no_create_nb_dir():
56 44 with TemporaryDirectory() as td:
57 45 nbdir = os.path.join(td, 'notebooks')
58 46 app = NotebookApp()
59 47 with nt.assert_raises(TraitError):
60 48 app.notebook_dir = nbdir
61 49
62 50 def test_missing_nb_dir():
63 51 with TemporaryDirectory() as td:
64 52 nbdir = os.path.join(td, 'notebook', 'dir', 'is', 'missing')
65 53 app = NotebookApp()
66 54 with nt.assert_raises(TraitError):
67 55 app.notebook_dir = nbdir
68 56
69 57 def test_invalid_nb_dir():
70 58 with NamedTemporaryFile() as tf:
71 59 app = NotebookApp()
72 60 with nt.assert_raises(TraitError):
73 61 app.notebook_dir = tf
74 62
@@ -1,76 +1,66 b''
1 1 """Test HTML utils"""
2 2
3 #-----------------------------------------------------------------------------
4 # Copyright (C) 2013 The IPython Development Team
5 #
6 # Distributed under the terms of the BSD License. The full license is in
7 # the file COPYING, distributed as part of this software.
8 #-----------------------------------------------------------------------------
9
10 #-----------------------------------------------------------------------------
11 # Imports
12 #-----------------------------------------------------------------------------
3 # Copyright (c) Jupyter Development Team.
4 # Distributed under the terms of the Modified BSD License.
13 5
14 6 import os
15 7
16 8 import nose.tools as nt
17 9
18 import IPython.testing.tools as tt
10 from traitlets.tests.utils import check_help_all_output
19 11 from IPython.html.utils import url_escape, url_unescape, is_hidden
20 12 from IPython.utils.tempdir import TemporaryDirectory
21 13
22 #-----------------------------------------------------------------------------
23 # Test functions
24 #-----------------------------------------------------------------------------
25 14
26 15 def test_help_output():
27 """ipython notebook --help-all works"""
28 tt.help_all_output_test('notebook')
16 """jupyter notebook --help-all works"""
17 # FIXME: will be jupyter_notebook
18 check_help_all_output('IPython.html')
29 19
30 20
31 21 def test_url_escape():
32 22
33 23 # changes path or notebook name with special characters to url encoding
34 24 # these tests specifically encode paths with spaces
35 25 path = url_escape('/this is a test/for spaces/')
36 26 nt.assert_equal(path, '/this%20is%20a%20test/for%20spaces/')
37 27
38 28 path = url_escape('notebook with space.ipynb')
39 29 nt.assert_equal(path, 'notebook%20with%20space.ipynb')
40 30
41 31 path = url_escape('/path with a/notebook and space.ipynb')
42 32 nt.assert_equal(path, '/path%20with%20a/notebook%20and%20space.ipynb')
43 33
44 34 path = url_escape('/ !@$#%^&* / test %^ notebook @#$ name.ipynb')
45 35 nt.assert_equal(path,
46 36 '/%20%21%40%24%23%25%5E%26%2A%20/%20test%20%25%5E%20notebook%20%40%23%24%20name.ipynb')
47 37
48 38 def test_url_unescape():
49 39
50 40 # decodes a url string to a plain string
51 41 # these tests decode paths with spaces
52 42 path = url_unescape('/this%20is%20a%20test/for%20spaces/')
53 43 nt.assert_equal(path, '/this is a test/for spaces/')
54 44
55 45 path = url_unescape('notebook%20with%20space.ipynb')
56 46 nt.assert_equal(path, 'notebook with space.ipynb')
57 47
58 48 path = url_unescape('/path%20with%20a/notebook%20and%20space.ipynb')
59 49 nt.assert_equal(path, '/path with a/notebook and space.ipynb')
60 50
61 51 path = url_unescape(
62 52 '/%20%21%40%24%23%25%5E%26%2A%20/%20test%20%25%5E%20notebook%20%40%23%24%20name.ipynb')
63 53 nt.assert_equal(path, '/ !@$#%^&* / test %^ notebook @#$ name.ipynb')
64 54
65 55 def test_is_hidden():
66 56 with TemporaryDirectory() as root:
67 57 subdir1 = os.path.join(root, 'subdir')
68 58 os.makedirs(subdir1)
69 59 nt.assert_equal(is_hidden(subdir1, root), False)
70 60 subdir2 = os.path.join(root, '.subdir2')
71 61 os.makedirs(subdir2)
72 62 nt.assert_equal(is_hidden(subdir2, root), True)
73 63 subdir34 = os.path.join(root, 'subdir3', '.subdir4')
74 64 os.makedirs(subdir34)
75 65 nt.assert_equal(is_hidden(subdir34, root), True)
76 66 nt.assert_equal(is_hidden(subdir34), True)
@@ -1,78 +1,64 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
4 a single command.
5
6 Authors:
7
8 * Min RK
9 """
10
11 #-----------------------------------------------------------------------------
12 # Imports
13 #-----------------------------------------------------------------------------
3 # Copyright (c) Jupyter Development Team.
4 # Distributed under the terms of the Modified BSD License.
14 5
15 6 import sys
16 7
17 8 from nose import SkipTest
18 9
19 import IPython.testing.tools as tt
10 from traitlets.tests.utils import check_help_all_output
20 11 from IPython.testing import decorators as dec
21 12
22 #-----------------------------------------------------------------------------
23 # Tests
24 #-----------------------------------------------------------------------------
25
26 13 @dec.skip_win32
27 14 def test_console_starts():
28 15 """test that `ipython console` starts a terminal"""
29 16 p, pexpect, t = start_console()
30 17 p.sendline('5')
31 18 idx = p.expect([r'Out\[\d+\]: 5', pexpect.EOF], timeout=t)
32 19 idx = p.expect([r'In \[\d+\]', pexpect.EOF], timeout=t)
33 20 stop_console(p, pexpect, t)
34 21
35 22 def test_help_output():
36 23 """ipython console --help-all works"""
37 tt.help_all_output_test('console')
38
24 check_help_all_output('jupyter_console')
39 25
40 26 def test_display_text():
41 27 "Ensure display protocol plain/text key is supported"
42 28 # equivalent of:
43 29 #
44 30 # x = %lsmagic
45 31 # from IPython.display import display; display(x);
46 32 p, pexpect, t = start_console()
47 33 p.sendline('x = %lsmagic')
48 34 idx = p.expect([r'In \[\d+\]', pexpect.EOF], timeout=t)
49 35 p.sendline('from IPython.display import display; display(x);')
50 36 p.expect([r'Available line magics:', pexpect.EOF], timeout=t)
51 37 stop_console(p, pexpect, t)
52 38
53 39 def stop_console(p, pexpect, t):
54 40 "Stop a running `ipython console` running via pexpect"
55 41 # send ctrl-D;ctrl-D to exit
56 42 p.sendeof()
57 43 p.sendeof()
58 44 p.expect([pexpect.EOF, pexpect.TIMEOUT], timeout=t)
59 45 if p.isalive():
60 46 p.terminate()
61 47
62 48
63 49 def start_console():
64 50 "Start `ipython console` using pexpect"
65 51 import pexpect
66 52
67 53 args = ['-m', 'IPython', 'console', '--colors=NoColor']
68 54 cmd = sys.executable
69 55
70 56 try:
71 57 p = pexpect.spawn(cmd, args=args)
72 58 except IOError:
73 59 raise SkipTest("Couldn't find command %s" % cmd)
74 60
75 61 # timeout after one minute
76 62 t = 60
77 63 idx = p.expect([r'In \[\d+\]', pexpect.EOF], timeout=t)
78 64 return p, pexpect, t
@@ -1,243 +1,243 b''
1 1 # -*- coding: utf-8 -*-
2 2 """Test NbConvertApp"""
3 3
4 4 # Copyright (c) IPython Development Team.
5 5 # Distributed under the terms of the Modified BSD License.
6 6
7 7 import os
8 8 import glob
9 9 import sys
10 10
11 11 from .base import TestsBase
12 12 from ..postprocessors import PostProcessorBase
13 13
14 import IPython.testing.tools as tt
14 from traitlets.tests.utils import check_help_all_output
15 15 from IPython.testing import decorators as dec
16 16
17 17 #-----------------------------------------------------------------------------
18 18 # Classes and functions
19 19 #-----------------------------------------------------------------------------
20 20
21 21 class DummyPost(PostProcessorBase):
22 22 def postprocess(self, filename):
23 23 print("Dummy:%s" % filename)
24 24
25 25 class TestNbConvertApp(TestsBase):
26 26 """Collection of NbConvertApp tests"""
27 27
28 28
29 29 def test_notebook_help(self):
30 30 """Will help show if no notebooks are specified?"""
31 31 with self.create_temp_cwd():
32 32 out, err = self.call('nbconvert --log-level 0', ignore_return_code=True)
33 33 self.assertIn("see '--help-all'", out)
34 34
35 35 def test_help_output(self):
36 36 """ipython nbconvert --help-all works"""
37 tt.help_all_output_test('nbconvert')
37 check_help_all_output('jupyter_nbconvert')
38 38
39 39 def test_glob(self):
40 40 """
41 41 Do search patterns work for notebook names?
42 42 """
43 43 with self.create_temp_cwd(['notebook*.ipynb']):
44 44 self.call('nbconvert --to python *.ipynb --log-level 0')
45 45 assert os.path.isfile('notebook1.py')
46 46 assert os.path.isfile('notebook2.py')
47 47
48 48
49 49 def test_glob_subdir(self):
50 50 """
51 51 Do search patterns work for subdirectory notebook names?
52 52 """
53 53 with self.create_temp_cwd():
54 54 self.copy_files_to(['notebook*.ipynb'], 'subdir/')
55 55 self.call('nbconvert --to python --log-level 0 ' +
56 56 os.path.join('subdir', '*.ipynb'))
57 57 assert os.path.isfile('notebook1.py')
58 58 assert os.path.isfile('notebook2.py')
59 59
60 60
61 61 def test_explicit(self):
62 62 """
63 63 Do explicit notebook names work?
64 64 """
65 65 with self.create_temp_cwd(['notebook*.ipynb']):
66 66 self.call('nbconvert --log-level 0 --to python notebook2')
67 67 assert not os.path.isfile('notebook1.py')
68 68 assert os.path.isfile('notebook2.py')
69 69
70 70
71 71 @dec.onlyif_cmds_exist('pdflatex')
72 72 @dec.onlyif_cmds_exist('pandoc')
73 73 def test_filename_spaces(self):
74 74 """
75 75 Generate PDFs with graphics if notebooks have spaces in the name?
76 76 """
77 77 with self.create_temp_cwd(['notebook2.ipynb']):
78 78 os.rename('notebook2.ipynb', 'notebook with spaces.ipynb')
79 79 self.call('nbconvert --log-level 0 --to pdf'
80 80 ' "notebook with spaces"'
81 81 ' --PDFExporter.latex_count=1'
82 82 ' --PDFExporter.verbose=True'
83 83 )
84 84 assert os.path.isfile('notebook with spaces.pdf')
85 85
86 86 def test_post_processor(self):
87 87 """Do post processors work?"""
88 88 with self.create_temp_cwd(['notebook1.ipynb']):
89 89 out, err = self.call('nbconvert --log-level 0 --to python notebook1 '
90 90 '--post jupyter_nbconvert.tests.test_nbconvertapp.DummyPost')
91 91 self.assertIn('Dummy:notebook1.py', out)
92 92
93 93 @dec.onlyif_cmds_exist('pandoc')
94 94 def test_spurious_cr(self):
95 95 """Check for extra CR characters"""
96 96 with self.create_temp_cwd(['notebook2.ipynb']):
97 97 self.call('nbconvert --log-level 0 --to latex notebook2')
98 98 assert os.path.isfile('notebook2.tex')
99 99 with open('notebook2.tex') as f:
100 100 tex = f.read()
101 101 self.call('nbconvert --log-level 0 --to html notebook2')
102 102 assert os.path.isfile('notebook2.html')
103 103 with open('notebook2.html') as f:
104 104 html = f.read()
105 105 self.assertEqual(tex.count('\r'), tex.count('\r\n'))
106 106 self.assertEqual(html.count('\r'), html.count('\r\n'))
107 107
108 108 @dec.onlyif_cmds_exist('pandoc')
109 109 def test_png_base64_html_ok(self):
110 110 """Is embedded png data well formed in HTML?"""
111 111 with self.create_temp_cwd(['notebook2.ipynb']):
112 112 self.call('nbconvert --log-level 0 --to HTML '
113 113 'notebook2.ipynb --template full')
114 114 assert os.path.isfile('notebook2.html')
115 115 with open('notebook2.html') as f:
116 116 assert "data:image/png;base64,b'" not in f.read()
117 117
118 118 @dec.onlyif_cmds_exist('pandoc')
119 119 def test_template(self):
120 120 """
121 121 Do export templates work?
122 122 """
123 123 with self.create_temp_cwd(['notebook2.ipynb']):
124 124 self.call('nbconvert --log-level 0 --to slides '
125 125 'notebook2.ipynb')
126 126 assert os.path.isfile('notebook2.slides.html')
127 127 with open('notebook2.slides.html') as f:
128 128 assert '/reveal.css' in f.read()
129 129
130 130 def test_output_ext(self):
131 131 """test --output=outputfile[.ext]"""
132 132 with self.create_temp_cwd(['notebook1.ipynb']):
133 133 self.call('nbconvert --log-level 0 --to python '
134 134 'notebook1.ipynb --output nb.py')
135 135 assert os.path.exists('nb.py')
136 136
137 137 self.call('nbconvert --log-level 0 --to python '
138 138 'notebook1.ipynb --output nb2')
139 139 assert os.path.exists('nb2.py')
140 140
141 141 def test_glob_explicit(self):
142 142 """
143 143 Can a search pattern be used along with matching explicit notebook names?
144 144 """
145 145 with self.create_temp_cwd(['notebook*.ipynb']):
146 146 self.call('nbconvert --log-level 0 --to python '
147 147 '*.ipynb notebook1.ipynb notebook2.ipynb')
148 148 assert os.path.isfile('notebook1.py')
149 149 assert os.path.isfile('notebook2.py')
150 150
151 151
152 152 def test_explicit_glob(self):
153 153 """
154 154 Can explicit notebook names be used and then a matching search pattern?
155 155 """
156 156 with self.create_temp_cwd(['notebook*.ipynb']):
157 157 self.call('nbconvert --log-level 0 --to=python '
158 158 'notebook1.ipynb notebook2.ipynb *.ipynb')
159 159 assert os.path.isfile('notebook1.py')
160 160 assert os.path.isfile('notebook2.py')
161 161
162 162
163 163 def test_default_config(self):
164 164 """
165 165 Does the default config work?
166 166 """
167 167 with self.create_temp_cwd(['notebook*.ipynb', 'ipython_nbconvert_config.py']):
168 168 self.call('nbconvert --log-level 0')
169 169 assert os.path.isfile('notebook1.py')
170 170 assert not os.path.isfile('notebook2.py')
171 171
172 172
173 173 def test_override_config(self):
174 174 """
175 175 Can the default config be overriden?
176 176 """
177 177 with self.create_temp_cwd(['notebook*.ipynb',
178 178 'ipython_nbconvert_config.py',
179 179 'override.py']):
180 180 self.call('nbconvert --log-level 0 --config="override.py"')
181 181 assert not os.path.isfile('notebook1.py')
182 182 assert os.path.isfile('notebook2.py')
183 183
184 184 def test_accents_in_filename(self):
185 185 """
186 186 Can notebook names include accents?
187 187 """
188 188 with self.create_temp_cwd():
189 189 self.create_empty_notebook(u'nb1_análisis.ipynb')
190 190 self.call('nbconvert --log-level 0 --to python nb1_*')
191 191 assert os.path.isfile(u'nb1_análisis.py')
192 192
193 193 @dec.onlyif_cmds_exist('pdflatex', 'pandoc')
194 194 def test_filename_accent_pdf(self):
195 195 """
196 196 Generate PDFs if notebooks have an accent in their name?
197 197 """
198 198 with self.create_temp_cwd():
199 199 self.create_empty_notebook(u'nb1_análisis.ipynb')
200 200 self.call('nbconvert --log-level 0 --to pdf "nb1_*"'
201 201 ' --PDFExporter.latex_count=1'
202 202 ' --PDFExporter.verbose=True')
203 203 assert os.path.isfile(u'nb1_análisis.pdf')
204 204
205 205 def test_cwd_plugin(self):
206 206 """
207 207 Verify that an extension in the cwd can be imported.
208 208 """
209 209 with self.create_temp_cwd(['hello.py']):
210 210 self.create_empty_notebook(u'empty.ipynb')
211 211 self.call('nbconvert empty --to html --NbConvertApp.writer_class=\'hello.HelloWriter\'')
212 212 assert os.path.isfile(u'hello.txt')
213 213
214 214 def test_output_suffix(self):
215 215 """
216 216 Verify that the output suffix is applied
217 217 """
218 218 with self.create_temp_cwd():
219 219 self.create_empty_notebook('empty.ipynb')
220 220 self.call('nbconvert empty.ipynb --to notebook')
221 221 assert os.path.isfile('empty.nbconvert.ipynb')
222 222
223 223 def test_different_build_dir(self):
224 224 """
225 225 Verify that the output suffix is not applied
226 226 """
227 227 with self.create_temp_cwd():
228 228 self.create_empty_notebook('empty.ipynb')
229 229 os.mkdir('output')
230 230 self.call(
231 231 'nbconvert empty.ipynb --to notebook '
232 232 '--FilesWriter.build_directory=output')
233 233 assert os.path.isfile('output/empty.ipynb')
234 234
235 235 def test_inplace(self):
236 236 """
237 237 Verify that the notebook is converted in place
238 238 """
239 239 with self.create_temp_cwd():
240 240 self.create_empty_notebook('empty.ipynb')
241 241 self.call('nbconvert empty.ipynb --to notebook --inplace')
242 242 assert os.path.isfile('empty.ipynb')
243 243 assert not os.path.isfile('empty.nbconvert.ipynb')
@@ -1,27 +1,15 b''
1 1 """Test QtConsoleApp"""
2 2
3 #-----------------------------------------------------------------------------
4 # Copyright (C) 2013 The IPython Development Team
5 #
6 # Distributed under the terms of the BSD License. The full license is in
7 # the file COPYING, distributed as part of this software.
8 #-----------------------------------------------------------------------------
9
10 #-----------------------------------------------------------------------------
11 # Imports
12 #-----------------------------------------------------------------------------
3 # Copyright (c) Jupyter Development Team.
4 # Distributed under the terms of the Modified BSD License.
13 5
14 6 import nose.tools as nt
15 7
16 import IPython.testing.tools as tt
8 from traitlets.tests.utils import check_help_all_output
17 9 from IPython.testing.decorators import skip_if_no_x11
18 10
19 #-----------------------------------------------------------------------------
20 # Test functions
21 #-----------------------------------------------------------------------------
22
23 11 @skip_if_no_x11
24 12 def test_help_output():
25 """ipython qtconsole --help-all works"""
26 tt.help_all_output_test('qtconsole')
13 """jupyter qtconsole --help-all works"""
14 check_help_all_output('jupyter_qtconsole')
27 15
General Comments 0
You need to be logged in to leave comments. Login now