Show More
@@ -147,10 +147,10 b' class NotebookManager(LoggingConfigurable):' | |||||
147 |
|
147 | |||
148 | if name is None: |
|
148 | if name is None: | |
149 | try: |
|
149 | try: | |
150 | name = nb.name |
|
150 | name = nb.metadata.name | |
151 | except AttributeError: |
|
151 | except AttributeError: | |
152 | raise web.HTTPError(400) |
|
152 | raise web.HTTPError(400) | |
153 | nb.name = name |
|
153 | nb.metadata.name = name | |
154 |
|
154 | |||
155 | notebook_id = self.new_notebook_id(name) |
|
155 | notebook_id = self.new_notebook_id(name) | |
156 | self.save_notebook_object(notebook_id, nb) |
|
156 | self.save_notebook_object(notebook_id, nb) | |
@@ -167,7 +167,7 b' class NotebookManager(LoggingConfigurable):' | |||||
167 | raise web.HTTPError(400) |
|
167 | raise web.HTTPError(400) | |
168 |
|
168 | |||
169 | if name is not None: |
|
169 | if name is not None: | |
170 | nb.name = name |
|
170 | nb.metadata.name = name | |
171 | self.save_notebook_object(notebook_id, nb) |
|
171 | self.save_notebook_object(notebook_id, nb) | |
172 |
|
172 | |||
173 | def save_notebook_object(self, notebook_id, nb): |
|
173 | def save_notebook_object(self, notebook_id, nb): | |
@@ -176,7 +176,7 b' class NotebookManager(LoggingConfigurable):' | |||||
176 | raise web.HTTPError(404) |
|
176 | raise web.HTTPError(404) | |
177 | old_name = self.mapping[notebook_id] |
|
177 | old_name = self.mapping[notebook_id] | |
178 | try: |
|
178 | try: | |
179 | new_name = nb.name |
|
179 | new_name = nb.metadata.name | |
180 | except AttributeError: |
|
180 | except AttributeError: | |
181 | raise web.HTTPError(400) |
|
181 | raise web.HTTPError(400) | |
182 | path = self.get_path_by_name(new_name) |
|
182 | path = self.get_path_by_name(new_name) |
@@ -21,6 +21,7 b' var IPython = (function (IPython) {' | |||||
21 | this.kernel = null; |
|
21 | this.kernel = null; | |
22 | this.dirty = false; |
|
22 | this.dirty = false; | |
23 | this.msg_cell_map = {}; |
|
23 | this.msg_cell_map = {}; | |
|
24 | this.metadata = {}; | |||
24 | this.style(); |
|
25 | this.style(); | |
25 | this.create_elements(); |
|
26 | this.create_elements(); | |
26 | this.bind_events(); |
|
27 | this.bind_events(); | |
@@ -711,6 +712,8 b' var IPython = (function (IPython) {' | |||||
711 | // Always delete cell 0 as they get renumbered as they are deleted. |
|
712 | // Always delete cell 0 as they get renumbered as they are deleted. | |
712 | this.delete_cell(0); |
|
713 | this.delete_cell(0); | |
713 | }; |
|
714 | }; | |
|
715 | // Save the metadata | |||
|
716 | this.metadata = data.metadata; | |||
714 | // Only handle 1 worksheet for now. |
|
717 | // Only handle 1 worksheet for now. | |
715 | var worksheet = data.worksheets[0]; |
|
718 | var worksheet = data.worksheets[0]; | |
716 | if (worksheet !== undefined) { |
|
719 | if (worksheet !== undefined) { | |
@@ -744,7 +747,8 b' var IPython = (function (IPython) {' | |||||
744 | }; |
|
747 | }; | |
745 | data = { |
|
748 | data = { | |
746 | // Only handle 1 worksheet for now. |
|
749 | // Only handle 1 worksheet for now. | |
747 | worksheets : [{cells:cell_array}] |
|
750 | worksheets : [{cells:cell_array}], | |
|
751 | metadata : this.metadata | |||
748 | } |
|
752 | } | |
749 | return data |
|
753 | return data | |
750 | }; |
|
754 | }; | |
@@ -755,7 +759,7 b' var IPython = (function (IPython) {' | |||||
755 | var nbname = IPython.save_widget.get_notebook_name(); |
|
759 | var nbname = IPython.save_widget.get_notebook_name(); | |
756 | // We may want to move the name/id/nbformat logic inside toJSON? |
|
760 | // We may want to move the name/id/nbformat logic inside toJSON? | |
757 | var data = this.toJSON(); |
|
761 | var data = this.toJSON(); | |
758 | data.name = nbname; |
|
762 | data.metadata.name = nbname; | |
759 | data.nbformat = 2; |
|
763 | data.nbformat = 2; | |
760 | // We do the call with settings so we can set cache to false. |
|
764 | // We do the call with settings so we can set cache to false. | |
761 | var settings = { |
|
765 | var settings = { | |
@@ -805,7 +809,7 b' var IPython = (function (IPython) {' | |||||
805 | this.insert_code_cell_after(); |
|
809 | this.insert_code_cell_after(); | |
806 | }; |
|
810 | }; | |
807 | IPython.save_widget.status_save(); |
|
811 | IPython.save_widget.status_save(); | |
808 | IPython.save_widget.set_notebook_name(data.name); |
|
812 | IPython.save_widget.set_notebook_name(data.metadata.name); | |
809 | this.start_kernel(); |
|
813 | this.start_kernel(); | |
810 | this.dirty = false; |
|
814 | this.dirty = false; | |
811 | // fromJSON always selects the last cell inserted. We need to wait |
|
815 | // fromJSON always selects the last cell inserted. We need to wait |
@@ -16,6 +16,7 b' Authors:' | |||||
16 | # Imports |
|
16 | # Imports | |
17 | #----------------------------------------------------------------------------- |
|
17 | #----------------------------------------------------------------------------- | |
18 |
|
18 | |||
|
19 | from __future__ import print_function | |||
19 | import json |
|
20 | import json | |
20 | from xml.etree import ElementTree as ET |
|
21 | from xml.etree import ElementTree as ET | |
21 | import re |
|
22 | import re | |
@@ -26,7 +27,7 b' from IPython.nbformat import v1' | |||||
26 | from IPython.nbformat.v2 import ( |
|
27 | from IPython.nbformat.v2 import ( | |
27 | NotebookNode, |
|
28 | NotebookNode, | |
28 | new_code_cell, new_text_cell, new_notebook, new_output, new_worksheet, |
|
29 | new_code_cell, new_text_cell, new_notebook, new_output, new_worksheet, | |
29 | parse_filename |
|
30 | parse_filename, new_metadata, new_author | |
30 | ) |
|
31 | ) | |
31 |
|
32 | |||
32 | #----------------------------------------------------------------------------- |
|
33 | #----------------------------------------------------------------------------- | |
@@ -96,10 +97,6 b' def reads_xml(s, **kwargs):' | |||||
96 | return nb |
|
97 | return nb | |
97 |
|
98 | |||
98 |
|
99 | |||
99 | def writes_xml(nb, **kwargs): |
|
|||
100 | return v2.writes_xml(nb, **kwargs) |
|
|||
101 |
|
||||
102 |
|
||||
103 | def reads_py(s, **kwargs): |
|
100 | def reads_py(s, **kwargs): | |
104 | """Read a .py notebook from a string and return the NotebookNode object.""" |
|
101 | """Read a .py notebook from a string and return the NotebookNode object.""" | |
105 | nbformat, s = parse_py(s, **kwargs) |
|
102 | nbformat, s = parse_py(s, **kwargs) | |
@@ -125,9 +122,9 b' def reads(s, format, **kwargs):' | |||||
125 |
|
122 | |||
126 | Parameters |
|
123 | Parameters | |
127 | ---------- |
|
124 | ---------- | |
128 |
s : |
|
125 | s : unicode | |
129 | The raw string to read the notebook from. |
|
126 | The raw unicode string to read the notebook from. | |
130 | format : ('json','py') |
|
127 | format : (u'json', u'ipynb', u'py') | |
131 | The format that the string is in. |
|
128 | The format that the string is in. | |
132 |
|
129 | |||
133 | Returns |
|
130 | Returns | |
@@ -135,11 +132,12 b' def reads(s, format, **kwargs):' | |||||
135 | nb : NotebookNode |
|
132 | nb : NotebookNode | |
136 | The notebook that was read. |
|
133 | The notebook that was read. | |
137 | """ |
|
134 | """ | |
138 | if format == 'xml': |
|
135 | format = unicode(format) | |
|
136 | if format == u'xml': | |||
139 | return reads_xml(s, **kwargs) |
|
137 | return reads_xml(s, **kwargs) | |
140 | elif format == 'json': |
|
138 | elif format == u'json' or format == u'ipynb': | |
141 | return reads_json(s, **kwargs) |
|
139 | return reads_json(s, **kwargs) | |
142 | elif format == 'py': |
|
140 | elif format == u'py': | |
143 | return reads_py(s, **kwargs) |
|
141 | return reads_py(s, **kwargs) | |
144 | else: |
|
142 | else: | |
145 | raise NBFormatError('Unsupported format: %s' % format) |
|
143 | raise NBFormatError('Unsupported format: %s' % format) | |
@@ -154,19 +152,20 b' def writes(nb, format, **kwargs):' | |||||
154 | ---------- |
|
152 | ---------- | |
155 | nb : NotebookNode |
|
153 | nb : NotebookNode | |
156 | The notebook to write. |
|
154 | The notebook to write. | |
157 | format : ('json','py') |
|
155 | format : (u'json', u'ipynb', u'py') | |
158 | The format to write the notebook in. |
|
156 | The format to write the notebook in. | |
159 |
|
157 | |||
160 | Returns |
|
158 | Returns | |
161 | ------- |
|
159 | ------- | |
162 |
s : |
|
160 | s : unicode | |
163 | The notebook string. |
|
161 | The notebook string. | |
164 | """ |
|
162 | """ | |
165 | if format == 'xml': |
|
163 | format = unicode(format) | |
166 | return writes_xml(nb, **kwargs) |
|
164 | if format == u'xml': | |
167 | elif format == 'json': |
|
165 | raise NotImplementedError('Write to XML files is not implemented.') | |
|
166 | elif format == u'json' or format == u'ipynb': | |||
168 | return writes_json(nb, **kwargs) |
|
167 | return writes_json(nb, **kwargs) | |
169 | elif format == 'py': |
|
168 | elif format == u'py': | |
170 | return writes_py(nb, **kwargs) |
|
169 | return writes_py(nb, **kwargs) | |
171 | else: |
|
170 | else: | |
172 | raise NBFormatError('Unsupported format: %s' % format) |
|
171 | raise NBFormatError('Unsupported format: %s' % format) | |
@@ -182,7 +181,7 b' def read(fp, format, **kwargs):' | |||||
182 | ---------- |
|
181 | ---------- | |
183 | fp : file |
|
182 | fp : file | |
184 | Any file-like object with a read method. |
|
183 | Any file-like object with a read method. | |
185 | format : ('json','py') |
|
184 | format : (u'json', u'ipynb', u'py') | |
186 | The format that the string is in. |
|
185 | The format that the string is in. | |
187 |
|
186 | |||
188 | Returns |
|
187 | Returns | |
@@ -204,14 +203,28 b' def write(nb, fp, format, **kwargs):' | |||||
204 | The notebook to write. |
|
203 | The notebook to write. | |
205 | fp : file |
|
204 | fp : file | |
206 | Any file-like object with a write method. |
|
205 | Any file-like object with a write method. | |
207 | format : ('json','py') |
|
206 | format : (u'json', u'ipynb', u'py') | |
208 | The format to write the notebook in. |
|
207 | The format to write the notebook in. | |
209 |
|
208 | |||
210 | Returns |
|
209 | Returns | |
211 | ------- |
|
210 | ------- | |
212 |
s : |
|
211 | s : unicode | |
213 | The notebook string. |
|
212 | The notebook string. | |
214 | """ |
|
213 | """ | |
215 | return fp.write(writes(nb, format, **kwargs)) |
|
214 | return fp.write(writes(nb, format, **kwargs)) | |
216 |
|
215 | |||
|
216 | def _convert_to_metadata(): | |||
|
217 | """Convert to a notebook having notebook metadata.""" | |||
|
218 | import glob | |||
|
219 | for fname in glob.glob('*.ipynb'): | |||
|
220 | print('Converting file:',fname) | |||
|
221 | with open(fname,'r') as f: | |||
|
222 | nb = read(f,u'json') | |||
|
223 | md = new_metadata() | |||
|
224 | if u'name' in nb: | |||
|
225 | md.name = nb.name | |||
|
226 | del nb[u'name'] | |||
|
227 | nb.metadata = md | |||
|
228 | with open(fname,'w') as f: | |||
|
229 | write(nb, f, u'json') | |||
217 |
|
230 |
@@ -18,15 +18,16 b' Authors:' | |||||
18 |
|
18 | |||
19 | from .nbbase import ( |
|
19 | from .nbbase import ( | |
20 | NotebookNode, |
|
20 | NotebookNode, | |
21 | new_code_cell, new_text_cell, new_notebook, new_output, new_worksheet |
|
21 | new_code_cell, new_text_cell, new_notebook, new_output, new_worksheet, | |
|
22 | new_metadata, new_author | |||
22 | ) |
|
23 | ) | |
23 |
|
24 | |||
24 | from .nbjson import reads as reads_json, writes as writes_json |
|
25 | from .nbjson import reads as reads_json, writes as writes_json | |
25 | from .nbjson import reads as read_json, writes as write_json |
|
26 | from .nbjson import reads as read_json, writes as write_json | |
26 | from .nbjson import to_notebook as to_notebook_json |
|
27 | from .nbjson import to_notebook as to_notebook_json | |
27 |
|
28 | |||
28 |
from .nbxml import reads as reads_xml |
|
29 | from .nbxml import reads as reads_xml | |
29 |
from .nbxml import reads as read_xml |
|
30 | from .nbxml import reads as read_xml | |
30 | from .nbxml import to_notebook as to_notebook_xml |
|
31 | from .nbxml import to_notebook as to_notebook_xml | |
31 |
|
32 | |||
32 | from .nbpy import reads as reads_py, writes as writes_py |
|
33 | from .nbpy import reads as reads_py, writes as writes_py |
@@ -131,26 +131,49 b' def new_worksheet(name=None, cells=None):' | |||||
131 | return ws |
|
131 | return ws | |
132 |
|
132 | |||
133 |
|
133 | |||
134 |
def new_notebook( |
|
134 | def new_notebook(metadata=None, worksheets=None): | |
135 | created=None, saved=None, license=None): |
|
|||
136 | """Create a notebook by name, id and a list of worksheets.""" |
|
135 | """Create a notebook by name, id and a list of worksheets.""" | |
137 | nb = NotebookNode() |
|
136 | nb = NotebookNode() | |
138 | nb.nbformat = 2 |
|
137 | nb.nbformat = 2 | |
139 | if name is not None: |
|
|||
140 | nb.name = unicode(name) |
|
|||
141 | if worksheets is None: |
|
138 | if worksheets is None: | |
142 | nb.worksheets = [] |
|
139 | nb.worksheets = [] | |
143 | else: |
|
140 | else: | |
144 | nb.worksheets = list(worksheets) |
|
141 | nb.worksheets = list(worksheets) | |
145 |
if |
|
142 | if metadata is None: | |
146 | nb.author = unicode(author) |
|
143 | nb.metadata = new_metadata() | |
147 | if email is not None: |
|
144 | else: | |
148 | nb.email = unicode(email) |
|
145 | nb.metadata = NotebookNode(metadata) | |
|
146 | return nb | |||
|
147 | ||||
|
148 | ||||
|
149 | def new_metadata(name=None, authors=None, license=None, created=None, | |||
|
150 | modified=None, gistid=None): | |||
|
151 | """Create a new metadata node.""" | |||
|
152 | metadata = NotebookNode() | |||
|
153 | if name is not None: | |||
|
154 | metadata.name = unicode(name) | |||
|
155 | if authors is not None: | |||
|
156 | metadata.authors = list(authors) | |||
149 | if created is not None: |
|
157 | if created is not None: | |
150 |
|
|
158 | metadata.created = unicode(created) | |
151 |
if |
|
159 | if modified is not None: | |
152 |
|
|
160 | metadata.modified = unicode(modified) | |
153 | if license is not None: |
|
161 | if license is not None: | |
154 |
|
|
162 | metadata.license = unicode(license) | |
155 | return nb |
|
163 | if gistid is not None: | |
|
164 | metadata.gistid = unicode(gistid) | |||
|
165 | return metadata | |||
|
166 | ||||
|
167 | def new_author(name=None, email=None, affiliation=None, url=None): | |||
|
168 | """Create a new author.""" | |||
|
169 | author = NotebookNode() | |||
|
170 | if name is not None: | |||
|
171 | author.name = unicode(name) | |||
|
172 | if email is not None: | |||
|
173 | author.email = unicode(email) | |||
|
174 | if affiliation is not None: | |||
|
175 | author.affiliation = unicode(affiliation) | |||
|
176 | if url is not None: | |||
|
177 | author.url = unicode(url) | |||
|
178 | return author | |||
156 |
|
179 |
@@ -178,74 +178,10 b' class XMLReader(NotebookReader):' | |||||
178 | email=nbemail,license=nblicense,saved=nbsaved,created=nbcreated) |
|
178 | email=nbemail,license=nblicense,saved=nbsaved,created=nbcreated) | |
179 | return nb |
|
179 | return nb | |
180 |
|
180 | |||
181 |
|
181 | |||
182 | class XMLWriter(NotebookWriter): |
|
|||
183 |
|
||||
184 | def writes(self, nb, **kwargs): |
|
|||
185 | warnings.warn('The XML notebook format is no longer supported, ' |
|
|||
186 | 'please convert your notebooks to JSON.', DeprecationWarning) |
|
|||
187 | nb_e = ET.Element(u'notebook') |
|
|||
188 | _set_text(nb,u'name',nb_e,u'name') |
|
|||
189 | _set_text(nb,u'author',nb_e,u'author') |
|
|||
190 | _set_text(nb,u'email',nb_e,u'email') |
|
|||
191 | _set_text(nb,u'license',nb_e,u'license') |
|
|||
192 | _set_text(nb,u'created',nb_e,u'created') |
|
|||
193 | _set_text(nb,u'saved',nb_e,u'saved') |
|
|||
194 | _set_int(nb,u'nbformat',nb_e,u'nbformat') |
|
|||
195 | wss_e = ET.SubElement(nb_e,u'worksheets') |
|
|||
196 | for ws in nb.worksheets: |
|
|||
197 | ws_e = ET.SubElement(wss_e, u'worksheet') |
|
|||
198 | _set_text(ws,u'name',ws_e,u'name') |
|
|||
199 | cells_e = ET.SubElement(ws_e,u'cells') |
|
|||
200 | for cell in ws.cells: |
|
|||
201 | cell_type = cell.cell_type |
|
|||
202 | if cell_type == u'code': |
|
|||
203 | cell_e = ET.SubElement(cells_e, u'codecell') |
|
|||
204 | _set_text(cell,u'input',cell_e,u'input') |
|
|||
205 | _set_text(cell,u'language',cell_e,u'language') |
|
|||
206 | _set_int(cell,u'prompt_number',cell_e,u'prompt_number') |
|
|||
207 | _set_bool(cell,u'collapsed',cell_e,u'collapsed') |
|
|||
208 | outputs_e = ET.SubElement(cell_e, u'outputs') |
|
|||
209 | for output in cell.outputs: |
|
|||
210 | output_e = ET.SubElement(outputs_e, u'output') |
|
|||
211 | _set_text(output,u'output_type',output_e,u'output_type') |
|
|||
212 | _set_text(output,u'text',output_e,u'text') |
|
|||
213 | _set_binary(output,u'png',output_e,u'png') |
|
|||
214 | _set_binary(output,u'jpeg',output_e,u'jpeg') |
|
|||
215 | _set_text(output,u'html',output_e,u'html') |
|
|||
216 | _set_text(output,u'svg',output_e,u'svg') |
|
|||
217 | _set_text(output,u'latex',output_e,u'latex') |
|
|||
218 | _set_text(output,u'json',output_e,u'json') |
|
|||
219 | _set_text(output,u'javascript',output_e,u'javascript') |
|
|||
220 | _set_int(output,u'prompt_number',output_e,u'prompt_number') |
|
|||
221 | _set_text(output,u'etype',output_e,u'etype') |
|
|||
222 | _set_text(output,u'evalue',output_e,u'evalue') |
|
|||
223 | if u'traceback' in output: |
|
|||
224 | tb_e = ET.SubElement(output_e, u'traceback') |
|
|||
225 | for frame in output.traceback: |
|
|||
226 | frame_e = ET.SubElement(tb_e, u'frame') |
|
|||
227 | frame_e.text = frame |
|
|||
228 | elif cell_type == u'html': |
|
|||
229 | cell_e = ET.SubElement(cells_e, u'htmlcell') |
|
|||
230 | _set_text(cell,u'source',cell_e,u'source') |
|
|||
231 | _set_text(cell,u'rendered',cell_e,u'rendered') |
|
|||
232 | elif cell_type == u'markdown': |
|
|||
233 | cell_e = ET.SubElement(cells_e, u'markdowncell') |
|
|||
234 | _set_text(cell,u'source',cell_e,u'source') |
|
|||
235 | _set_text(cell,u'rendered',cell_e,u'rendered') |
|
|||
236 |
|
||||
237 | indent(nb_e) |
|
|||
238 | txt = ET.tostring(nb_e, encoding="utf-8") |
|
|||
239 | txt = '<?xml version="1.0" encoding="utf-8"?>\n' + txt |
|
|||
240 | return txt |
|
|||
241 |
|
||||
242 |
|
||||
243 | _reader = XMLReader() |
|
182 | _reader = XMLReader() | |
244 | _writer = XMLWriter() |
|
|||
245 |
|
183 | |||
246 | reads = _reader.reads |
|
184 | reads = _reader.reads | |
247 | read = _reader.read |
|
185 | read = _reader.read | |
248 | to_notebook = _reader.to_notebook |
|
186 | to_notebook = _reader.to_notebook | |
249 | write = _writer.write |
|
|||
250 | writes = _writer.writes |
|
|||
251 |
|
187 |
@@ -1,6 +1,7 b'' | |||||
1 | from ..nbbase import ( |
|
1 | from ..nbbase import ( | |
2 | NotebookNode, |
|
2 | NotebookNode, | |
3 | new_code_cell, new_text_cell, new_worksheet, new_notebook, new_output |
|
3 | new_code_cell, new_text_cell, new_worksheet, new_notebook, new_output, | |
|
4 | new_metadata, new_author | |||
4 | ) |
|
5 | ) | |
5 |
|
6 | |||
6 |
|
7 | |||
@@ -65,14 +66,14 b' ws.cells.append(new_code_cell(' | |||||
65 | )] |
|
66 | )] | |
66 | )) |
|
67 | )) | |
67 |
|
68 | |||
|
69 | authors = [new_author(name='Bart Simpson',email='bsimpson@fox.com', | |||
|
70 | affiliation=u'Fox',url=u'http://www.fox.com')] | |||
|
71 | md = new_metadata(name=u'My Notebook',license=u'BSD',created=u'8601_goes_here', | |||
|
72 | modified=u'8601_goes_here',gistid=u'21341231',authors=authors) | |||
|
73 | ||||
68 | nb0 = new_notebook( |
|
74 | nb0 = new_notebook( | |
69 | name='nb0', |
|
|||
70 | worksheets=[ws, new_worksheet(name='worksheet2')], |
|
75 | worksheets=[ws, new_worksheet(name='worksheet2')], | |
71 | author='Bart Simpson', |
|
76 | metadata=md | |
72 | email='bsimpson@fox.com', |
|
|||
73 | saved='ISO8601_goes_here', |
|
|||
74 | created='ISO8601_goes_here', |
|
|||
75 | license='BSD' |
|
|||
76 | ) |
|
77 | ) | |
77 |
|
78 | |||
78 | nb0_py = """# <nbformat>2</nbformat> |
|
79 | nb0_py = """# <nbformat>2</nbformat> |
@@ -2,23 +2,24 b' from unittest import TestCase' | |||||
2 |
|
2 | |||
3 | from ..nbbase import ( |
|
3 | from ..nbbase import ( | |
4 | NotebookNode, |
|
4 | NotebookNode, | |
5 | new_code_cell, new_text_cell, new_worksheet, new_notebook, new_output |
|
5 | new_code_cell, new_text_cell, new_worksheet, new_notebook, new_output, | |
|
6 | new_author, new_metadata | |||
6 | ) |
|
7 | ) | |
7 |
|
8 | |||
8 | class TestCell(TestCase): |
|
9 | class TestCell(TestCase): | |
9 |
|
10 | |||
10 | def test_empty_code_cell(self): |
|
11 | def test_empty_code_cell(self): | |
11 | cc = new_code_cell() |
|
12 | cc = new_code_cell() | |
12 | self.assertEquals(cc.cell_type,'code') |
|
13 | self.assertEquals(cc.cell_type,u'code') | |
13 | self.assertEquals('input' not in cc, True) |
|
14 | self.assertEquals(u'input' not in cc, True) | |
14 | self.assertEquals('prompt_number' not in cc, True) |
|
15 | self.assertEquals(u'prompt_number' not in cc, True) | |
15 | self.assertEquals(cc.outputs, []) |
|
16 | self.assertEquals(cc.outputs, []) | |
16 | self.assertEquals(cc.collapsed, False) |
|
17 | self.assertEquals(cc.collapsed, False) | |
17 |
|
18 | |||
18 | def test_code_cell(self): |
|
19 | def test_code_cell(self): | |
19 | cc = new_code_cell(input='a=10', prompt_number=0, collapsed=True) |
|
20 | cc = new_code_cell(input='a=10', prompt_number=0, collapsed=True) | |
20 | cc.outputs = [new_output(output_type='pyout', |
|
21 | cc.outputs = [new_output(output_type=u'pyout', | |
21 | output_svg='foo',output_text='10',prompt_number=0)] |
|
22 | output_svg=u'foo',output_text=u'10',prompt_number=0)] | |
22 | self.assertEquals(cc.input, u'a=10') |
|
23 | self.assertEquals(cc.input, u'a=10') | |
23 | self.assertEquals(cc.prompt_number, 0) |
|
24 | self.assertEquals(cc.prompt_number, 0) | |
24 | self.assertEquals(cc.language, u'python') |
|
25 | self.assertEquals(cc.language, u'python') | |
@@ -39,8 +40,8 b' class TestCell(TestCase):' | |||||
39 | def test_empty_html_cell(self): |
|
40 | def test_empty_html_cell(self): | |
40 | tc = new_text_cell(u'html') |
|
41 | tc = new_text_cell(u'html') | |
41 | self.assertEquals(tc.cell_type, u'html') |
|
42 | self.assertEquals(tc.cell_type, u'html') | |
42 | self.assertEquals('source' not in tc, True) |
|
43 | self.assertEquals(u'source' not in tc, True) | |
43 | self.assertEquals('rendered' not in tc, True) |
|
44 | self.assertEquals(u'rendered' not in tc, True) | |
44 |
|
45 | |||
45 | def test_html_cell(self): |
|
46 | def test_html_cell(self): | |
46 | tc = new_text_cell(u'html', 'hi', 'hi') |
|
47 | tc = new_text_cell(u'html', 'hi', 'hi') | |
@@ -50,8 +51,8 b' class TestCell(TestCase):' | |||||
50 | def test_empty_markdown_cell(self): |
|
51 | def test_empty_markdown_cell(self): | |
51 | tc = new_text_cell(u'markdown') |
|
52 | tc = new_text_cell(u'markdown') | |
52 | self.assertEquals(tc.cell_type, u'markdown') |
|
53 | self.assertEquals(tc.cell_type, u'markdown') | |
53 | self.assertEquals('source' not in tc, True) |
|
54 | self.assertEquals(u'source' not in tc, True) | |
54 | self.assertEquals('rendered' not in tc, True) |
|
55 | self.assertEquals(u'rendered' not in tc, True) | |
55 |
|
56 | |||
56 | def test_markdown_cell(self): |
|
57 | def test_markdown_cell(self): | |
57 | tc = new_text_cell(u'markdown', 'hi', 'hi') |
|
58 | tc = new_text_cell(u'markdown', 'hi', 'hi') | |
@@ -64,11 +65,11 b' class TestWorksheet(TestCase):' | |||||
64 | def test_empty_worksheet(self): |
|
65 | def test_empty_worksheet(self): | |
65 | ws = new_worksheet() |
|
66 | ws = new_worksheet() | |
66 | self.assertEquals(ws.cells,[]) |
|
67 | self.assertEquals(ws.cells,[]) | |
67 | self.assertEquals('name' not in ws, True) |
|
68 | self.assertEquals(u'name' not in ws, True) | |
68 |
|
69 | |||
69 | def test_worksheet(self): |
|
70 | def test_worksheet(self): | |
70 | cells = [new_code_cell(), new_text_cell(u'html')] |
|
71 | cells = [new_code_cell(), new_text_cell(u'html')] | |
71 | ws = new_worksheet(cells=cells,name='foo') |
|
72 | ws = new_worksheet(cells=cells,name=u'foo') | |
72 | self.assertEquals(ws.cells,cells) |
|
73 | self.assertEquals(ws.cells,cells) | |
73 | self.assertEquals(ws.name,u'foo') |
|
74 | self.assertEquals(ws.name,u'foo') | |
74 |
|
75 | |||
@@ -77,13 +78,36 b' class TestNotebook(TestCase):' | |||||
77 | def test_empty_notebook(self): |
|
78 | def test_empty_notebook(self): | |
78 | nb = new_notebook() |
|
79 | nb = new_notebook() | |
79 | self.assertEquals(nb.worksheets, []) |
|
80 | self.assertEquals(nb.worksheets, []) | |
80 |
self.assertEquals( |
|
81 | self.assertEquals(nb.metadata, NotebookNode()) | |
81 | self.assertEquals(nb.nbformat,2) |
|
82 | self.assertEquals(nb.nbformat,2) | |
82 |
|
83 | |||
83 | def test_notebook(self): |
|
84 | def test_notebook(self): | |
84 | worksheets = [new_worksheet(),new_worksheet()] |
|
85 | worksheets = [new_worksheet(),new_worksheet()] | |
85 | nb = new_notebook(name='foo',worksheets=worksheets) |
|
86 | metadata = new_metadata(name=u'foo') | |
86 | self.assertEquals(nb.name,u'foo') |
|
87 | nb = new_notebook(metadata=metadata,worksheets=worksheets) | |
|
88 | self.assertEquals(nb.metadata.name,u'foo') | |||
87 | self.assertEquals(nb.worksheets,worksheets) |
|
89 | self.assertEquals(nb.worksheets,worksheets) | |
88 | self.assertEquals(nb.nbformat,2) |
|
90 | self.assertEquals(nb.nbformat,2) | |
89 |
|
91 | |||
|
92 | class TestMetadata(TestCase): | |||
|
93 | ||||
|
94 | def test_empty_metadata(self): | |||
|
95 | md = new_metadata() | |||
|
96 | self.assertEquals(u'name' not in md, True) | |||
|
97 | self.assertEquals(u'authors' not in md, True) | |||
|
98 | self.assertEquals(u'license' not in md, True) | |||
|
99 | self.assertEquals(u'saved' not in md, True) | |||
|
100 | self.assertEquals(u'modified' not in md, True) | |||
|
101 | self.assertEquals(u'gistid' not in md, True) | |||
|
102 | ||||
|
103 | def test_metadata(self): | |||
|
104 | authors = [new_author(name='Bart Simpson',email='bsimpson@fox.com')] | |||
|
105 | md = new_metadata(name=u'foo',license=u'BSD',created=u'today', | |||
|
106 | modified=u'now',gistid=u'21341231',authors=authors) | |||
|
107 | self.assertEquals(md.name, u'foo') | |||
|
108 | self.assertEquals(md.license, u'BSD') | |||
|
109 | self.assertEquals(md.created, u'today') | |||
|
110 | self.assertEquals(md.modified, u'now') | |||
|
111 | self.assertEquals(md.gistid, u'21341231') | |||
|
112 | self.assertEquals(md.authors, authors) | |||
|
113 |
@@ -1,6 +1,8 b'' | |||||
1 | { |
|
1 | { | |
2 | "nbformat": 2, |
|
2 | "nbformat": 2, | |
3 | "name": "helloworld", |
|
3 | "metadata": { | |
|
4 | "name": "helloworld" | |||
|
5 | }, | |||
4 | "worksheets": [ |
|
6 | "worksheets": [ | |
5 | { |
|
7 | { | |
6 | "cells": [ |
|
8 | "cells": [ |
@@ -1,6 +1,8 b'' | |||||
1 | { |
|
1 | { | |
2 | "nbformat": 2, |
|
2 | "nbformat": 2, | |
3 | "name": "mcpricer", |
|
3 | "metadata": { | |
|
4 | "name": "mcpricer" | |||
|
5 | }, | |||
4 | "worksheets": [ |
|
6 | "worksheets": [ | |
5 | { |
|
7 | { | |
6 | "cells": [ |
|
8 | "cells": [ |
@@ -1,6 +1,8 b'' | |||||
1 | { |
|
1 | { | |
2 | "nbformat": 2, |
|
2 | "nbformat": 2, | |
3 | "name": "rmt", |
|
3 | "metadata": { | |
|
4 | "name": "rmt" | |||
|
5 | }, | |||
4 | "worksheets": [ |
|
6 | "worksheets": [ | |
5 | { |
|
7 | { | |
6 | "cells": [ |
|
8 | "cells": [ |
@@ -1,6 +1,8 b'' | |||||
1 | { |
|
1 | { | |
2 | "nbformat": 2, |
|
2 | "nbformat": 2, | |
3 | "name": "task_1", |
|
3 | "metadata": { | |
|
4 | "name": "task_1" | |||
|
5 | }, | |||
4 | "worksheets": [ |
|
6 | "worksheets": [ | |
5 | { |
|
7 | { | |
6 | "cells": [ |
|
8 | "cells": [ |
@@ -1,6 +1,8 b'' | |||||
1 | { |
|
1 | { | |
2 | "nbformat": 2, |
|
2 | "nbformat": 2, | |
3 | "name": "taskmap", |
|
3 | "metadata": { | |
|
4 | "name": "taskmap" | |||
|
5 | }, | |||
4 | "worksheets": [ |
|
6 | "worksheets": [ | |
5 | { |
|
7 | { | |
6 | "cells": [ |
|
8 | "cells": [ |
@@ -1,6 +1,4 b'' | |||||
1 | { |
|
1 | { | |
2 | "nbformat": 2, |
|
|||
3 | "name": "basic_quantum", |
|
|||
4 | "worksheets": [ |
|
2 | "worksheets": [ | |
5 | { |
|
3 | { | |
6 | "cells": [ |
|
4 | "cells": [ | |
@@ -276,5 +274,9 b'' | |||||
276 | } |
|
274 | } | |
277 | ] |
|
275 | ] | |
278 | } |
|
276 | } | |
279 | ] |
|
277 | ], | |
|
278 | "metadata": { | |||
|
279 | "name": "basic_quantum" | |||
|
280 | }, | |||
|
281 | "nbformat": 2 | |||
280 | } No newline at end of file |
|
282 | } |
@@ -1,6 +1,8 b'' | |||||
1 | { |
|
1 | { | |
2 | "nbformat": 2, |
|
2 | "nbformat": 2, | |
3 | "name": "decompose", |
|
3 | "metadata": { | |
|
4 | "name": "decompose" | |||
|
5 | }, | |||
4 | "worksheets": [ |
|
6 | "worksheets": [ | |
5 | { |
|
7 | { | |
6 | "cells": [ |
|
8 | "cells": [ |
@@ -1,6 +1,8 b'' | |||||
1 | { |
|
1 | { | |
2 | "nbformat": 2, |
|
2 | "nbformat": 2, | |
3 | "name": "dense_coding", |
|
3 | "metadata": { | |
|
4 | "name": "dense_coding" | |||
|
5 | }, | |||
4 | "worksheets": [ |
|
6 | "worksheets": [ | |
5 | { |
|
7 | { | |
6 | "cells": [ |
|
8 | "cells": [ |
@@ -1,6 +1,8 b'' | |||||
1 | { |
|
1 | { | |
2 | "nbformat": 2, |
|
2 | "nbformat": 2, | |
3 | "name": "formatting", |
|
3 | "metadata": { | |
|
4 | "name": "formatting" | |||
|
5 | }, | |||
4 | "worksheets": [ |
|
6 | "worksheets": [ | |
5 | { |
|
7 | { | |
6 | "cells": [ |
|
8 | "cells": [ |
@@ -1,6 +1,8 b'' | |||||
1 | { |
|
1 | { | |
2 | "nbformat": 2, |
|
2 | "nbformat": 2, | |
3 | "name": "grovers", |
|
3 | "metadata": { | |
|
4 | "name": "grovers" | |||
|
5 | }, | |||
4 | "worksheets": [ |
|
6 | "worksheets": [ | |
5 | { |
|
7 | { | |
6 | "cells": [ |
|
8 | "cells": [ |
@@ -1,6 +1,8 b'' | |||||
1 | { |
|
1 | { | |
2 | "nbformat": 2, |
|
2 | "nbformat": 2, | |
3 | "name": "qerror", |
|
3 | "metadata": { | |
|
4 | "name": "qerror" | |||
|
5 | }, | |||
4 | "worksheets": [ |
|
6 | "worksheets": [ | |
5 | { |
|
7 | { | |
6 | "cells": [ |
|
8 | "cells": [ |
@@ -1,6 +1,8 b'' | |||||
1 | { |
|
1 | { | |
2 | "nbformat": 2, |
|
2 | "nbformat": 2, | |
3 | "name": "qft", |
|
3 | "metadata": { | |
|
4 | "name": "qft" | |||
|
5 | }, | |||
4 | "worksheets": [ |
|
6 | "worksheets": [ | |
5 | { |
|
7 | { | |
6 | "cells": [ |
|
8 | "cells": [ |
@@ -1,6 +1,8 b'' | |||||
1 | { |
|
1 | { | |
2 | "nbformat": 2, |
|
2 | "nbformat": 2, | |
3 | "name": "quantum_computing", |
|
3 | "metadata": { | |
|
4 | "name": "quantum_computing" | |||
|
5 | }, | |||
4 | "worksheets": [ |
|
6 | "worksheets": [ | |
5 | { |
|
7 | { | |
6 | "cells": [ |
|
8 | "cells": [ |
@@ -1,6 +1,8 b'' | |||||
1 | { |
|
1 | { | |
2 | "nbformat": 2, |
|
2 | "nbformat": 2, | |
3 | "name": "dos", |
|
3 | "metadata": { | |
|
4 | "name": "dos" | |||
|
5 | }, | |||
4 | "worksheets": [ |
|
6 | "worksheets": [ | |
5 | { |
|
7 | { | |
6 | "cells": [ |
|
8 | "cells": [ |
@@ -1,6 +1,8 b'' | |||||
1 | { |
|
1 | { | |
2 | "nbformat": 2, |
|
2 | "nbformat": 2, | |
3 | "name": "sympy", |
|
3 | "metadata": { | |
|
4 | "name": "sympy" | |||
|
5 | }, | |||
4 | "worksheets": [ |
|
6 | "worksheets": [ | |
5 | { |
|
7 | { | |
6 | "cells": [ |
|
8 | "cells": [ |
General Comments 0
You need to be logged in to leave comments.
Login now