本文整理汇总了Python中nbformat.v4.new_notebook函数的典型用法代码示例。如果您正苦于以下问题:Python new_notebook函数的具体用法?Python new_notebook怎么用?Python new_notebook使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了new_notebook函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_inline_merge_source_empty
def test_inline_merge_source_empty():
base = new_notebook()
local = new_notebook()
remote = new_notebook()
expected = new_notebook()
merged, decisions = merge_notebooks(base, local, remote)
assert merged == expected
开发者ID:vidartf,项目名称:nbdime,代码行数:7,代码来源:test_merge_notebooks_inline.py
示例2: test_inline_merge_attachments
def test_inline_merge_attachments():
# FIXME: Use output creation utils Vidar wrote in another test file
base = new_notebook()
local = new_notebook()
remote = new_notebook()
expected = new_notebook()
merged, decisions = merge_notebooks(base, local, remote)
assert merged == expected
开发者ID:vidartf,项目名称:nbdime,代码行数:8,代码来源:test_merge_notebooks_inline.py
示例3: test_inline_merge_dummy_notebooks
def test_inline_merge_dummy_notebooks():
"Just the basic empty notebook passes through."
base = new_notebook()
local = new_notebook()
remote = new_notebook()
expected = new_notebook()
merged, decisions = merge_notebooks(base, local, remote)
assert expected == merged
开发者ID:vidartf,项目名称:nbdime,代码行数:8,代码来源:test_merge_notebooks_inline.py
示例4: test_inline_merge_notebook_version
def test_inline_merge_notebook_version():
"Minor version gets bumped to max."
base = new_notebook(nbformat=4, nbformat_minor=0)
local = new_notebook(nbformat=4, nbformat_minor=1)
remote = new_notebook(nbformat=4, nbformat_minor=2)
expected = new_notebook(nbformat=4, nbformat_minor=2)
merged, decisions = merge_notebooks(base, local, remote)
assert expected == merged
开发者ID:vidartf,项目名称:nbdime,代码行数:8,代码来源:test_merge_notebooks_inline.py
示例5: setUp
def setUp(self):
nbdir = self.notebook_dir
subdir = pjoin(nbdir, 'foo')
try:
os.mkdir(subdir)
except OSError as e:
# Deleting the folder in an earlier test may have failed
if e.errno != errno.EEXIST:
raise
self.addCleanup(partial(shutil.rmtree, subdir, ignore_errors=True))
with io.open(pjoin(subdir, 'nb1.ipynb'), 'w', encoding='utf-8') as f:
nb = new_notebook()
write(nb, f, version=4)
self.sess_api = SessionAPI(self.request)
@self.addCleanup
def cleanup_sessions():
for session in self.sess_api.list().json():
self.sess_api.delete(session['id'])
# This is necessary in some situations on Windows: without it, it
# fails to delete the directory because something is still using
# it. I think there is a brief period after the kernel terminates
# where Windows still treats its working directory as in use. On my
# Windows VM, 0.01s is not long enough, but 0.1s appears to work
# reliably. -- TK, 15 December 2014
time.sleep(0.1)
开发者ID:BarnetteME1,项目名称:DnD-stuff,代码行数:30,代码来源:test_sessions_api.py
示例6: test_raw_template_dynamic_attr_reversed
def test_raw_template_dynamic_attr_reversed(self):
"""
Test that template_file and raw_template traitlets play nicely together.
- source assigns raw_template default first, then template_file
- checks that the raw_template overrules template_file if set
- checks that once raw_template is set to '', template_file returns
"""
nb = v4.new_notebook()
nb.cells.append(v4.new_code_cell("some_text"))
class AttrDynamicExporter(TemplateExporter):
@default('raw_template')
def _raw_template_default(self):
return raw_template
@default('template_file')
def _template_file_default(self):
return "rst.tpl"
exporter_attr_dynamic = AttrDynamicExporter()
output_attr_dynamic, _ = exporter_attr_dynamic.from_notebook_node(nb)
assert "blah" in output_attr_dynamic
exporter_attr_dynamic.raw_template = ''
assert exporter_attr_dynamic.template_file == "rst.tpl"
output_attr_dynamic, _ = exporter_attr_dynamic.from_notebook_node(nb)
assert "blah" not in output_attr_dynamic
开发者ID:jupyter,项目名称:nbconvert,代码行数:26,代码来源:test_templateexporter.py
示例7: new
def new(self, model=None, path=''):
"""Create a new file or directory and return its model with no content.
To create a new untitled entity in a directory, use `new_untitled`.
"""
path = path.strip('/')
if model is None:
model = {}
if path.endswith('.ipynb'):
model.setdefault('type', 'notebook')
else:
model.setdefault('type', 'file')
# no content, not a directory, so fill out new-file model
if 'content' not in model and model['type'] != 'directory':
if model['type'] == 'notebook':
model['content'] = new_notebook()
model['format'] = 'json'
else:
model['content'] = ''
model['type'] = 'file'
model['format'] = 'text'
model = self.save(model, path)
return model
开发者ID:ACGC,项目名称:notebook,代码行数:26,代码来源:manager.py
示例8: test_modify_cell_with_submissions
def test_modify_cell_with_submissions(self, preprocessor, gradebook, resources):
nb = new_notebook()
nb.cells.append(create_grade_and_solution_cell("hello", "markdown", "foo", 2))
nb, resources = preprocessor.preprocess(nb, resources)
notebook = gradebook.find_notebook("test", "ps0")
grade_cell = gradebook.find_grade_cell("foo", "test", "ps0")
solution_cell = gradebook.find_solution_cell("foo", "test", "ps0")
source_cell = gradebook.find_source_cell("foo", "test", "ps0")
assert grade_cell.max_score == 2
assert source_cell.source == "hello"
gradebook.add_student("hacker123")
submission = gradebook.add_submission("ps0", "hacker123").notebooks[0]
assert len(notebook.submissions) == 1
nb.cells[-1] = create_grade_and_solution_cell("goodbye", "markdown", "foo", 1)
nb, resources = preprocessor.preprocess(nb, resources)
gradebook.db.refresh(notebook)
gradebook.db.refresh(submission)
gradebook.db.refresh(grade_cell)
gradebook.db.refresh(solution_cell)
gradebook.db.refresh(source_cell)
assert len(notebook.submissions) == 1
assert grade_cell.max_score == 1
assert source_cell.source == "goodbye"
开发者ID:0905huhy,项目名称:nbgrader,代码行数:27,代码来源:test_savecells.py
示例9: test_grade_existing_manual_grade
def test_grade_existing_manual_grade(self, preprocessors, gradebook, resources):
"""Is a failing code cell correctly graded?"""
cell = create_grade_and_solution_cell("hello", "markdown", "foo", 1)
nb = new_notebook()
nb.cells.append(cell)
preprocessors[0].preprocess(nb, resources)
gradebook.add_submission("ps0", "bar")
cell.source = "hello!"
preprocessors[1].preprocess(nb, resources)
grade_cell = gradebook.find_grade("foo", "test", "ps0", "bar")
assert grade_cell.score == 0
assert grade_cell.max_score == 1
assert grade_cell.auto_score == None
assert grade_cell.manual_score == None
assert grade_cell.needs_manual_grade
grade_cell.manual_score = 1
grade_cell.needs_manual_grade = False
gradebook.db.commit()
preprocessors[1].preprocess(nb, resources)
grade_cell = gradebook.find_grade("foo", "test", "ps0", "bar")
assert grade_cell.score == 1
assert grade_cell.max_score == 1
assert grade_cell.auto_score == None
assert grade_cell.manual_score == 1
assert grade_cell.needs_manual_grade
开发者ID:parente,项目名称:nbgrader,代码行数:29,代码来源:test_saveautogrades.py
示例10: notebook
def notebook(self, s):
"""Export and convert IPython notebooks.
This function can export the current IPython history to a notebook file.
For example, to export the history to "foo.ipynb" do "%notebook foo.ipynb".
The -e or --export flag is deprecated in IPython 5.2, and will be
removed in the future.
"""
args = magic_arguments.parse_argstring(self.notebook, s)
from nbformat import write, v4
cells = []
hist = list(self.shell.history_manager.get_range())
if(len(hist)<=1):
raise ValueError('History is empty, cannot export')
for session, execution_count, source in hist[:-1]:
cells.append(v4.new_code_cell(
execution_count=execution_count,
source=source
))
nb = v4.new_notebook(cells=cells)
with io.open(args.filename, 'w', encoding='utf-8') as f:
write(nb, f, version=4)
开发者ID:BarnetteME1,项目名称:DnD-stuff,代码行数:25,代码来源:basic.py
示例11: test_very_long_cells
def test_very_long_cells(self):
"""
Torture test that long cells do not cause issues
"""
lorem_ipsum_text = textwrap.dedent("""\
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec
dignissim, ipsum non facilisis tempus, dui felis tincidunt metus,
nec pulvinar neque odio eget risus. Nulla nisi lectus, cursus
suscipit interdum at, ultrices sit amet orci. Mauris facilisis
imperdiet elit, vitae scelerisque ipsum dignissim non. Integer
consequat malesuada neque sit amet pulvinar. Curabitur pretium
ut turpis eget aliquet. Maecenas sagittis lacus sed lectus
volutpat, eu adipiscing purus pulvinar. Maecenas consequat
luctus urna, eget cursus quam mollis a. Aliquam vitae ornare
erat, non hendrerit urna. Sed eu diam nec massa egestas pharetra
at nec tellus. Fusce feugiat lacus quis urna sollicitudin volutpat.
Quisque at sapien non nibh feugiat tempus ac ultricies purus.
""")
lorem_ipsum_text = lorem_ipsum_text.replace("\n"," ") + "\n\n"
large_lorem_ipsum_text = "".join([lorem_ipsum_text]*3000)
notebook_name = "lorem_ipsum_long.ipynb"
nb = v4.new_notebook(
cells=[
v4.new_markdown_cell(source=large_lorem_ipsum_text)
]
)
with TemporaryDirectory() as td:
nbfile = os.path.join(td, notebook_name)
with open(nbfile, 'w') as f:
write(nb, f, 4)
(output, resources) = LatexExporter(template_file='article').from_filename(nbfile)
assert len(output) > 0
开发者ID:jhamrick,项目名称:nbconvert,代码行数:35,代码来源:test_latex.py
示例12: test_preprocessor_collapsible_headings
def test_preprocessor_collapsible_headings():
"""Test collapsible_headings preprocessor."""
# check import shortcut
from jupyter_contrib_nbextensions.nbconvert_support import CollapsibleHeadingsPreprocessor # noqa
cells = []
for lvl in range(6, 1, -1):
for collapsed in (True, False):
cells.extend([
nbf.new_markdown_cell(
source='{} {} heading level {}'.format(
'#' * lvl,
'Collapsed' if collapsed else 'Uncollapsed',
lvl),
metadata={'heading_collapsed': True} if collapsed else {}),
nbf.new_markdown_cell(source='\n'.join([
'want hidden' if collapsed else 'want to see',
'what I mean',
])),
nbf.new_code_cell(source='\n'.join([
'want hidden' if collapsed else 'want to see',
'what I mean',
])),
])
notebook_node = nbf.new_notebook(cells=cells)
body, resources = export_through_preprocessor(
notebook_node, CollapsibleHeadingsPreprocessor, RSTExporter, 'rst')
assert_not_in('hidden', body, 'check text hidden by collapsed headings')
assert_in('want to see', body, 'check for text under uncollapsed headings')
开发者ID:flipphillips,项目名称:IPython-notebook-extensions,代码行数:28,代码来源:test_preprocessors.py
示例13: build_notebook
def build_notebook(self, with_json_outputs=False):
"""Build a notebook in memory for use with preprocessor tests"""
outputs = [
nbformat.new_output("stream", name="stdout", text="a"),
nbformat.new_output("display_data", data={'text/plain': 'b'}),
nbformat.new_output("stream", name="stdout", text="c"),
nbformat.new_output("stream", name="stdout", text="d"),
nbformat.new_output("stream", name="stderr", text="e"),
nbformat.new_output("stream", name="stderr", text="f"),
nbformat.new_output("display_data", data={'image/png': 'Zw=='}), # g
nbformat.new_output("display_data", data={'application/pdf': 'aA=='}), # h
]
if with_json_outputs:
outputs.extend([
nbformat.new_output(
"display_data", data={'application/json': [1, 2, 3]}
), # j
nbformat.new_output(
"display_data", data={'application/json': {'a': 1, 'c': {'b': 2}}}
), # k
nbformat.new_output(
"display_data", data={'application/json': 'abc'}
), # l
nbformat.new_output(
"display_data", data={'application/json': 15.03}
), # m
])
cells=[nbformat.new_code_cell(source="$ e $", execution_count=1, outputs=outputs),
nbformat.new_markdown_cell(source="$ e $")]
return nbformat.new_notebook(cells=cells)
开发者ID:jupyter,项目名称:nbconvert,代码行数:33,代码来源:base.py
示例14: split_into_units
def split_into_units(nb_name, include_header=True):
"""Split notebook into units."""
try:
nb = nbformat.read(nb_name, as_version=4)
except IOError as e:
if e.errno == 2:
print('File not found: {0}'.format(nb_name), sys.stderr)
return []
else:
raise e
cells = nb.cells
indexes = [i for i, cell in enumerate(cells)
if cell.cell_type == 'markdown' and cell.source.startswith('# ')]
separated_cells = [cells[i:j] for i, j in zip(indexes, indexes[1:]+[None])]
units = [current.new_notebook(cells=cells,
metadata={'name': cells[0]
.source
.split('\n')[0][2:]})
for cells in separated_cells]
if not include_header:
for unit in units:
# The first line is the header.
unit.cells[0].source = '\n'.join(unit.cells[0].source
.split('\n')[1:])
return units
开发者ID:Huaguiyuan,项目名称:phys_codes,代码行数:26,代码来源:converter.py
示例15: create_notebook
def create_notebook(name, cells):
nb = new_notebook()
for cell in cells:
nb.cells.append(new_code_cell(source=cell))
with open(name, "w") as fh:
write(nb, fh, 4)
开发者ID:alaindomissy,项目名称:nbflow,代码行数:7,代码来源:util.py
示例16: setUp
def setUp(self):
nbdir = self.notebook_dir
if not os.path.isdir(pjoin(nbdir, 'foo')):
subdir = pjoin(nbdir, 'foo')
os.mkdir(subdir)
# Make sure that we clean this up when we're done.
# By using addCleanup this will happen correctly even if we fail
# later in setUp.
@self.addCleanup
def cleanup_dir():
shutil.rmtree(subdir, ignore_errors=True)
nb = new_notebook()
nb.cells.append(new_markdown_cell(u'Created by test ³'))
cc1 = new_code_cell(source=u'print(2*6)')
cc1.outputs.append(new_output(output_type="stream", text=u'12'))
cc1.outputs.append(new_output(output_type="execute_result",
data={'image/png' : png_green_pixel},
execution_count=1,
))
nb.cells.append(cc1)
with io.open(pjoin(nbdir, 'foo', 'testnb.ipynb'), 'w',
encoding='utf-8') as f:
write(nb, f, version=4)
self.nbconvert_api = NbconvertAPI(self.request)
开发者ID:BarnetteME1,项目名称:DnD-stuff,代码行数:31,代码来源:test_nbconvert_handlers.py
示例17: test_nonexistant_grade_id
def test_nonexistant_grade_id(self, preprocessors, resources):
"""Are cells not in the database ignored?"""
cell = create_grade_cell("", "code", "", 1)
cell.metadata.nbgrader['grade'] = False
nb = new_notebook()
nb.cells.append(cell)
nb, resources = preprocessors[0].preprocess(nb, resources)
nb, resources = preprocessors[1].preprocess(nb, resources)
assert 'grade_id' not in cell.metadata.nbgrader
cell = create_grade_cell("", "code", "foo", 1)
cell.metadata.nbgrader['grade'] = False
nb = new_notebook()
nb.cells.append(cell)
nb, resources = preprocessors[0].preprocess(nb, resources)
nb, resources = preprocessors[1].preprocess(nb, resources)
assert 'grade_id' not in cell.metadata.nbgrader
开发者ID:0905huhy,项目名称:nbgrader,代码行数:17,代码来源:test_overwritecells.py
示例18: test_htmltoc2
def test_htmltoc2(self):
"""Test exporter for adding table of contents"""
nb = v4.new_notebook(cells=[
v4.new_code_cell(source="a = 'world'"),
v4.new_markdown_cell(source="# Heading"),
])
self.check_stuff_gets_embedded(
nb, 'html_toc', to_be_included=['toc2'])
开发者ID:hagne,项目名称:IPython-notebook-extensions,代码行数:8,代码来源:test_exporters.py
示例19: create_rich_help_func
def create_rich_help_func(self):
'''
Build a help renderer with an attached __richdoc__ notebook.
'''
nb = nb_v4.new_notebook()
f = rich_help()
f.__richdoc__ = nb
return f
开发者ID:FeiXiang-Chen,项目名称:contentmanagement,代码行数:8,代码来源:loader.py
示例20: convert_normal_cells
def convert_normal_cells(normal_cells):
""" Convert normal_cells into html. """
for cell in normal_cells:
if cell.cell_type == 'markdown':
cell.source = re.sub(r'\\begin\{ *equation *\}', '\[', cell.source)
cell.source = re.sub(r'\\end\{ *equation *\}', '\]', cell.source)
tmp = current.new_notebook(cells=normal_cells)
html = export_unit_to_html(tmp)
return html
开发者ID:Huaguiyuan,项目名称:phys_codes,代码行数:9,代码来源:converter.py
注:本文中的nbformat.v4.new_notebook函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论