##// END OF EJS Templates
move ipython command line logic to one place...
Paul Ivanov -
Show More
@@ -20,6 +20,13 b' import shutil'
20 import IPython
20 import IPython
21 from IPython.utils.tempdir import TemporaryDirectory
21 from IPython.utils.tempdir import TemporaryDirectory
22 from IPython.utils.process import get_output_error_code
22 from IPython.utils.process import get_output_error_code
23 from IPython.utils import py3compat
24
25 # Define ipython command line name
26 if py3compat.PY3:
27 ipy_cmd = 'ipython3 '
28 else:
29 ipy_cmd = 'ipython '
23
30
24 #-----------------------------------------------------------------------------
31 #-----------------------------------------------------------------------------
25 # Classes and functions
32 # Classes and functions
@@ -165,7 +172,7 b' class TestsBase(object):'
165
172
166
173
167 def call(self, parameters, raise_on_error=True):
174 def call(self, parameters, raise_on_error=True):
168 stdout, stderr, retcode = get_output_error_code(parameters)
175 stdout, stderr, retcode = get_output_error_code(ipy_cmd + parameters)
169 if retcode != 0 and raise_on_error:
176 if retcode != 0 and raise_on_error:
170 raise OSError(stderr)
177 raise OSError(stderr)
171 return stdout, stderr
178 return stdout, stderr
@@ -16,7 +16,6 b' Contains tests for the nbconvertapp'
16 import os
16 import os
17 from .base import TestsBase
17 from .base import TestsBase
18
18
19 from IPython.utils import py3compat
20 from IPython.testing import decorators as dec
19 from IPython.testing import decorators as dec
21
20
22
21
@@ -24,12 +23,6 b' from IPython.testing import decorators as dec'
24 # Constants
23 # Constants
25 #-----------------------------------------------------------------------------
24 #-----------------------------------------------------------------------------
26
25
27 # Define ipython commandline name
28 if py3compat.PY3:
29 IPYTHON = 'ipython3'
30 else:
31 IPYTHON = 'ipython'
32
33
26
34 #-----------------------------------------------------------------------------
27 #-----------------------------------------------------------------------------
35 # Classes and functions
28 # Classes and functions
@@ -44,7 +37,7 b' class TestNbConvertApp(TestsBase):'
44 Will help show if no notebooks are specified?
37 Will help show if no notebooks are specified?
45 """
38 """
46 with self.create_temp_cwd():
39 with self.create_temp_cwd():
47 out, err = self.call(IPYTHON + ' nbconvert', raise_on_error=False)
40 out, err = self.call('nbconvert', raise_on_error=False)
48 assert "see '--help-all'" in out
41 assert "see '--help-all'" in out
49
42
50
43
@@ -53,8 +46,7 b' class TestNbConvertApp(TestsBase):'
53 Do search patterns work for notebook names?
46 Do search patterns work for notebook names?
54 """
47 """
55 with self.create_temp_cwd(['notebook*.ipynb']):
48 with self.create_temp_cwd(['notebook*.ipynb']):
56 self.call(IPYTHON + ' nbconvert --to="python"'
49 self.call('nbconvert --to="python" --notebooks=*.ipynb')
57 ' --notebooks=*.ipynb')
58 assert os.path.isfile('notebook1.py')
50 assert os.path.isfile('notebook1.py')
59 assert os.path.isfile('notebook2.py')
51 assert os.path.isfile('notebook2.py')
60
52
@@ -65,7 +57,7 b' class TestNbConvertApp(TestsBase):'
65 """
57 """
66 with self.create_temp_cwd():
58 with self.create_temp_cwd():
67 self.copy_files_to(['notebook*.ipynb'], 'subdir/')
59 self.copy_files_to(['notebook*.ipynb'], 'subdir/')
68 self.call(IPYTHON + ' nbconvert --to="python"'
60 self.call('nbconvert --to="python"'
69 ' --notebooks=%s' % os.path.join('subdir', '*.ipynb'))
61 ' --notebooks=%s' % os.path.join('subdir', '*.ipynb'))
70 assert os.path.isfile('notebook1.py')
62 assert os.path.isfile('notebook1.py')
71 assert os.path.isfile('notebook2.py')
63 assert os.path.isfile('notebook2.py')
@@ -76,8 +68,7 b' class TestNbConvertApp(TestsBase):'
76 Do explicit notebook names work?
68 Do explicit notebook names work?
77 """
69 """
78 with self.create_temp_cwd(['notebook*.ipynb']):
70 with self.create_temp_cwd(['notebook*.ipynb']):
79 self.call(IPYTHON + ' nbconvert --to="python"'
71 self.call('nbconvert --to="python" --notebooks=notebook2.ipynb')
80 ' --notebooks=notebook2.ipynb')
81 assert not os.path.isfile('notebook1.py')
72 assert not os.path.isfile('notebook1.py')
82 assert os.path.isfile('notebook2.py')
73 assert os.path.isfile('notebook2.py')
83
74
@@ -89,8 +80,8 b' class TestNbConvertApp(TestsBase):'
89 Do post processors work?
80 Do post processors work?
90 """
81 """
91 with self.create_temp_cwd(['notebook1.ipynb']):
82 with self.create_temp_cwd(['notebook1.ipynb']):
92 self.call(IPYTHON + ' nbconvert --to="latex" notebook1'
83 self.call('nbconvert --to="latex" notebook1'
93 ' --post="PDF" --PDFPostProcessor.verbose=True')
84 ' --post="PDF" --PDFPostProcessor.verbose=True')
94 assert os.path.isfile('notebook1.tex')
85 assert os.path.isfile('notebook1.tex')
95 print("\n\n\t" + "\n\t".join([f for f in os.listdir('.') if os.path.isfile(f)]) + "\n\n")
86 print("\n\n\t" + "\n\t".join([f for f in os.listdir('.') if os.path.isfile(f)]) + "\n\n")
96 assert os.path.isfile('notebook1.pdf')
87 assert os.path.isfile('notebook1.pdf')
@@ -102,9 +93,8 b' class TestNbConvertApp(TestsBase):'
102 Do export templates work?
93 Do export templates work?
103 """
94 """
104 with self.create_temp_cwd(['notebook2.ipynb']):
95 with self.create_temp_cwd(['notebook2.ipynb']):
105 self.call(IPYTHON + ' nbconvert --to=slides'
96 self.call('nbconvert --to=slides --notebooks=notebook2.ipynb'
106 ' --notebooks=notebook2.ipynb'
97 ' --template=reveal')
107 ' --template=reveal')
108 assert os.path.isfile('notebook2.slides.html')
98 assert os.path.isfile('notebook2.slides.html')
109 with open('notebook2.slides.html') as f:
99 with open('notebook2.slides.html') as f:
110 assert '/reveal.css' in f.read()
100 assert '/reveal.css' in f.read()
@@ -115,7 +105,7 b' class TestNbConvertApp(TestsBase):'
115 Can a search pattern be used along with matching explicit notebook names?
105 Can a search pattern be used along with matching explicit notebook names?
116 """
106 """
117 with self.create_temp_cwd(['notebook*.ipynb']):
107 with self.create_temp_cwd(['notebook*.ipynb']):
118 self.call(IPYTHON + ' nbconvert --to="python" --notebooks='
108 self.call('nbconvert --to="python" --notebooks='
119 '*.ipynb,notebook1.ipynb,notebook2.ipynb')
109 '*.ipynb,notebook1.ipynb,notebook2.ipynb')
120 assert os.path.isfile('notebook1.py')
110 assert os.path.isfile('notebook1.py')
121 assert os.path.isfile('notebook2.py')
111 assert os.path.isfile('notebook2.py')
@@ -126,7 +116,7 b' class TestNbConvertApp(TestsBase):'
126 Can explicit notebook names be used and then a matching search pattern?
116 Can explicit notebook names be used and then a matching search pattern?
127 """
117 """
128 with self.create_temp_cwd(['notebook*.ipynb']):
118 with self.create_temp_cwd(['notebook*.ipynb']):
129 self.call(IPYTHON + ' nbconvert --to="python" --notebooks='
119 self.call('nbconvert --to="python" --notebooks='
130 'notebook1.ipynb,notebook2.ipynb,*.ipynb')
120 'notebook1.ipynb,notebook2.ipynb,*.ipynb')
131 assert os.path.isfile('notebook1.py')
121 assert os.path.isfile('notebook1.py')
132 assert os.path.isfile('notebook2.py')
122 assert os.path.isfile('notebook2.py')
@@ -137,7 +127,7 b' class TestNbConvertApp(TestsBase):'
137 Does the default config work?
127 Does the default config work?
138 """
128 """
139 with self.create_temp_cwd(['notebook*.ipynb', 'ipython_nbconvert_config.py']):
129 with self.create_temp_cwd(['notebook*.ipynb', 'ipython_nbconvert_config.py']):
140 self.call(IPYTHON + ' nbconvert')
130 self.call('nbconvert')
141 assert os.path.isfile('notebook1.py')
131 assert os.path.isfile('notebook1.py')
142 assert not os.path.isfile('notebook2.py')
132 assert not os.path.isfile('notebook2.py')
143
133
@@ -149,6 +139,6 b' class TestNbConvertApp(TestsBase):'
149 with self.create_temp_cwd(['notebook*.ipynb',
139 with self.create_temp_cwd(['notebook*.ipynb',
150 'ipython_nbconvert_config.py',
140 'ipython_nbconvert_config.py',
151 'override.py']):
141 'override.py']):
152 self.call(IPYTHON + ' nbconvert --config="override.py"')
142 self.call('nbconvert --config="override.py"')
153 assert not os.path.isfile('notebook1.py')
143 assert not os.path.isfile('notebook1.py')
154 assert os.path.isfile('notebook2.py')
144 assert os.path.isfile('notebook2.py')
General Comments 0
You need to be logged in to leave comments. Login now