##// END OF EJS Templates
fix some validation bugs in v3...
MinRK -
Show More
@@ -1,27 +1,14 b''
1 """
1 """Tests for the coalescestreams preprocessor"""
2 Module with tests for the coalescestreams preprocessor
3 """
4
2
5 #-----------------------------------------------------------------------------
3 # Copyright (c) IPython Development Team.
6 # Copyright (c) 2013, the IPython Development Team.
7 #
8 # Distributed under the terms of the Modified BSD License.
4 # Distributed under the terms of the Modified BSD License.
9 #
10 # The full license is in the file COPYING.txt, distributed with this software.
11 #-----------------------------------------------------------------------------
12
5
13 #-----------------------------------------------------------------------------
14 # Imports
15 #-----------------------------------------------------------------------------
16 from IPython.nbformat import current as nbformat
6 from IPython.nbformat import current as nbformat
17
7
18 from .base import PreprocessorTestsBase
8 from .base import PreprocessorTestsBase
19 from ..coalescestreams import coalesce_streams
9 from ..coalescestreams import coalesce_streams
20
10
21
11
22 #-----------------------------------------------------------------------------
23 # Class
24 #-----------------------------------------------------------------------------
25 class TestCoalesceStreams(PreprocessorTestsBase):
12 class TestCoalesceStreams(PreprocessorTestsBase):
26 """Contains test functions for coalescestreams.py"""
13 """Contains test functions for coalescestreams.py"""
27
14
@@ -47,7 +34,7 b' class TestCoalesceStreams(PreprocessorTestsBase):'
47 nbformat.new_output(output_type="stream", stream="stdout", output_text="6"),
34 nbformat.new_output(output_type="stream", stream="stdout", output_text="6"),
48 nbformat.new_output(output_type="stream", stream="stdout", output_text="7")]
35 nbformat.new_output(output_type="stream", stream="stdout", output_text="7")]
49 cells=[nbformat.new_code_cell(input="# None", prompt_number=1,outputs=outputs)]
36 cells=[nbformat.new_code_cell(input="# None", prompt_number=1,outputs=outputs)]
50 worksheets = [nbformat.new_worksheet(name="worksheet1", cells=cells)]
37 worksheets = [nbformat.new_worksheet(cells=cells)]
51
38
52 nb = nbformat.new_notebook(name="notebook1", worksheets=worksheets)
39 nb = nbformat.new_notebook(name="notebook1", worksheets=worksheets)
53 res = self.build_resources()
40 res = self.build_resources()
@@ -64,7 +51,7 b' class TestCoalesceStreams(PreprocessorTestsBase):'
64 nbformat.new_output(output_type="stream", stream="stdout", output_text="\rc\n"),
51 nbformat.new_output(output_type="stream", stream="stdout", output_text="\rc\n"),
65 nbformat.new_output(output_type="stream", stream="stdout", output_text="z\rz\rd")]
52 nbformat.new_output(output_type="stream", stream="stdout", output_text="z\rz\rd")]
66 cells=[nbformat.new_code_cell(input="# None", prompt_number=1,outputs=outputs)]
53 cells=[nbformat.new_code_cell(input="# None", prompt_number=1,outputs=outputs)]
67 worksheets = [nbformat.new_worksheet(name="worksheet1", cells=cells)]
54 worksheets = [nbformat.new_worksheet(cells=cells)]
68
55
69 nb = nbformat.new_notebook(name="notebook1", worksheets=worksheets)
56 nb = nbformat.new_notebook(name="notebook1", worksheets=worksheets)
70 res = self.build_resources()
57 res = self.build_resources()
@@ -1,18 +1,7 b''
1 """
1 """Tests for the revealhelp preprocessor"""
2 Module with tests for the revealhelp preprocessor
3 """
4
2
5 #-----------------------------------------------------------------------------
3 # Copyright (c) IPython Development Team.
6 # Copyright (c) 2013, the IPython Development Team.
7 #
8 # Distributed under the terms of the Modified BSD License.
4 # Distributed under the terms of the Modified BSD License.
9 #
10 # The full license is in the file COPYING.txt, distributed with this software.
11 #-----------------------------------------------------------------------------
12
13 #-----------------------------------------------------------------------------
14 # Imports
15 #-----------------------------------------------------------------------------
16
5
17 from IPython.nbformat import current as nbformat
6 from IPython.nbformat import current as nbformat
18
7
@@ -20,10 +9,6 b' from .base import PreprocessorTestsBase'
20 from ..revealhelp import RevealHelpPreprocessor
9 from ..revealhelp import RevealHelpPreprocessor
21
10
22
11
23 #-----------------------------------------------------------------------------
24 # Class
25 #-----------------------------------------------------------------------------
26
27 class Testrevealhelp(PreprocessorTestsBase):
12 class Testrevealhelp(PreprocessorTestsBase):
28 """Contains test functions for revealhelp.py"""
13 """Contains test functions for revealhelp.py"""
29
14
@@ -41,7 +26,7 b' class Testrevealhelp(PreprocessorTestsBase):'
41 nbformat.new_code_cell(input="", prompt_number=2, outputs=outputs),
26 nbformat.new_code_cell(input="", prompt_number=2, outputs=outputs),
42 nbformat.new_text_cell('markdown', source="", metadata=slide_metadata),
27 nbformat.new_text_cell('markdown', source="", metadata=slide_metadata),
43 nbformat.new_text_cell('markdown', source="", metadata=subslide_metadata)]
28 nbformat.new_text_cell('markdown', source="", metadata=subslide_metadata)]
44 worksheets = [nbformat.new_worksheet(name="worksheet1", cells=cells)]
29 worksheets = [nbformat.new_worksheet(cells=cells)]
45
30
46 return nbformat.new_notebook(name="notebook1", worksheets=worksheets)
31 return nbformat.new_notebook(name="notebook1", worksheets=worksheets)
47
32
@@ -53,7 +53,6 b' def new_output(output_type, output_text=None, output_png=None,'
53 metadata = {}
53 metadata = {}
54 if not isinstance(metadata, dict):
54 if not isinstance(metadata, dict):
55 raise TypeError("metadata must be dict")
55 raise TypeError("metadata must be dict")
56 output.metadata = metadata
57
56
58 if output_type != 'pyerr':
57 if output_type != 'pyerr':
59 if output_text is not None:
58 if output_text is not None:
@@ -87,6 +86,8 b' def new_output(output_type, output_text=None, output_png=None,'
87
86
88 if output_type == u'stream':
87 if output_type == u'stream':
89 output.stream = 'stdout' if stream is None else cast_unicode(stream)
88 output.stream = 'stdout' if stream is None else cast_unicode(stream)
89 else:
90 output.metadata = metadata
90
91
91 return output
92 return output
92
93
@@ -121,21 +122,17 b' def new_text_cell(cell_type, source=None, rendered=None, metadata=None):'
121 cell_type = 'raw'
122 cell_type = 'raw'
122 if source is not None:
123 if source is not None:
123 cell.source = cast_unicode(source)
124 cell.source = cast_unicode(source)
124 if rendered is not None:
125 cell.rendered = cast_unicode(rendered)
126 cell.metadata = NotebookNode(metadata or {})
125 cell.metadata = NotebookNode(metadata or {})
127 cell.cell_type = cell_type
126 cell.cell_type = cell_type
128 return cell
127 return cell
129
128
130
129
131 def new_heading_cell(source=None, rendered=None, level=1, metadata=None):
130 def new_heading_cell(source=None, level=1, rendered=None, metadata=None):
132 """Create a new section cell with a given integer level."""
131 """Create a new section cell with a given integer level."""
133 cell = NotebookNode()
132 cell = NotebookNode()
134 cell.cell_type = u'heading'
133 cell.cell_type = u'heading'
135 if source is not None:
134 if source is not None:
136 cell.source = cast_unicode(source)
135 cell.source = cast_unicode(source)
137 if rendered is not None:
138 cell.rendered = cast_unicode(rendered)
139 cell.level = int(level)
136 cell.level = int(level)
140 cell.metadata = NotebookNode(metadata or {})
137 cell.metadata = NotebookNode(metadata or {})
141 return cell
138 return cell
@@ -144,8 +141,6 b' def new_heading_cell(source=None, rendered=None, level=1, metadata=None):'
144 def new_worksheet(name=None, cells=None, metadata=None):
141 def new_worksheet(name=None, cells=None, metadata=None):
145 """Create a worksheet by name with with a list of cells."""
142 """Create a worksheet by name with with a list of cells."""
146 ws = NotebookNode()
143 ws = NotebookNode()
147 if name is not None:
148 ws.name = cast_unicode(name)
149 if cells is None:
144 if cells is None:
150 ws.cells = []
145 ws.cells = []
151 else:
146 else:
@@ -117,7 +117,7 b''
117 "properties": {
117 "properties": {
118 "cell_type": {
118 "cell_type": {
119 "description": "String identifying the type of cell.",
119 "description": "String identifying the type of cell.",
120 "enum": ["markdown"]
120 "enum": ["markdown", "html"]
121 },
121 },
122 "metadata": {
122 "metadata": {
123 "description": "Cell-level metadata.",
123 "description": "Cell-level metadata.",
@@ -13,12 +13,11 b' from ..nbbase import ('
13 png = encodestring(os.urandom(5)).decode('ascii')
13 png = encodestring(os.urandom(5)).decode('ascii')
14 jpeg = encodestring(os.urandom(6)).decode('ascii')
14 jpeg = encodestring(os.urandom(6)).decode('ascii')
15
15
16 ws = new_worksheet(name='worksheet1')
16 ws = new_worksheet()
17
17
18 ws.cells.append(new_text_cell(
18 ws.cells.append(new_text_cell(
19 u'html',
19 u'html',
20 source='Some NumPy Examples',
20 source='Some NumPy Examples',
21 rendered='Some NumPy Examples'
22 ))
21 ))
23
22
24
23
@@ -31,7 +30,6 b' ws.cells.append(new_code_cell('
31 ws.cells.append(new_text_cell(
30 ws.cells.append(new_text_cell(
32 u'markdown',
31 u'markdown',
33 source='A random array',
32 source='A random array',
34 rendered='A random array'
35 ))
33 ))
36
34
37 ws.cells.append(new_text_cell(
35 ws.cells.append(new_text_cell(
@@ -70,7 +68,7 b' ws.cells.append(new_code_cell('
70 output_png=png,
68 output_png=png,
71 output_jpeg=jpeg,
69 output_jpeg=jpeg,
72 output_svg=u'<svg>',
70 output_svg=u'<svg>',
73 output_json=u'json data',
71 output_json=u'{"json": "data"}',
74 output_javascript=u'var i=0;',
72 output_javascript=u'var i=0;',
75 prompt_number=3
73 prompt_number=3
76 ),new_output(
74 ),new_output(
@@ -81,7 +79,7 b' ws.cells.append(new_code_cell('
81 output_png=png,
79 output_png=png,
82 output_jpeg=jpeg,
80 output_jpeg=jpeg,
83 output_svg=u'<svg>',
81 output_svg=u'<svg>',
84 output_json=u'json data',
82 output_json=u'{"json": "data"}',
85 output_javascript=u'var i=0;'
83 output_javascript=u'var i=0;'
86 ),new_output(
84 ),new_output(
87 output_type=u'pyerr',
85 output_type=u'pyerr',
@@ -104,7 +102,7 b" md = new_metadata(name=u'My Notebook',license=u'BSD',created=u'8601_goes_here',"
104 modified=u'8601_goes_here',gistid=u'21341231',authors=authors)
102 modified=u'8601_goes_here',gistid=u'21341231',authors=authors)
105
103
106 nb0 = new_notebook(
104 nb0 = new_notebook(
107 worksheets=[ws, new_worksheet(name='worksheet2')],
105 worksheets=[ws, new_worksheet()],
108 metadata=md
106 metadata=md
109 )
107 )
110
108
@@ -41,45 +41,37 b' class TestCell(TestCase):'
41 tc = new_text_cell(u'html')
41 tc = new_text_cell(u'html')
42 self.assertEqual(tc.cell_type, u'html')
42 self.assertEqual(tc.cell_type, u'html')
43 self.assertEqual(u'source' not in tc, True)
43 self.assertEqual(u'source' not in tc, True)
44 self.assertEqual(u'rendered' not in tc, True)
45
44
46 def test_html_cell(self):
45 def test_html_cell(self):
47 tc = new_text_cell(u'html', 'hi', 'hi')
46 tc = new_text_cell(u'html', 'hi')
48 self.assertEqual(tc.source, u'hi')
47 self.assertEqual(tc.source, u'hi')
49 self.assertEqual(tc.rendered, u'hi')
50
48
51 def test_empty_markdown_cell(self):
49 def test_empty_markdown_cell(self):
52 tc = new_text_cell(u'markdown')
50 tc = new_text_cell(u'markdown')
53 self.assertEqual(tc.cell_type, u'markdown')
51 self.assertEqual(tc.cell_type, u'markdown')
54 self.assertEqual(u'source' not in tc, True)
52 self.assertEqual(u'source' not in tc, True)
55 self.assertEqual(u'rendered' not in tc, True)
56
53
57 def test_markdown_cell(self):
54 def test_markdown_cell(self):
58 tc = new_text_cell(u'markdown', 'hi', 'hi')
55 tc = new_text_cell(u'markdown', 'hi')
59 self.assertEqual(tc.source, u'hi')
56 self.assertEqual(tc.source, u'hi')
60 self.assertEqual(tc.rendered, u'hi')
61
57
62 def test_empty_raw_cell(self):
58 def test_empty_raw_cell(self):
63 tc = new_text_cell(u'raw')
59 tc = new_text_cell(u'raw')
64 self.assertEqual(tc.cell_type, u'raw')
60 self.assertEqual(tc.cell_type, u'raw')
65 self.assertEqual(u'source' not in tc, True)
61 self.assertEqual(u'source' not in tc, True)
66 self.assertEqual(u'rendered' not in tc, True)
67
62
68 def test_raw_cell(self):
63 def test_raw_cell(self):
69 tc = new_text_cell(u'raw', 'hi', 'hi')
64 tc = new_text_cell(u'raw', 'hi')
70 self.assertEqual(tc.source, u'hi')
65 self.assertEqual(tc.source, u'hi')
71 self.assertEqual(tc.rendered, u'hi')
72
66
73 def test_empty_heading_cell(self):
67 def test_empty_heading_cell(self):
74 tc = new_heading_cell()
68 tc = new_heading_cell()
75 self.assertEqual(tc.cell_type, u'heading')
69 self.assertEqual(tc.cell_type, u'heading')
76 self.assertEqual(u'source' not in tc, True)
70 self.assertEqual(u'source' not in tc, True)
77 self.assertEqual(u'rendered' not in tc, True)
78
71
79 def test_heading_cell(self):
72 def test_heading_cell(self):
80 tc = new_heading_cell(u'hi', u'hi', level=2)
73 tc = new_heading_cell(u'hi', level=2)
81 self.assertEqual(tc.source, u'hi')
74 self.assertEqual(tc.source, u'hi')
82 self.assertEqual(tc.rendered, u'hi')
83 self.assertEqual(tc.level, 2)
75 self.assertEqual(tc.level, 2)
84
76
85
77
@@ -92,9 +84,8 b' class TestWorksheet(TestCase):'
92
84
93 def test_worksheet(self):
85 def test_worksheet(self):
94 cells = [new_code_cell(), new_text_cell(u'html')]
86 cells = [new_code_cell(), new_text_cell(u'html')]
95 ws = new_worksheet(cells=cells,name=u'foo')
87 ws = new_worksheet(cells=cells)
96 self.assertEqual(ws.cells,cells)
88 self.assertEqual(ws.cells,cells)
97 self.assertEqual(ws.name,u'foo')
98
89
99 class TestNotebook(TestCase):
90 class TestNotebook(TestCase):
100
91
General Comments 0
You need to be logged in to leave comments. Login now