##// END OF EJS Templates
fix backward `f, nb` args for nbformat.write
Min RK -
Show More
@@ -608,4 +608,4 b' Defaulting color scheme to \'NoColor\'"""'
608 ))
608 ))
609 nb = v4.new_notebook(cells=cells)
609 nb = v4.new_notebook(cells=cells)
610 with io.open(args.filename, 'w', encoding='utf-8') as f:
610 with io.open(args.filename, 'w', encoding='utf-8') as f:
611 write(f, nb, version=4)
611 write(nb, f, version=4)
@@ -67,7 +67,7 b' class APITest(NotebookTestBase):'
67
67
68 with io.open(pjoin(nbdir, 'foo', 'testnb.ipynb'), 'w',
68 with io.open(pjoin(nbdir, 'foo', 'testnb.ipynb'), 'w',
69 encoding='utf-8') as f:
69 encoding='utf-8') as f:
70 write(f, nb, version=4)
70 write(nb, f, version=4)
71
71
72 self.nbconvert_api = NbconvertAPI(self.base_url())
72 self.nbconvert_api = NbconvertAPI(self.base_url())
73
73
@@ -303,7 +303,7 b' class FileContentsManager(ContentsManager):'
303 nb['metadata']['name'] = u''
303 nb['metadata']['name'] = u''
304
304
305 with atomic_writing(os_path, encoding='utf-8') as f:
305 with atomic_writing(os_path, encoding='utf-8') as f:
306 nbformat.write(f, nb, version=nbformat.NO_CONVERT)
306 nbformat.write(nb, f, version=nbformat.NO_CONVERT)
307
307
308 def _save_file(self, os_path, model, name='', path=''):
308 def _save_file(self, os_path, model, name='', path=''):
309 """save a non-notebook file"""
309 """save a non-notebook file"""
@@ -144,7 +144,7 b' class APITest(NotebookTestBase):'
144 with io.open(pjoin(nbdir, d, '%s.ipynb' % name), 'w',
144 with io.open(pjoin(nbdir, d, '%s.ipynb' % name), 'w',
145 encoding='utf-8') as f:
145 encoding='utf-8') as f:
146 nb = new_notebook()
146 nb = new_notebook()
147 write(f, nb, version=4)
147 write(nb, f, version=4)
148
148
149 # create a text file
149 # create a text file
150 with io.open(pjoin(nbdir, d, '%s.txt' % name), 'w',
150 with io.open(pjoin(nbdir, d, '%s.txt' % name), 'w',
@@ -64,7 +64,7 b' class SessionAPITest(NotebookTestBase):'
64 with io.open(pjoin(nbdir, 'foo', 'nb1.ipynb'), 'w',
64 with io.open(pjoin(nbdir, 'foo', 'nb1.ipynb'), 'w',
65 encoding='utf-8') as f:
65 encoding='utf-8') as f:
66 nb = new_notebook()
66 nb = new_notebook()
67 write(f, nb, version=4)
67 write(nb, f, version=4)
68
68
69 self.sess_api = SessionAPI(self.base_url())
69 self.sess_api = SessionAPI(self.base_url())
70
70
@@ -74,7 +74,7 b' class FilesTest(NotebookTestBase):'
74
74
75 with io.open(pjoin(nbdir, 'testnb.ipynb'), 'w',
75 with io.open(pjoin(nbdir, 'testnb.ipynb'), 'w',
76 encoding='utf-8') as f:
76 encoding='utf-8') as f:
77 write(f, nb, version=4)
77 write(nb, f, version=4)
78
78
79 with io.open(pjoin(nbdir, 'test.bin'), 'wb') as f:
79 with io.open(pjoin(nbdir, 'test.bin'), 'wb') as f:
80 f.write(b'\xff' + os.urandom(5))
80 f.write(b'\xff' + os.urandom(5))
@@ -95,7 +95,7 b' class TestLatexExporter(ExportersTestsBase):'
95 with TemporaryDirectory() as td:
95 with TemporaryDirectory() as td:
96 nbfile = os.path.join(td, notebook_name)
96 nbfile = os.path.join(td, notebook_name)
97 with open(nbfile, 'w') as f:
97 with open(nbfile, 'w') as f:
98 write(f, nb, 4)
98 write(nb, f, 4)
99
99
100 (output, resources) = LatexExporter(template_file='article').from_filename(nbfile)
100 (output, resources) = LatexExporter(template_file='article').from_filename(nbfile)
101 assert len(output) > 0
101 assert len(output) > 0
@@ -103,7 +103,7 b' class TestsBase(unittest.TestCase):'
103 def create_empty_notebook(self, path):
103 def create_empty_notebook(self, path):
104 nb = v4.new_notebook()
104 nb = v4.new_notebook()
105 with io.open(path, 'w', encoding='utf-8') as f:
105 with io.open(path, 'w', encoding='utf-8') as f:
106 write(f, nb, 4)
106 write(nb, f, 4)
107
107
108 def copy_files_to(self, copy_filenames, dest='.'):
108 def copy_files_to(self, copy_filenames, dest='.'):
109 "Copy test files into the destination directory"
109 "Copy test files into the destination directory"
@@ -123,17 +123,17 b' def read(fp, as_version, **kwargs):'
123 return reads(fp.read(), as_version, **kwargs)
123 return reads(fp.read(), as_version, **kwargs)
124
124
125
125
126 def write(fp, nb, version=NO_CONVERT, **kwargs):
126 def write(nb, fp, version=NO_CONVERT, **kwargs):
127 """Write a notebook to a file in a given nbformat version.
127 """Write a notebook to a file in a given nbformat version.
128
128
129 The file-like object must accept unicode input.
129 The file-like object must accept unicode input.
130
130
131 Parameters
131 Parameters
132 ----------
132 ----------
133 fp : file
134 Any file-like object with a write method that accepts unicode.
135 nb : NotebookNode
133 nb : NotebookNode
136 The notebook to write.
134 The notebook to write.
135 fp : file
136 Any file-like object with a write method that accepts unicode.
137 version : int, optional
137 version : int, optional
138 The nbformat version to write.
138 The nbformat version to write.
139 If nb is not this version, it will be converted.
139 If nb is not this version, it will be converted.
@@ -311,7 +311,7 b' class TrustNotebookApp(BaseIPythonApplication):'
311 print("Signing notebook: %s" % notebook_path)
311 print("Signing notebook: %s" % notebook_path)
312 self.notary.sign(nb)
312 self.notary.sign(nb)
313 with atomic_writing(notebook_path) as f:
313 with atomic_writing(notebook_path) as f:
314 write(f, nb, NO_CONVERT)
314 write(nb, f, NO_CONVERT)
315
315
316 def generate_new_key(self):
316 def generate_new_key(self):
317 """Generate a new notebook signature key"""
317 """Generate a new notebook signature key"""
General Comments 0
You need to be logged in to leave comments. Login now