Repository: mwouts/jupytext

Issue:
Argument --test fails if run on different jupytext versions
`jupytext --test --to ipynb FILE.py` fails with:
```diff
[jupytext] Reading FILE.py
--- expected
+++ actual
@@ -5,7 +5,7 @@
 #       extension: .py
 #       format_name: light
 #       format_version: '1.5'
-#       jupytext_version: 1.3.0
+#       jupytext_version: 1.3.2
 #   kernelspec:
 #     display_name: Python 3
 #     language: python
```

I suggest to add `jupytext_version` (and maybe even `format_version`) to [`_IGNORE_CELL_METADATA`](https://github.com/mwouts/jupytext/blob/700f03a61b81b0f80df3f67551ecc2bf956a873c/jupytext/compare.py#L141-L145) (or appropriate), because those lines will differ on different jupytext invocations but might otherwise not influence the converted output in any way.

They remain covered by `--test-strict`.

Discussion:
codecov[bot]: # [Codecov](https://codecov.io/gh/mwouts/jupytext/pull/420?src=pr&el=h1) Report
> Merging [#420](https://codecov.io/gh/mwouts/jupytext/pull/420?src=pr&el=desc) into [master](https://codecov.io/gh/mwouts/jupytext/commit/65a47b0908a76e692c27b8c9679fe6a95ec8fe35?src=pr&el=desc) will **decrease** coverage by `1.04%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/mwouts/jupytext/pull/420/graphs/tree.svg?width=650&token=a1pNjsiILi&height=150&src=pr)](https://codecov.io/gh/mwouts/jupytext/pull/420?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #420      +/-   ##
==========================================
- Coverage   98.93%   97.88%   -1.05%     
==========================================
  Files          75       75              
  Lines        7596     7608      +12     
==========================================
- Hits         7515     7447      -68     
- Misses         81      161      +80
```


| [Impacted Files](https://codecov.io/gh/mwouts/jupytext/pull/420?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [jupytext/cli.py](https://codecov.io/gh/mwouts/jupytext/pull/420/diff?src=pr&el=tree#diff-anVweXRleHQvY2xpLnB5) | `95.62% <100%> (+0.08%)` | :arrow_up: |
| [tests/test\_cli.py](https://codecov.io/gh/mwouts/jupytext/pull/420/diff?src=pr&el=tree#diff-dGVzdHMvdGVzdF9jbGkucHk=) | `98.06% <100%> (-1.94%)` | :arrow_down: |
| [tests/test\_read\_simple\_pandoc.py](https://codecov.io/gh/mwouts/jupytext/pull/420/diff?src=pr&el=tree#diff-dGVzdHMvdGVzdF9yZWFkX3NpbXBsZV9wYW5kb2MucHk=) | `44.82% <0%> (-55.18%)` | :arrow_down: |
| [jupytext/pandoc.py](https://codecov.io/gh/mwouts/jupytext/pull/420/diff?src=pr&el=tree#diff-anVweXRleHQvcGFuZG9jLnB5) | `40.81% <0%> (-55.11%)` | :arrow_down: |
| [jupytext/jupytext.py](https://codecov.io/gh/mwouts/jupytext/pull/420/diff?src=pr&el=tree#diff-anVweXRleHQvanVweXRleHQucHk=) | `94.39% <0%> (-4.21%)` | :arrow_down: |
| [jupytext/kernels.py](https://codecov.io/gh/mwouts/jupytext/pull/420/diff?src=pr&el=tree#diff-anVweXRleHQva2VybmVscy5weQ==) | `86.66% <0%> (-3.34%)` | :arrow_down: |
| [tests/test\_contentsmanager.py](https://codecov.io/gh/mwouts/jupytext/pull/420/diff?src=pr&el=tree#diff-dGVzdHMvdGVzdF9jb250ZW50c21hbmFnZXIucHk=) | `98.9% <0%> (-1.1%)` | :arrow_down: |
| [tests/test\_mirror.py](https://codecov.io/gh/mwouts/jupytext/pull/420/diff?src=pr&el=tree#diff-dGVzdHMvdGVzdF9taXJyb3IucHk=) | `99.28% <0%> (-0.72%)` | :arrow_down: |
| [jupytext/formats.py](https://codecov.io/gh/mwouts/jupytext/pull/420/diff?src=pr&el=tree#diff-anVweXRleHQvZm9ybWF0cy5weQ==) | `98% <0%> (-0.67%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/mwouts/jupytext/pull/420?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/mwouts/jupytext/pull/420?src=pr&el=footer). Last update [65a47b0...ba185f7](https://codecov.io/gh/mwouts/jupytext/pull/420?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c33b2fb..df8a3d6 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 7ea4111..2b250fe 100644
--- a/jupytext/cli.py
+++ b/jupytext/cli.py
@@ -12,6 +12,7 @@ from tempfile import NamedTemporaryFile
 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)))


Test patch:
diff --git a/tests/test_cli.py b/tests/test_cli.py
index a12466b..39b06a6 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'))