From 0e8e44b37c4cc80bc1448dd074391d8db933d7b8 Mon Sep 17 00:00:00 2001 From: Marc Wouts Date: Thu, 27 Jun 2024 22:24:57 +0100 Subject: [PATCH] Document how to fix `jupytext` stripping `mystnb` file metadata. #1247 using either a local metadata filter, or a Jupytext configuration file --- .../functional/round_trip/test_myst_header.py | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 tests/functional/round_trip/test_myst_header.py diff --git a/tests/functional/round_trip/test_myst_header.py b/tests/functional/round_trip/test_myst_header.py new file mode 100644 index 00000000..a1869dcc --- /dev/null +++ b/tests/functional/round_trip/test_myst_header.py @@ -0,0 +1,58 @@ +from jupytext import reads, writes +from jupytext.compare import compare +from jupytext.config import load_jupytext_configuration_file + + +def test_myst_header_is_stable_1247_using_inline_filter( + md="""--- +jupytext: + formats: md:myst + notebook_metadata_filter: -jupytext.text_representation.jupytext_version,settings,mystnb + text_representation: + extension: .md + format_name: myst + format_version: 0.13 +kernelspec: + display_name: Python 3 (ipykernel) + language: python + name: python3 +mystnb: + execution_mode: 'off' +settings: + output_matplotlib_strings: remove +--- +""", +): + nb = reads(md, fmt="md") + md2 = writes(nb, fmt="md") + + compare(md2, md) + + +def test_myst_header_is_stable_1247_using_config( + jupytext_toml_content="""notebook_metadata_filter = "-jupytext.text_representation.jupytext_version,settings,mystnb" +""", + md="""--- +jupytext: + formats: md:myst + text_representation: + extension: .md + format_name: myst + format_version: 0.13 +kernelspec: + display_name: Python 3 (ipykernel) + language: python + name: python3 +mystnb: + execution_mode: 'off' +settings: + output_matplotlib_strings: remove +--- +""", +): + config = load_jupytext_configuration_file("jupytext.toml", jupytext_toml_content) + + nb = reads(md, fmt="md", config=config) + md2 = writes(nb, fmt="md", config=config) + + compare(md2, md)