Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_raw_cell_with_metadata(markdown="""
raw content
"""):
nb = jupytext.reads(markdown, 'md')
compare(nb.cells[0], new_raw_cell(source='raw content', metadata={'key': 'value'}))
markdown2 = jupytext.writes(nb, 'md')
compare(markdown2, markdown)
def test_title_no_metadata(text='title', value=('title', {})):
compare(text_to_metadata(text, allow_title=True), value)
assert metadata_to_text(*value) == text.strip()
pynb="""def test_read_cell_explicit_start_end(pynb='''
import pandas as pd
# +
def data():
return pd.DataFrame({'A': [0, 1]})
data()
'''):
nb = jupytext.reads(pynb, 'py')
pynb2 = jupytext.writes(nb, 'py')
compare(pynb2, pynb)
"""):
nb = jupytext.reads(pynb, 'py')
pynb2 = jupytext.writes(nb, 'py')
compare(pynb2, pynb)
def test_parse_rmd_options(options, language_and_metadata):
compare(rmd_options_to_metadata(options), language_and_metadata)
def test_active_ipynb_rmd_using_tags(ext, no_jupytext_version_number):
nb = jupytext.reads(HEADER[ext] + ACTIVE_IPYNB_RMD_USING_TAG[ext], ext)
assert len(nb.cells) == 1
compare(jupytext.writes(nb, ext), ACTIVE_IPYNB_RMD_USING_TAG[ext])
compare(nb.cells[0], ACTIVE_IPYNB_RMD_USING_TAG['.ipynb'])
def test_read_markdown_cell_with_triple_quote_307(
script="""# This script test that commented triple quotes '''
# do not impede the correct identification of Markdown cells
# Here is Markdown cell number 2 '''
"""):
notebook = jupytext.reads(script, 'py')
assert len(notebook.cells) == 2
assert notebook.cells[0].cell_type == 'markdown'
assert notebook.cells[0].source == """This script test that commented triple quotes '''
do not impede the correct identification of Markdown cells"""
assert notebook.cells[1].cell_type == 'markdown'
assert notebook.cells[1].source == "Here is Markdown cell number 2 '''"
script2 = jupytext.writes(notebook, 'py')
compare(script2, script)
# +
# Final cell
1 + 1
"""):
notebook = jupytext.reads(script, 'py')
assert len(notebook.cells) == 3
for cell in notebook.cells:
lines = cell.source.splitlines()
if len(lines) != 1:
assert lines[0]
assert lines[-1]
script2 = jupytext.writes(notebook, 'py')
compare(script2, script)
def test_markdown_cell_with_metadata(markdown="""
A long
markdown cell
"""):
nb = jupytext.reads(markdown, 'md')
compare(nb.cells[0], new_markdown_cell(source='A long\n\n\nmarkdown cell',
metadata={'key': 'value'}))
markdown2 = jupytext.writes(nb, 'md')
compare(markdown2, markdown)
def test_code_cell_with_metadata(markdown="""```python tags=["parameters"]
a = 1
b = 2
"""): nb = jupytext.reads(markdown, 'md') compare(nb.cells[0], new_code_cell(source='a = 1\nb = 2', metadata={'tags': ['parameters']})) markdown2 = jupytext.writes(nb, 'md') compare(markdown2, markdown)
update=args.update,
allow_expected_differences=not args.test_strict,
stop_on_first_error=args.stop_on_first_error)
# Round trip from a text file
else:
with open(nb_file) as fp:
org_text = fp.read()
# If the destination is not ipynb, we convert to/back that format
if dest_fmt['extension'] != '.ipynb':
dest_text = writes(notebook, fmt=dest_fmt)
notebook = reads(dest_text, fmt=dest_fmt)
text = writes(notebook, fmt=fmt)
compare(text, org_text)
except (NotebookDifference, AssertionError) as err:
sys.stdout.write('{}: {}'.format(nb_file, str(err)))
return 1
return 0
# b. Output to the desired file or format
if nb_dest:
if nb_dest == nb_file and not dest_fmt:
dest_fmt = fmt
# Test consistency between dest name and output format
if dest_fmt and nb_dest != '-':
base_path(nb_dest, dest_fmt)
# Describe what jupytext is doing