diff --git a/CHANGELOG.md b/CHANGELOG.md index c33b2fb7b..df8a3d6df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,8 @@ ------------------ **Fixed** -- Code cells in the Markdown format can contain triple backticks inside multiline strings (#419) +- Code cells in the Markdown format can contain triple backticks inside multiline strings (#419) +- Changes in the YAML header when running `jupytext --test` on text files are ignored (#414). 1.3.2 (2020-01-08) ------------------ diff --git a/jupytext/cli.py b/jupytext/cli.py index 7ea411181..2b250fe70 100644 --- a/jupytext/cli.py +++ b/jupytext/cli.py @@ -12,6 +12,7 @@ from .jupytext import read, reads, write, writes from .formats import _VALID_FORMAT_OPTIONS, _BINARY_FORMAT_OPTIONS, check_file_version from .formats import long_form_one_format, long_form_multiple_formats, short_form_one_format, check_auto_ext +from .languages import _SCRIPT_EXTENSIONS from .header import recursive_update from .paired_paths import paired_paths, base_path, full_path, InconsistentPath from .combine import combine_inputs_with_outputs @@ -415,7 +416,19 @@ def jupytext_single_file(nb_file, args, log): notebook = reads(dest_text, fmt=dest_fmt) text = writes(notebook, fmt=fmt) - compare(text, org_text) + + if args.test_strict: + compare(text, org_text) + else: + # we ignore the YAML header in the comparison #414 + comment = _SCRIPT_EXTENSIONS.get(fmt['extension'], {}).get('comment', '') + # white spaces between the comment char and the YAML delimiters are allowed + if comment: + comment = comment + r'\s*' + yaml_header = re.compile(r'^{}---\s*\n.*\n{}---\s*\n'.format(comment, comment), + re.MULTILINE | re.DOTALL) + compare(re.sub(yaml_header, '', text), + re.sub(yaml_header, '', org_text)) except (NotebookDifference, AssertionError) as err: sys.stdout.write('{}: {}'.format(nb_file, str(err))) diff --git a/tests/test_cli.py b/tests/test_cli.py index a12466b9b..39b06a615 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -275,6 +275,32 @@ def test_ipynb_to_py_then_update_test(nb_file, tmpdir): jupytext(['--test', '--update', '--to', 'ipynb', tmp_nbpy]) +def test_test_to_ipynb_ignore_version_number_414(tmpdir, text="""# --- +# jupyter: +# jupytext: +# text_representation: +# extension: .py +# format_name: light +# format_version: '1.4' +# jupytext_version: 1.1.0 +# kernelspec: +# display_name: Python 3 +# language: python +# name: python3 +# --- + +# A short markdown cell + +# Followed by a code cell +2 + 2 +"""): + tmp_py = str(tmpdir.join('script.py')) + with open(tmp_py, 'w') as fp: + fp.write(text) + + assert jupytext(['--test', '--to', 'ipynb', tmp_py]) == 0 + + @pytest.mark.parametrize('nb_file', list_notebooks('ipynb_py')) def test_convert_to_percent_format(nb_file, tmpdir): tmp_ipynb = str(tmpdir.join('notebook.ipynb'))