Skip to content

Commit

Permalink
Ignore changes in the YAML header in jupytext --test
Browse files Browse the repository at this point in the history
  • Loading branch information
mwouts committed Jan 19, 2020
1 parent 65a47b0 commit 5328a7d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
------------------
Expand Down
15 changes: 14 additions & 1 deletion jupytext/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)))
Expand Down
26 changes: 26 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down

0 comments on commit 5328a7d

Please sign in to comment.