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