Show More
@@ -1,149 +1,160 b'' | |||||
1 | """ |
|
1 | """ | |
2 | Contains writer for writing nbconvert output to PDF. |
|
2 | Contains writer for writing nbconvert output to PDF. | |
3 | """ |
|
3 | """ | |
4 | #----------------------------------------------------------------------------- |
|
4 | #----------------------------------------------------------------------------- | |
5 | #Copyright (c) 2013, the IPython Development Team. |
|
5 | #Copyright (c) 2013, the IPython Development Team. | |
6 | # |
|
6 | # | |
7 | #Distributed under the terms of the Modified BSD License. |
|
7 | #Distributed under the terms of the Modified BSD License. | |
8 | # |
|
8 | # | |
9 | #The full license is in the file COPYING.txt, distributed with this software. |
|
9 | #The full license is in the file COPYING.txt, distributed with this software. | |
10 | #----------------------------------------------------------------------------- |
|
10 | #----------------------------------------------------------------------------- | |
11 |
|
11 | |||
12 | #----------------------------------------------------------------------------- |
|
12 | #----------------------------------------------------------------------------- | |
13 | # Imports |
|
13 | # Imports | |
14 | #----------------------------------------------------------------------------- |
|
14 | #----------------------------------------------------------------------------- | |
15 |
|
15 | |||
16 | import subprocess |
|
16 | import subprocess | |
17 | import os |
|
17 | import os | |
18 | import sys |
|
18 | import sys | |
19 |
|
19 | |||
20 | from IPython.utils.traitlets import Integer, List, Bool |
|
20 | from IPython.utils.traitlets import Integer, List, Bool | |
|
21 | from IPython.utils.encoding import DEFAULT_ENCODING | |||
21 |
|
22 | |||
22 | from .base import PostProcessorBase |
|
23 | from .base import PostProcessorBase | |
23 |
|
24 | |||
|
25 | ||||
24 | #----------------------------------------------------------------------------- |
|
26 | #----------------------------------------------------------------------------- | |
25 | # Classes |
|
27 | # Classes | |
26 | #----------------------------------------------------------------------------- |
|
28 | #----------------------------------------------------------------------------- | |
27 | class PDFPostProcessor(PostProcessorBase): |
|
29 | class PDFPostProcessor(PostProcessorBase): | |
28 | """Writer designed to write to PDF files""" |
|
30 | """Writer designed to write to PDF files""" | |
29 |
|
31 | |||
30 | latex_count = Integer(3, config=True, help=""" |
|
32 | latex_count = Integer(3, config=True, help=""" | |
31 | How many times pdflatex will be called. |
|
33 | How many times pdflatex will be called. | |
32 | """) |
|
34 | """) | |
33 |
|
35 | |||
34 | latex_command = List(["pdflatex", "{filename}"], config=True, help=""" |
|
36 | latex_command = List(["pdflatex", "{filename}"], config=True, help=""" | |
35 | Shell command used to compile PDF.""") |
|
37 | Shell command used to compile PDF.""") | |
36 |
|
38 | |||
37 | bib_command = List(["bibtex", "{filename}"], config=True, help=""" |
|
39 | bib_command = List(["bibtex", "{filename}"], config=True, help=""" | |
38 | Shell command used to run bibtex.""") |
|
40 | Shell command used to run bibtex.""") | |
39 |
|
41 | |||
40 | verbose = Bool(False, config=True, help=""" |
|
42 | verbose = Bool(False, config=True, help=""" | |
41 | Whether or not to display the output of the compile call. |
|
43 | Whether or not to display the output of the compile call. | |
42 | """) |
|
44 | """) | |
43 |
|
45 | |||
44 | temp_file_exts = List(['.aux', '.bbl', '.blg', '.idx', '.log', '.out'], |
|
46 | temp_file_exts = List(['.aux', '.bbl', '.blg', '.idx', '.log', '.out'], | |
45 | config=True, help=""" |
|
47 | config=True, help=""" | |
46 | Filename extensions of temp files to remove after running. |
|
48 | Filename extensions of temp files to remove after running. | |
47 | """) |
|
49 | """) | |
48 | pdf_open = Bool(False, config=True, help=""" |
|
50 | pdf_open = Bool(False, config=True, help=""" | |
49 | Whether or not to open the pdf after the compile call. |
|
51 | Whether or not to open the pdf after the compile call. | |
50 | """) |
|
52 | """) | |
51 |
|
53 | |||
52 | def run_command(self, command_list, filename, count, log_function): |
|
54 | def run_command(self, command_list, filename, count, log_function): | |
53 | """Run command_list count times. |
|
55 | """Run command_list count times. | |
54 |
|
56 | |||
55 | Parameters |
|
57 | Parameters | |
56 | ---------- |
|
58 | ---------- | |
57 | command_list : list |
|
59 | command_list : list | |
58 | A list of args to provide to Popen. Each element of this |
|
60 | A list of args to provide to Popen. Each element of this | |
59 | list will be interpolated with the filename to convert. |
|
61 | list will be interpolated with the filename to convert. | |
60 | filename : unicode |
|
62 | filename : unicode | |
61 | The name of the file to convert. |
|
63 | The name of the file to convert. | |
62 | count : int |
|
64 | count : int | |
63 | How many times to run the command. |
|
65 | How many times to run the command. | |
64 |
|
66 | |||
65 | Returns |
|
67 | Returns | |
66 | ------- |
|
68 | ------- | |
67 | continue : bool |
|
69 | continue : bool | |
68 | A boolean indicating if the command was successful (True) |
|
70 | A boolean indicating if the command was successful (True) | |
69 | or failed (False). |
|
71 | or failed (False). | |
70 | """ |
|
72 | """ | |
|
73 | #HACK: Encode file name with the correct encoding | |||
|
74 | # For Windows must be cp1252 (win application) and we cannot use | |||
|
75 | # encoding.DEFAULT_ENCODING or sys.stdin.encoding because input | |||
|
76 | # encoding could be different (cp437 in case of dos console) | |||
|
77 | if sys.platform == 'win32': | |||
|
78 | filename = filename.encode('cp1252') | |||
|
79 | else: | |||
|
80 | filename = filename.encode('utf-8') | |||
|
81 | #END_HACK | |||
71 | command = [c.format(filename=filename) for c in command_list] |
|
82 | command = [c.format(filename=filename) for c in command_list] | |
72 | times = 'time' if count == 1 else 'times' |
|
83 | times = 'time' if count == 1 else 'times' | |
73 | self.log.info("Running %s %i %s: %s", command_list[0], count, times, command) |
|
84 | self.log.info("Running %s %i %s: %s", command_list[0], count, times, command) | |
74 | with open(os.devnull, 'rb') as null: |
|
85 | with open(os.devnull, 'rb') as null: | |
75 | stdout = subprocess.PIPE if not self.verbose else None |
|
86 | stdout = subprocess.PIPE if not self.verbose else None | |
76 | for index in range(count): |
|
87 | for index in range(count): | |
77 | p = subprocess.Popen(command, stdout=stdout, stdin=null) |
|
88 | p = subprocess.Popen(command, stdout=stdout, stdin=null, shell=True) | |
78 | out, err = p.communicate() |
|
89 | out, err = p.communicate() | |
79 | if p.returncode: |
|
90 | if p.returncode: | |
80 | if self.verbose: |
|
91 | if self.verbose: | |
81 | # verbose means I didn't capture stdout with PIPE, |
|
92 | # verbose means I didn't capture stdout with PIPE, | |
82 | # so it's already been displayed and `out` is None. |
|
93 | # so it's already been displayed and `out` is None. | |
83 | out = u'' |
|
94 | out = u'' | |
84 | else: |
|
95 | else: | |
85 | out = out.decode('utf-8', 'replace') |
|
96 | out = out.decode('utf-8', 'replace') | |
86 | log_function(command, out) |
|
97 | log_function(command, out) | |
87 | return False # failure |
|
98 | return False # failure | |
88 | return True # success |
|
99 | return True # success | |
89 |
|
100 | |||
90 | def run_latex(self, filename): |
|
101 | def run_latex(self, filename): | |
91 | """Run pdflatex self.latex_count times.""" |
|
102 | """Run pdflatex self.latex_count times.""" | |
92 |
|
103 | |||
93 | def log_error(command, out): |
|
104 | def log_error(command, out): | |
94 | self.log.critical(u"%s failed: %s\n%s", command[0], command, out) |
|
105 | self.log.critical(u"%s failed: %s\n%s", command[0], command, out) | |
95 |
|
106 | |||
96 | return self.run_command(self.latex_command, filename, |
|
107 | return self.run_command(self.latex_command, filename, | |
97 | self.latex_count, log_error) |
|
108 | self.latex_count, log_error) | |
98 |
|
109 | |||
99 | def run_bib(self, filename): |
|
110 | def run_bib(self, filename): | |
100 | """Run bibtex self.latex_count times.""" |
|
111 | """Run bibtex self.latex_count times.""" | |
101 | filename = os.path.splitext(filename)[0] |
|
112 | filename = os.path.splitext(filename)[0] | |
102 |
|
113 | |||
103 | def log_error(command, out): |
|
114 | def log_error(command, out): | |
104 | self.log.warn('%s had problems, most likely because there were no citations', |
|
115 | self.log.warn('%s had problems, most likely because there were no citations', | |
105 | command[0]) |
|
116 | command[0]) | |
106 | self.log.debug(u"%s output: %s\n%s", command[0], command, out) |
|
117 | self.log.debug(u"%s output: %s\n%s", command[0], command, out) | |
107 |
|
118 | |||
108 | return self.run_command(self.bib_command, filename, 1, log_error) |
|
119 | return self.run_command(self.bib_command, filename, 1, log_error) | |
109 |
|
120 | |||
110 | def clean_temp_files(self, filename): |
|
121 | def clean_temp_files(self, filename): | |
111 | """Remove temporary files created by pdflatex/bibtext.""" |
|
122 | """Remove temporary files created by pdflatex/bibtext.""" | |
112 | self.log.info("Removing temporary LaTeX files") |
|
123 | self.log.info("Removing temporary LaTeX files") | |
113 | filename = os.path.splitext(filename)[0] |
|
124 | filename = os.path.splitext(filename)[0] | |
114 | for ext in self.temp_file_exts: |
|
125 | for ext in self.temp_file_exts: | |
115 | try: |
|
126 | try: | |
116 | os.remove(filename+ext) |
|
127 | os.remove(filename+ext) | |
117 | except OSError: |
|
128 | except OSError: | |
118 | pass |
|
129 | pass | |
119 |
|
130 | |||
120 | def open_pdf(self, filename): |
|
131 | def open_pdf(self, filename): | |
121 | """Open the pdf in the default viewer.""" |
|
132 | """Open the pdf in the default viewer.""" | |
122 | if sys.platform.startswith('darwin'): |
|
133 | if sys.platform.startswith('darwin'): | |
123 | subprocess.call(('open', filename)) |
|
134 | subprocess.call(('open', filename)) | |
124 | elif os.name == 'nt': |
|
135 | elif os.name == 'nt': | |
125 | os.startfile(filename) |
|
136 | os.startfile(filename) | |
126 | elif os.name == 'posix': |
|
137 | elif os.name == 'posix': | |
127 | subprocess.call(('xdg-open', filename)) |
|
138 | subprocess.call(('xdg-open', filename)) | |
128 | return |
|
139 | return | |
129 |
|
140 | |||
130 | def postprocess(self, filename): |
|
141 | def postprocess(self, filename): | |
131 | """Build a PDF by running pdflatex and bibtex""" |
|
142 | """Build a PDF by running pdflatex and bibtex""" | |
132 | self.log.info("Building PDF") |
|
143 | self.log.info("Building PDF") | |
133 | cont = self.run_latex(filename) |
|
144 | cont = self.run_latex(filename) | |
134 | if cont: |
|
145 | if cont: | |
135 | cont = self.run_bib(filename) |
|
146 | cont = self.run_bib(filename) | |
136 | else: |
|
147 | else: | |
137 | self.clean_temp_files(filename) |
|
148 | self.clean_temp_files(filename) | |
138 | return |
|
149 | return | |
139 | if cont: |
|
150 | if cont: | |
140 | cont = self.run_latex(filename) |
|
151 | cont = self.run_latex(filename) | |
141 | self.clean_temp_files(filename) |
|
152 | self.clean_temp_files(filename) | |
142 | filename = os.path.splitext(filename)[0] |
|
153 | filename = os.path.splitext(filename)[0] | |
143 | if os.path.isfile(filename+'.pdf'): |
|
154 | if os.path.isfile(filename+'.pdf'): | |
144 | self.log.info('PDF successfully created') |
|
155 | self.log.info('PDF successfully created') | |
145 | if self.pdf_open: |
|
156 | if self.pdf_open: | |
146 | self.log.info('Viewer called') |
|
157 | self.log.info('Viewer called') | |
147 | self.open_pdf(filename+'.pdf') |
|
158 | self.open_pdf(filename+'.pdf') | |
148 | return |
|
159 | return | |
149 |
|
160 |
@@ -1,218 +1,217 b'' | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 | """Test NbConvertApp""" |
|
2 | """Test NbConvertApp""" | |
3 |
|
3 | |||
4 | #----------------------------------------------------------------------------- |
|
4 | #----------------------------------------------------------------------------- | |
5 | # Copyright (C) 2013 The IPython Development Team |
|
5 | # Copyright (C) 2013 The IPython Development Team | |
6 | # |
|
6 | # | |
7 | # Distributed under the terms of the BSD License. The full license is in |
|
7 | # Distributed under the terms of the BSD License. The full license is in | |
8 | # the file COPYING, distributed as part of this software. |
|
8 | # the file COPYING, distributed as part of this software. | |
9 | #----------------------------------------------------------------------------- |
|
9 | #----------------------------------------------------------------------------- | |
10 |
|
10 | |||
11 | #----------------------------------------------------------------------------- |
|
11 | #----------------------------------------------------------------------------- | |
12 | # Imports |
|
12 | # Imports | |
13 | #----------------------------------------------------------------------------- |
|
13 | #----------------------------------------------------------------------------- | |
14 |
|
14 | |||
15 | import os |
|
15 | import os | |
16 | import glob |
|
16 | import glob | |
17 | import sys |
|
17 | import sys | |
18 |
|
18 | |||
19 | from .base import TestsBase |
|
19 | from .base import TestsBase | |
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 |
|
23 | |||
24 |
|
24 | |||
25 | #----------------------------------------------------------------------------- |
|
25 | #----------------------------------------------------------------------------- | |
26 | # Constants |
|
26 | # Constants | |
27 | #----------------------------------------------------------------------------- |
|
27 | #----------------------------------------------------------------------------- | |
28 |
|
28 | |||
29 |
|
29 | |||
30 | #----------------------------------------------------------------------------- |
|
30 | #----------------------------------------------------------------------------- | |
31 | # Classes and functions |
|
31 | # Classes and functions | |
32 | #----------------------------------------------------------------------------- |
|
32 | #----------------------------------------------------------------------------- | |
33 |
|
33 | |||
34 | class TestNbConvertApp(TestsBase): |
|
34 | class TestNbConvertApp(TestsBase): | |
35 | """Collection of NbConvertApp tests""" |
|
35 | """Collection of NbConvertApp tests""" | |
36 |
|
36 | |||
37 |
|
37 | |||
38 | def test_notebook_help(self): |
|
38 | def test_notebook_help(self): | |
39 | """Will help show if no notebooks are specified?""" |
|
39 | """Will help show if no notebooks are specified?""" | |
40 | with self.create_temp_cwd(): |
|
40 | with self.create_temp_cwd(): | |
41 | out, err = self.call('nbconvert --log-level 0', ignore_return_code=True) |
|
41 | out, err = self.call('nbconvert --log-level 0', ignore_return_code=True) | |
42 | self.assertIn("see '--help-all'", out) |
|
42 | self.assertIn("see '--help-all'", out) | |
43 |
|
43 | |||
44 | def test_help_output(self): |
|
44 | def test_help_output(self): | |
45 | """ipython nbconvert --help-all works""" |
|
45 | """ipython nbconvert --help-all works""" | |
46 | tt.help_all_output_test('nbconvert') |
|
46 | tt.help_all_output_test('nbconvert') | |
47 |
|
47 | |||
48 | def test_glob(self): |
|
48 | def test_glob(self): | |
49 | """ |
|
49 | """ | |
50 | Do search patterns work for notebook names? |
|
50 | Do search patterns work for notebook names? | |
51 | """ |
|
51 | """ | |
52 | with self.create_temp_cwd(['notebook*.ipynb']): |
|
52 | with self.create_temp_cwd(['notebook*.ipynb']): | |
53 | self.call('nbconvert --to python *.ipynb --log-level 0') |
|
53 | self.call('nbconvert --to python *.ipynb --log-level 0') | |
54 | assert os.path.isfile('notebook1.py') |
|
54 | assert os.path.isfile('notebook1.py') | |
55 | assert os.path.isfile('notebook2.py') |
|
55 | assert os.path.isfile('notebook2.py') | |
56 |
|
56 | |||
57 |
|
57 | |||
58 | def test_glob_subdir(self): |
|
58 | def test_glob_subdir(self): | |
59 | """ |
|
59 | """ | |
60 | Do search patterns work for subdirectory notebook names? |
|
60 | Do search patterns work for subdirectory notebook names? | |
61 | """ |
|
61 | """ | |
62 | with self.create_temp_cwd(): |
|
62 | with self.create_temp_cwd(): | |
63 | self.copy_files_to(['notebook*.ipynb'], 'subdir/') |
|
63 | self.copy_files_to(['notebook*.ipynb'], 'subdir/') | |
64 | self.call('nbconvert --to python --log-level 0 ' + |
|
64 | self.call('nbconvert --to python --log-level 0 ' + | |
65 | os.path.join('subdir', '*.ipynb')) |
|
65 | os.path.join('subdir', '*.ipynb')) | |
66 | assert os.path.isfile('notebook1.py') |
|
66 | assert os.path.isfile('notebook1.py') | |
67 | assert os.path.isfile('notebook2.py') |
|
67 | assert os.path.isfile('notebook2.py') | |
68 |
|
68 | |||
69 |
|
69 | |||
70 | def test_explicit(self): |
|
70 | def test_explicit(self): | |
71 | """ |
|
71 | """ | |
72 | Do explicit notebook names work? |
|
72 | Do explicit notebook names work? | |
73 | """ |
|
73 | """ | |
74 | with self.create_temp_cwd(['notebook*.ipynb']): |
|
74 | with self.create_temp_cwd(['notebook*.ipynb']): | |
75 | self.call('nbconvert --log-level 0 --to python notebook2') |
|
75 | self.call('nbconvert --log-level 0 --to python notebook2') | |
76 | assert not os.path.isfile('notebook1.py') |
|
76 | assert not os.path.isfile('notebook1.py') | |
77 | assert os.path.isfile('notebook2.py') |
|
77 | assert os.path.isfile('notebook2.py') | |
78 |
|
78 | |||
79 |
|
79 | |||
80 | @dec.onlyif_cmds_exist('pdflatex') |
|
80 | @dec.onlyif_cmds_exist('pdflatex') | |
81 | @dec.onlyif_cmds_exist('pandoc') |
|
81 | @dec.onlyif_cmds_exist('pandoc') | |
82 | def test_filename_spaces(self): |
|
82 | def test_filename_spaces(self): | |
83 | """ |
|
83 | """ | |
84 | Generate PDFs with graphics if notebooks have spaces in the name? |
|
84 | Generate PDFs with graphics if notebooks have spaces in the name? | |
85 | """ |
|
85 | """ | |
86 | with self.create_temp_cwd(['notebook2.ipynb']): |
|
86 | with self.create_temp_cwd(['notebook2.ipynb']): | |
87 | os.rename('notebook2.ipynb', 'notebook with spaces.ipynb') |
|
87 | os.rename('notebook2.ipynb', 'notebook with spaces.ipynb') | |
88 | o,e = self.call('nbconvert --log-level 0 --to latex ' |
|
88 | o,e = self.call('nbconvert --log-level 0 --to latex ' | |
89 | '"notebook with spaces" --post PDF ' |
|
89 | '"notebook with spaces" --post PDF ' | |
90 | '--PDFPostProcessor.verbose=True') |
|
90 | '--PDFPostProcessor.verbose=True') | |
91 | assert os.path.isfile('notebook with spaces.tex') |
|
91 | assert os.path.isfile('notebook with spaces.tex') | |
92 | assert os.path.isdir('notebook with spaces_files') |
|
92 | assert os.path.isdir('notebook with spaces_files') | |
93 | assert os.path.isfile('notebook with spaces.pdf') |
|
93 | assert os.path.isfile('notebook with spaces.pdf') | |
94 |
|
94 | |||
95 | @dec.onlyif_cmds_exist('pdflatex') |
|
95 | @dec.onlyif_cmds_exist('pdflatex') | |
96 | @dec.onlyif_cmds_exist('pandoc') |
|
96 | @dec.onlyif_cmds_exist('pandoc') | |
97 | def test_post_processor(self): |
|
97 | def test_post_processor(self): | |
98 | """ |
|
98 | """ | |
99 | Do post processors work? |
|
99 | Do post processors work? | |
100 | """ |
|
100 | """ | |
101 | with self.create_temp_cwd(['notebook1.ipynb']): |
|
101 | with self.create_temp_cwd(['notebook1.ipynb']): | |
102 | self.call('nbconvert --log-level 0 --to latex notebook1 ' |
|
102 | self.call('nbconvert --log-level 0 --to latex notebook1 ' | |
103 | '--post PDF --PDFPostProcessor.verbose=True') |
|
103 | '--post PDF --PDFPostProcessor.verbose=True') | |
104 | assert os.path.isfile('notebook1.tex') |
|
104 | assert os.path.isfile('notebook1.tex') | |
105 | assert os.path.isfile('notebook1.pdf') |
|
105 | assert os.path.isfile('notebook1.pdf') | |
106 |
|
106 | |||
107 | @dec.onlyif_cmds_exist('pandoc') |
|
107 | @dec.onlyif_cmds_exist('pandoc') | |
108 | def test_spurious_cr(self): |
|
108 | def test_spurious_cr(self): | |
109 | """Check for extra CR characters""" |
|
109 | """Check for extra CR characters""" | |
110 | with self.create_temp_cwd(['notebook2.ipynb']): |
|
110 | with self.create_temp_cwd(['notebook2.ipynb']): | |
111 | self.call('nbconvert --log-level 0 --to latex notebook2') |
|
111 | self.call('nbconvert --log-level 0 --to latex notebook2') | |
112 | assert os.path.isfile('notebook2.tex') |
|
112 | assert os.path.isfile('notebook2.tex') | |
113 | with open('notebook2.tex') as f: |
|
113 | with open('notebook2.tex') as f: | |
114 | tex = f.read() |
|
114 | tex = f.read() | |
115 | self.call('nbconvert --log-level 0 --to html notebook2') |
|
115 | self.call('nbconvert --log-level 0 --to html notebook2') | |
116 | assert os.path.isfile('notebook2.html') |
|
116 | assert os.path.isfile('notebook2.html') | |
117 | with open('notebook2.html') as f: |
|
117 | with open('notebook2.html') as f: | |
118 | html = f.read() |
|
118 | html = f.read() | |
119 | self.assertEqual(tex.count('\r'), tex.count('\r\n')) |
|
119 | self.assertEqual(tex.count('\r'), tex.count('\r\n')) | |
120 | self.assertEqual(html.count('\r'), html.count('\r\n')) |
|
120 | self.assertEqual(html.count('\r'), html.count('\r\n')) | |
121 |
|
121 | |||
122 | @dec.onlyif_cmds_exist('pandoc') |
|
122 | @dec.onlyif_cmds_exist('pandoc') | |
123 | def test_png_base64_html_ok(self): |
|
123 | def test_png_base64_html_ok(self): | |
124 | """Is embedded png data well formed in HTML?""" |
|
124 | """Is embedded png data well formed in HTML?""" | |
125 | with self.create_temp_cwd(['notebook2.ipynb']): |
|
125 | with self.create_temp_cwd(['notebook2.ipynb']): | |
126 | self.call('nbconvert --log-level 0 --to HTML ' |
|
126 | self.call('nbconvert --log-level 0 --to HTML ' | |
127 | 'notebook2.ipynb --template full') |
|
127 | 'notebook2.ipynb --template full') | |
128 | assert os.path.isfile('notebook2.html') |
|
128 | assert os.path.isfile('notebook2.html') | |
129 | with open('notebook2.html') as f: |
|
129 | with open('notebook2.html') as f: | |
130 | assert "data:image/png;base64,b'" not in f.read() |
|
130 | assert "data:image/png;base64,b'" not in f.read() | |
131 |
|
131 | |||
132 | @dec.onlyif_cmds_exist('pandoc') |
|
132 | @dec.onlyif_cmds_exist('pandoc') | |
133 | def test_template(self): |
|
133 | def test_template(self): | |
134 | """ |
|
134 | """ | |
135 | Do export templates work? |
|
135 | Do export templates work? | |
136 | """ |
|
136 | """ | |
137 | with self.create_temp_cwd(['notebook2.ipynb']): |
|
137 | with self.create_temp_cwd(['notebook2.ipynb']): | |
138 | self.call('nbconvert --log-level 0 --to slides ' |
|
138 | self.call('nbconvert --log-level 0 --to slides ' | |
139 | 'notebook2.ipynb --template reveal') |
|
139 | 'notebook2.ipynb --template reveal') | |
140 | assert os.path.isfile('notebook2.slides.html') |
|
140 | assert os.path.isfile('notebook2.slides.html') | |
141 | with open('notebook2.slides.html') as f: |
|
141 | with open('notebook2.slides.html') as f: | |
142 | assert '/reveal.css' in f.read() |
|
142 | assert '/reveal.css' in f.read() | |
143 |
|
143 | |||
144 |
|
144 | |||
145 | def test_glob_explicit(self): |
|
145 | def test_glob_explicit(self): | |
146 | """ |
|
146 | """ | |
147 | Can a search pattern be used along with matching explicit notebook names? |
|
147 | Can a search pattern be used along with matching explicit notebook names? | |
148 | """ |
|
148 | """ | |
149 | with self.create_temp_cwd(['notebook*.ipynb']): |
|
149 | with self.create_temp_cwd(['notebook*.ipynb']): | |
150 | self.call('nbconvert --log-level 0 --to python ' |
|
150 | self.call('nbconvert --log-level 0 --to python ' | |
151 | '*.ipynb notebook1.ipynb notebook2.ipynb') |
|
151 | '*.ipynb notebook1.ipynb notebook2.ipynb') | |
152 | assert os.path.isfile('notebook1.py') |
|
152 | assert os.path.isfile('notebook1.py') | |
153 | assert os.path.isfile('notebook2.py') |
|
153 | assert os.path.isfile('notebook2.py') | |
154 |
|
154 | |||
155 |
|
155 | |||
156 | def test_explicit_glob(self): |
|
156 | def test_explicit_glob(self): | |
157 | """ |
|
157 | """ | |
158 | Can explicit notebook names be used and then a matching search pattern? |
|
158 | Can explicit notebook names be used and then a matching search pattern? | |
159 | """ |
|
159 | """ | |
160 | with self.create_temp_cwd(['notebook*.ipynb']): |
|
160 | with self.create_temp_cwd(['notebook*.ipynb']): | |
161 | self.call('nbconvert --log-level 0 --to=python ' |
|
161 | self.call('nbconvert --log-level 0 --to=python ' | |
162 | 'notebook1.ipynb notebook2.ipynb *.ipynb') |
|
162 | 'notebook1.ipynb notebook2.ipynb *.ipynb') | |
163 | assert os.path.isfile('notebook1.py') |
|
163 | assert os.path.isfile('notebook1.py') | |
164 | assert os.path.isfile('notebook2.py') |
|
164 | assert os.path.isfile('notebook2.py') | |
165 |
|
165 | |||
166 |
|
166 | |||
167 | def test_default_config(self): |
|
167 | def test_default_config(self): | |
168 | """ |
|
168 | """ | |
169 | Does the default config work? |
|
169 | Does the default config work? | |
170 | """ |
|
170 | """ | |
171 | with self.create_temp_cwd(['notebook*.ipynb', 'ipython_nbconvert_config.py']): |
|
171 | with self.create_temp_cwd(['notebook*.ipynb', 'ipython_nbconvert_config.py']): | |
172 | self.call('nbconvert --log-level 0') |
|
172 | self.call('nbconvert --log-level 0') | |
173 | assert os.path.isfile('notebook1.py') |
|
173 | assert os.path.isfile('notebook1.py') | |
174 | assert not os.path.isfile('notebook2.py') |
|
174 | assert not os.path.isfile('notebook2.py') | |
175 |
|
175 | |||
176 |
|
176 | |||
177 | def test_override_config(self): |
|
177 | def test_override_config(self): | |
178 | """ |
|
178 | """ | |
179 | Can the default config be overriden? |
|
179 | Can the default config be overriden? | |
180 | """ |
|
180 | """ | |
181 | with self.create_temp_cwd(['notebook*.ipynb', |
|
181 | with self.create_temp_cwd(['notebook*.ipynb', | |
182 | 'ipython_nbconvert_config.py', |
|
182 | 'ipython_nbconvert_config.py', | |
183 | 'override.py']): |
|
183 | 'override.py']): | |
184 | self.call('nbconvert --log-level 0 --config="override.py"') |
|
184 | self.call('nbconvert --log-level 0 --config="override.py"') | |
185 | assert not os.path.isfile('notebook1.py') |
|
185 | assert not os.path.isfile('notebook1.py') | |
186 | assert os.path.isfile('notebook2.py') |
|
186 | assert os.path.isfile('notebook2.py') | |
187 |
|
187 | |||
188 | def test_accents_in_filename(self): |
|
188 | def test_accents_in_filename(self): | |
189 | """ |
|
189 | """ | |
190 | Can notebook names include accents? |
|
190 | Can notebook names include accents? | |
191 | """ |
|
191 | """ | |
192 | with self.create_temp_cwd(['nb*.ipynb']): |
|
192 | with self.create_temp_cwd(['nb*.ipynb']): | |
193 | self.call('nbconvert --log-level 0 --to python nb1_*') |
|
193 | self.call('nbconvert --log-level 0 --to python nb1_*') | |
194 | assert os.path.isfile(u'nb1_análisis.py') |
|
194 | assert os.path.isfile(u'nb1_análisis.py') | |
195 |
|
195 | |||
196 | @dec.onlyif_cmds_exist('pandoc') |
|
196 | @dec.onlyif_cmds_exist('pandoc') | |
197 | def test_accents_in_command_line(self): |
|
197 | def test_accents_in_command_line(self): | |
198 | """ |
|
198 | """ | |
199 | Are accents allowed in arguments of command line? |
|
199 | Are accents allowed in arguments of command line? | |
200 | """ |
|
200 | """ | |
201 | with self.create_temp_cwd(['nb*.ipynb']): |
|
201 | with self.create_temp_cwd(['nb*.ipynb']): | |
202 | self.call('nbconvert --to latex nb1_* ' |
|
202 | self.call('nbconvert --to latex nb1_* ' | |
203 | '--SphinxTransform.author="análisis"') |
|
203 | '--SphinxTransform.author="análisis"') | |
204 | assert os.path.isfile(u'nb1_análisis.tex') |
|
204 | assert os.path.isfile(u'nb1_análisis.tex') | |
205 |
|
205 | |||
206 | @dec.onlyif_cmds_exist('pdflatex') |
|
206 | @dec.onlyif_cmds_exist('pdflatex') | |
207 | @dec.onlyif_cmds_exist('pandoc') |
|
207 | @dec.onlyif_cmds_exist('pandoc') | |
208 | def test_filename_spaces(self): |
|
208 | def test_filename_spaces(self): | |
209 | """ |
|
209 | """ | |
210 | Generate PDFs if notebooks have an accent in their name? |
|
210 | Generate PDFs if notebooks have an accent in their name? | |
211 | """ |
|
211 | """ | |
212 | with self.create_temp_cwd(['nb*.ipynb']): |
|
212 | with self.create_temp_cwd(['nb*.ipynb']): | |
213 | o,e = self.call('nbconvert --log-level 0 --to latex ' |
|
213 | o,e = self.call('nbconvert --log-level 0 --to latex ' | |
214 | '"nb1_*" --post PDF ' |
|
214 | '"nb1_*" --post PDF ' | |
215 | '--PDFPostProcessor.verbose=True') |
|
215 | '--PDFPostProcessor.verbose=True') | |
216 | assert os.path.isfile('nb1_análisis.tex') |
|
216 | assert os.path.isfile(u'nb1_análisis.tex') | |
217 |
assert os.path.is |
|
217 | assert os.path.isfile(u'nb1_análisis.pdf') | |
218 | assert os.path.isfile('nb1_análisis.pdf') |
|
General Comments 0
You need to be logged in to leave comments.
Login now