Skip to content

Commit

Permalink
Add a test to document how to use the folder & prefix matching (#985)
Browse files Browse the repository at this point in the history
* Add a test to document how to use the folder & prefix matching

* Add an 'example' prefix to the first notebook

* Update CHANGELOG.md
  • Loading branch information
mwouts authored Nov 12, 2022
1 parent 418d67a commit 4162d6f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Jupytext ChangeLog

**Added**
- We now test Jupytext against Python 3.6 to 3.11 on the CI
- We have added a test to document how to use the folder and prefix matching when pairing notebooks ([#974](https://github.com/mwouts/jupytext/issues/974))


1.14.1 (2022-07-29)
Expand Down
31 changes: 31 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,37 @@ def test_cli_sync_file_with_suffix(tmpdir, cwd_tmpdir):
fp.read().splitlines()[-4:] == ["", "```{python}", "1+1", "```"]


def test_cli_sync_file_with_prefix_974(tmp_path, python_notebook):
"""Only the files that are in the example directory and that start with 'example' should be paired"""
(tmp_path / "pyproject.toml").write_text(
"""[tool.jupytext]
formats = "examples//example/ipynb,examples//example/py:percent"
"""
)

write(python_notebook, tmp_path / "example_notebook.ipynb")
(tmp_path / "examples" / "folder1").mkdir(parents=True)
write(python_notebook, tmp_path / "examples/folder1/utils.py")
write(python_notebook, tmp_path / "examples/folder1/example_paired.ipynb")

jupytext(
[
"--sync",
str(tmp_path / "example_notebook.ipynb"),
str(tmp_path / "examples/folder1/utils.py"),
str(tmp_path / "examples/folder1/example_paired.ipynb"),
]
)

assert not (
tmp_path / "example_notebook.py"
).exists(), "Not in the 'examples' directory"
assert not (
tmp_path / "examples/folder1/utils_not_paired.ipynb"
).exists(), "Not with the 'example' prefix"
assert (tmp_path / "examples/folder1/example_paired.py").exists(), "Paired"


@requires_sphinx_gallery
def test_rst2md(tmpdir, cwd_tmpdir):
tmp_py = "notebook.py"
Expand Down

0 comments on commit 4162d6f

Please sign in to comment.