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