/
test_metadata_filters_from_config.py
49 lines (41 loc) · 1.51 KB
/
test_metadata_filters_from_config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import nbformat
from nbformat.v4.nbbase import new_markdown_cell, new_notebook
from jupytext.cli import jupytext as jupytext_cli
from jupytext.compare import compare, compare_notebooks
def test_metadata_filters_from_config(tmpdir):
cfg_file = tmpdir.join("jupytext.toml")
nb_file = tmpdir.join("notebook.ipynb")
md_file = tmpdir.join("notebook.md")
cfg_file.write(
"""default_notebook_metadata_filter = "-all"
default_cell_metadata_filter = "-all"
"""
)
nb = new_notebook(
cells=[new_markdown_cell("A markdown cell")],
metadata={
"kernelspec": {
"display_name": "Python [conda env:.conda-week1]",
"language": "python",
"name": "conda-env-.conda-week1-py",
},
"language_info": {
"codemirror_mode": {"name": "ipython", "version": 3},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3",
},
"nbsphinx": {"execute": "never"},
},
)
nbformat.write(nb, str(nb_file))
jupytext_cli([str(nb_file), "--to", "md"])
md = md_file.read()
compare(md, "A markdown cell\n")
jupytext_cli([str(md_file), "--to", "notebook", "--update"])
nb2 = nbformat.read(str(nb_file), as_version=4)
del nb2.metadata["jupytext"]
compare_notebooks(nb2, nb)