Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test that metadata filters in the configuration files are taken into account when using jupytext --to #607

Merged
merged 1 commit into from
Aug 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ of R Markdown notebooks as a raw cell in Jupyter (#415)
- `jupytext notebook.ipynb --to filename.py` will warn that `--to` is used in place of `--output`.
- Warn if 'Include Metadata' is off when saving text files in Jupyter (#561)
- Test that notebooks paired through a configuration file are left unmodified (#598)
- Test that metadata filters in the configuration files are taken into account when using `jupytext --to` (#543)

**Changed**
- Install Jupytext from source on MyBinder to avoid cache issues (#567)
Expand Down
48 changes: 48 additions & 0 deletions tests/test_metadata_filters_from_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import nbformat
from nbformat.v4.nbbase import new_notebook, new_markdown_cell
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)