From abc39be9e8accfb7350aaa9dd7de1366c33e1bf0 2012-11-16 20:32:07 From: Maximilian Albert Date: 2012-11-16 20:32:07 Subject: [PATCH] Quick fix for failing tests. This will be cleaned up soon. This is only a quick fix to make the tests pass. Note that some tests which access the 'prompt_number' attribute were not affected by the additional unexecuted cell in tests/test.ipynb which was added in commit ec19b407dee30fb7e692ce753af9fc5bd3808f8f. So this probably indicates that not all corner cases are covered. --- diff --git a/converters/python.py b/converters/python.py index 5b0bf2d..7607e05 100755 --- a/converters/python.py +++ b/converters/python.py @@ -33,16 +33,21 @@ class ConverterPy(Converter): return ['#{0} {1}'.format('#'*cell.level, cell.source), ''] def render_code(self, cell): + try: + prompt_number = cell.prompt_number + except AttributeError: + prompt_number = " " + if not cell.input: return [] lines = [] if self.show_prompts: - lines.extend(['# In[%s]:' % cell.prompt_number]) + lines.extend(['# In[%s]:' % prompt_number]) src = cell.input lines.extend([src, '']) if self.show_output: if cell.outputs : - lines.extend(['# Out[%s]:' % cell.prompt_number]) + lines.extend(['# Out[%s]:' % prompt_number]) for output in cell.outputs: conv_fn = self.dispatch(output.output_type) lines.extend(conv_fn(output)) diff --git a/converters/rst.py b/converters/rst.py index 1e626ee..09ddcaf 100755 --- a/converters/rst.py +++ b/converters/rst.py @@ -11,10 +11,16 @@ class ConverterRST(Converter): return ['{0}\n{1}\n'.format(cell.source, marker * len(cell.source))] def render_code(self, cell): + # Note: cell has type 'IPython.nbformat.v3.nbbase.NotebookNode' if not cell.input: return [] - lines = ['In[%s]:' % cell.prompt_number, ''] + try: + prompt_number = cell.prompt_number + except AttributeError: + prompt_number = " " + + lines = ['In[%s]:' % prompt_number, ''] lines.extend(rst_directive('.. code:: python', cell.input)) for output in cell.outputs: