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_metadata_filter_user_plus_default():
assert filter_metadata(to_dict(['technical', 'user', 'preserve']), '-user', '-technical'
) == to_dict(['preserve'])
assert filter_metadata(to_dict(['technical', 'user', 'preserve']), 'all,-user', '-technical'
) == to_dict(['preserve', 'technical'])
assert filter_metadata(to_dict(['technical', 'user', 'preserve']), 'user', 'preserve,-all'
) == to_dict(['user', 'preserve'])
def test_ignore_metadata():
metadata = {'trusted': True, 'tags': ['remove_input']}
metadata = filter_metadata(metadata, None, _IGNORE_CELL_METADATA)
assert metadata_to_rmd_options('R', metadata) == 'r echo=FALSE'
def test_filter_metadata():
assert filter_metadata({'scrolled': True}, None, _IGNORE_CELL_METADATA) == {}
def test_metadata_filter_default():
assert filter_metadata(to_dict(['technical', 'user', 'preserve']), None, '-technical'
) == to_dict(['user', 'preserve'])
assert filter_metadata(to_dict(['technical', 'user', 'preserve']), None, 'preserve,-all'
) == to_dict(['preserve'])
def test_metadata_filter_user_plus_default():
assert filter_metadata(to_dict(['technical', 'user', 'preserve']), '-user', '-technical'
) == to_dict(['preserve'])
assert filter_metadata(to_dict(['technical', 'user', 'preserve']), 'all,-user', '-technical'
) == to_dict(['preserve', 'technical'])
assert filter_metadata(to_dict(['technical', 'user', 'preserve']), 'user', 'preserve,-all'
) == to_dict(['user', 'preserve'])
def test_negative_cell_metadata_filter():
assert filter_metadata(to_dict(['exectime']), '-linesto', '-exectime') == to_dict([])
def test_metadata_filter_default():
assert filter_metadata(to_dict(['technical', 'user', 'preserve']), None, '-technical'
) == to_dict(['user', 'preserve'])
assert filter_metadata(to_dict(['technical', 'user', 'preserve']), None, 'preserve,-all'
) == to_dict(['preserve'])
def filtered_notebook_metadata(notebook):
"""Notebook metadata, filtered for metadata added by Jupytext itself"""
metadata = copy(notebook.metadata)
metadata = filter_metadata(metadata,
notebook.metadata.get('jupytext', {}).get('notebook_metadata_filter'),
_DEFAULT_NOTEBOOK_METADATA)
if 'jupytext' in metadata:
del metadata['jupytext']
return metadata
def filtered_cell(cell, preserve_outputs, cell_metadata_filter):
"""Cell type, metadata and source from given cell"""
metadata = copy(cell.metadata)
filter_metadata(metadata, cell_metadata_filter, _IGNORE_CELL_METADATA)
filtered = {'cell_type': cell.cell_type,
'source': cell.source,
'metadata': metadata}
if preserve_outputs:
for key in ['execution_count', 'outputs']:
if key in cell:
filtered[key] = cell[key]
return filtered
def writes(self, nb, metadata=None, **kwargs):
"""Return the text representation of the notebook"""
if self.fmt.get('format_name') == 'pandoc':
metadata = insert_jupytext_info_and_filter_metadata(metadata, self.ext, self.implementation)
cells = []
for cell in nb.cells:
cell_metadata = filter_metadata(copy(cell.metadata),
self.fmt.get('cell_metadata_filter'),
_IGNORE_CELL_METADATA)
if cell.cell_type == 'code':
cells.append(new_code_cell(source=cell.source, metadata=cell_metadata))
else:
cells.append(NotebookNode(source=cell.source, metadata=cell_metadata, cell_type=cell.cell_type))
return notebook_to_md(NotebookNode(
nbformat=nb.nbformat,
nbformat_minor=nb.nbformat_minor,
metadata=metadata,
cells=cells))
# Copy the notebook, in order to be sure we do not modify the original notebook
nb = NotebookNode(
nbformat=nb.nbformat,