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