##// END OF EJS Templates
Merge pull request #6706 from jhamrick/display-prompt-numbers...
Thomas Kluyver -
r18350:ecca4c58 merge
parent child Browse files
Show More
@@ -0,0 +1,36 b''
1
2 // Test
3 casper.notebook_test(function () {
4
5 var that = this;
6 var set_prompt = function (i, val) {
7 that.evaluate(function (i, val) {
8 var cell = IPython.notebook.get_cell(i);
9 cell.set_input_prompt(val);
10 }, [i, val]);
11 };
12
13 var get_prompt = function (i) {
14 return that.evaluate(function (i) {
15 var elem = IPython.notebook.get_cell(i).element;
16 return elem.find('div.input_prompt').html();
17 }, [i]);
18 };
19
20 this.then(function () {
21 var a = 'print("a")';
22 var index = this.append_cell(a);
23
24 this.test.assertEquals(get_prompt(index), "In [ ]:", "prompt number is   by default");
25 set_prompt(index, 2);
26 this.test.assertEquals(get_prompt(index), "In [2]:", "prompt number is 2");
27 set_prompt(index, 0);
28 this.test.assertEquals(get_prompt(index), "In [0]:", "prompt number is 0");
29 set_prompt(index, "*");
30 this.test.assertEquals(get_prompt(index), "In [*]:", "prompt number is *");
31 set_prompt(index, undefined);
32 this.test.assertEquals(get_prompt(index), "In [ ]:", "prompt number is  ");
33 set_prompt(index, null);
34 this.test.assertEquals(get_prompt(index), "In [ ]:", "prompt number is  ");
35 });
36 });
@@ -0,0 +1,81 b''
1 {
2 "metadata": {
3 "name": "notebook2"
4 },
5 "nbformat": 3,
6 "nbformat_minor": 0,
7 "worksheets": [
8 {
9 "cells": [
10 {
11 "cell_type": "code",
12 "collapsed": false,
13 "input": [
14 "import numpy as np"
15 ],
16 "language": "python",
17 "metadata": {},
18 "outputs": [],
19 "prompt_number": 2
20 },
21 {
22 "cell_type": "code",
23 "collapsed": false,
24 "input": [
25 "evs = np.zeros(100)",
26 "evs.shape"
27 ],
28 "language": "python",
29 "metadata": {},
30 "outputs": [
31 {
32 "metadata": {},
33 "output_type": "pyout",
34 "prompt_number": 10,
35 "text": [
36 "(100,)"
37 ]
38 }
39 ],
40 "prompt_number": 10
41 },
42 {
43 "cell_type": "code",
44 "collapsed": false,
45 "input": [],
46 "language": "python",
47 "metadata": {},
48 "outputs": []
49 },
50 {
51 "cell_type": "code",
52 "collapsed": false,
53 "input": [],
54 "language": "python",
55 "metadata": {},
56 "outputs": [],
57 "prompt_number": null
58 },
59 {
60 "cell_type": "code",
61 "collapsed": false,
62 "input": [],
63 "language": "python",
64 "metadata": {},
65 "outputs": [],
66 "prompt_number": "*"
67 },
68 {
69 "cell_type": "code",
70 "collapsed": false,
71 "input": [],
72 "language": "python",
73 "metadata": {},
74 "outputs": [],
75 "prompt_number": 0
76 }
77 ],
78 "metadata": {}
79 }
80 ]
81 } No newline at end of file
@@ -410,7 +410,7 b' define(['
410
410
411 CodeCell.input_prompt_classical = function (prompt_value, lines_number) {
411 CodeCell.input_prompt_classical = function (prompt_value, lines_number) {
412 var ns;
412 var ns;
413 if (prompt_value === undefined) {
413 if (prompt_value === undefined || prompt_value === null) {
414 ns = " ";
414 ns = " ";
415 } else {
415 } else {
416 ns = encodeURIComponent(prompt_value);
416 ns = encodeURIComponent(prompt_value);
@@ -15,6 +15,7 b''
15 from .base import ExportersTestsBase
15 from .base import ExportersTestsBase
16 from ..html import HTMLExporter
16 from ..html import HTMLExporter
17 from IPython.testing.decorators import onlyif_any_cmd_exists
17 from IPython.testing.decorators import onlyif_any_cmd_exists
18 import re
18
19
19 #-----------------------------------------------------------------------------
20 #-----------------------------------------------------------------------------
20 # Class
21 # Class
@@ -59,3 +60,18 b' class TestHTMLExporter(ExportersTestsBase):'
59 (output, resources) = HTMLExporter(template_file='full').from_filename(self._get_notebook())
60 (output, resources) = HTMLExporter(template_file='full').from_filename(self._get_notebook())
60 assert len(output) > 0
61 assert len(output) > 0
61
62
63 @onlyif_any_cmd_exists('nodejs', 'node', 'pandoc')
64 def test_prompt_number(self):
65 """
66 Does HTMLExporter properly format input and output prompts?
67 """
68 (output, resources) = HTMLExporter(template_file='full').from_filename(
69 self._get_notebook(nb_name="prompt_numbers.ipynb"))
70 in_regex = r"In \[(.*)\]:"
71 out_regex = r"Out\[(.*)\]:"
72
73 ins = ["2", "10", " ", " ", "*", "0"]
74 outs = ["10"]
75
76 assert re.findall(in_regex, output) == ins
77 assert re.findall(out_regex, output) == outs
@@ -5,6 +5,7 b''
5
5
6 import os.path
6 import os.path
7 import textwrap
7 import textwrap
8 import re
8
9
9 from .base import ExportersTestsBase
10 from .base import ExportersTestsBase
10 from ..latex import LatexExporter
11 from ..latex import LatexExporter
@@ -99,3 +100,19 b' class TestLatexExporter(ExportersTestsBase):'
99
100
100 (output, resources) = LatexExporter(template_file='article').from_filename(nbfile)
101 (output, resources) = LatexExporter(template_file='article').from_filename(nbfile)
101 assert len(output) > 0
102 assert len(output) > 0
103
104 @onlyif_cmds_exist('pandoc')
105 def test_prompt_number_color(self):
106 """
107 Does LatexExporter properly format input and output prompts in color?
108 """
109 (output, resources) = LatexExporter().from_filename(
110 self._get_notebook(nb_name="prompt_numbers.ipynb"))
111 in_regex = r"In \[\{\\color\{incolor\}(.*)\}\]:"
112 out_regex = r"Out\[\{\\color\{outcolor\}(.*)\}\]:"
113
114 ins = ["2", "10", " ", " ", "*", "0"]
115 outs = ["10"]
116
117 assert re.findall(in_regex, output) == ins
118 assert re.findall(out_regex, output) == outs
@@ -23,7 +23,11 b''
23
23
24 {% block in_prompt -%}
24 {% block in_prompt -%}
25 <div class="prompt input_prompt">
25 <div class="prompt input_prompt">
26 In&nbsp;[{{ cell.prompt_number }}]:
26 {%- if cell.prompt_number is defined -%}
27 In&nbsp;[{{ cell.prompt_number|replace(None, "&nbsp;") }}]:
28 {%- else -%}
29 In&nbsp;[&nbsp;]:
30 {%- endif -%}
27 </div>
31 </div>
28 {%- endblock in_prompt %}
32 {%- endblock in_prompt %}
29
33
@@ -51,7 +55,11 b' In&nbsp;[{{ cell.prompt_number }}]:'
51 <div class="output_area">
55 <div class="output_area">
52 {%- if output.output_type == 'pyout' -%}
56 {%- if output.output_type == 'pyout' -%}
53 <div class="prompt output_prompt">
57 <div class="prompt output_prompt">
54 Out[{{ cell.prompt_number }}]:
58 {%- if cell.prompt_number is defined -%}
59 Out[{{ cell.prompt_number|replace(None, "&nbsp;") }}]:
60 {%- else -%}
61 Out[&nbsp;]:
62 {%- endif -%}
55 {%- else -%}
63 {%- else -%}
56 <div class="prompt">
64 <div class="prompt">
57 {%- endif -%}
65 {%- endif -%}
@@ -33,7 +33,11 b''
33 % Name: draw_prompt
33 % Name: draw_prompt
34 % Purpose: Renders an output/input prompt
34 % Purpose: Renders an output/input prompt
35 ((* macro add_prompt(text, cell, prompt) -*))
35 ((* macro add_prompt(text, cell, prompt) -*))
36 ((*- set prompt_number = "" ~ cell.prompt_number -*))
36 ((*- if cell.prompt_number is defined -*))
37 ((*- set prompt_number = "" ~ (cell.prompt_number | replace(None, " ")) -*))
38 ((*- else -*))
39 ((*- set prompt_number = " " -*))
40 ((*- endif -*))
37 ((*- set indentation = " " * (prompt_number | length + 7) -*))
41 ((*- set indentation = " " * (prompt_number | length + 7) -*))
38 \begin{verbatim}
42 \begin{verbatim}
39 (((- text | add_prompts(first=prompt ~ '[' ~ prompt_number ~ ']: ', cont=indentation) -)))
43 (((- text | add_prompts(first=prompt ~ '[' ~ prompt_number ~ ']: ', cont=indentation) -)))
@@ -46,7 +46,11 b''
46 % Name: draw_prompt
46 % Name: draw_prompt
47 % Purpose: Renders an output/input prompt
47 % Purpose: Renders an output/input prompt
48 ((* macro add_prompt(text, cell, prompt, prompt_color) -*))
48 ((* macro add_prompt(text, cell, prompt, prompt_color) -*))
49 ((*- set prompt_number = "" ~ cell.prompt_number -*))
49 ((*- if cell.prompt_number is defined -*))
50 ((*- set prompt_number = "" ~ (cell.prompt_number | replace(None, " ")) -*))
51 ((*- else -*))
52 ((*- set prompt_number = " " -*))
53 ((*- endif -*))
50 ((*- set indention = " " * (prompt_number | length + 7) -*))
54 ((*- set indention = " " * (prompt_number | length + 7) -*))
51 \begin{Verbatim}[commandchars=\\\{\}]
55 \begin{Verbatim}[commandchars=\\\{\}]
52 ((( text | add_prompts(first='{\color{' ~ prompt_color ~ '}' ~ prompt ~ '[{\\color{' ~ prompt_color ~ '}' ~ prompt_number ~ '}]:} ', cont=indention) )))
56 ((( text | add_prompts(first='{\color{' ~ prompt_color ~ '}' ~ prompt ~ '[{\\color{' ~ prompt_color ~ '}' ~ prompt_number ~ '}]:} ', cont=indention) )))
General Comments 0
You need to be logged in to leave comments. Login now