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_script_with_spyder_cell_with_name_is_percent(script="""#%% cell name
1 + 2"""):
assert guess_format(script, '.py')[0] == 'percent'
def test_script_with_spyder_cell_is_percent(script="""#%%
1 + 2"""):
assert guess_format(script, '.py')[0] == 'percent'
def test_guess_format_hydrogen():
text = """# %%
cat hello.txt
"""
assert guess_format(text, ext='.py')[0] == 'hydrogen'
# Again, a markdown cell
# In[33]:
2 + 2
#
3 + 3
"""):
assert jupytext.formats.guess_format(script, '.py')[0] == 'percent'
nb = jupytext.reads(script, '.py')
assert len(nb.cells) == 5
# Again, a markdown cell
# In[33]:
2 + 2
#
3 + 3
"""):
assert jupytext.formats.guess_format(script, '.py')[0] == 'hydrogen'
nb = jupytext.reads(script, '.py')
assert len(nb.cells) == 5
def test_guess_format_percent(nb_file):
with open(nb_file) as stream:
assert guess_format(stream.read(), ext='.py')[0] == 'percent'
def test_guess_format_sphinx(nb_file):
with open(nb_file) as stream:
assert guess_format(stream.read(), ext='.py')[0] == 'sphinx'
def test_guess_format_light(nb_file):
with open(nb_file) as stream:
assert guess_format(stream.read(), ext='.py')[0] == 'light'
:param kwargs: (not used) additional parameters for nbformat.reads
:return: the notebook
"""
fmt = copy(fmt) if fmt else divine_format(text)
fmt = long_form_one_format(fmt)
ext = fmt['extension']
if ext == '.ipynb':
return nbformat.reads(text, as_version, **kwargs)
format_name = read_format_from_metadata(text, ext) or fmt.get('format_name')
if format_name:
format_options = {}
else:
format_name, format_options = guess_format(text, ext)
if format_name:
fmt['format_name'] = format_name
fmt.update(format_options)
reader = TextNotebookConverter(fmt)
notebook = reader.reads(text, **kwargs)
rearrange_jupytext_metadata(notebook.metadata)
if format_name and insert_or_test_version_number():
notebook.metadata.setdefault('jupytext', {}).setdefault('text_representation', {}).update(
{'extension': ext, 'format_name': format_name})
return notebook