Skip to content

Commit

Permalink
Reproduce the conditions for #506 in a test
Browse files Browse the repository at this point in the history
  • Loading branch information
mwouts committed May 22, 2020
1 parent e1de793 commit da81638
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions tests/test_pre_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,3 +280,46 @@ def hook():

assert "notebook.py" in git("ls-tree", "-r", "master", "--name-only")
assert os.path.isfile(tmp_py)


def test_pre_commit_hook_with_subfolders_issue_506(tmpdir):
"""I have the following directory structure, where the nb/test.ipynb is paired with the py/test.py.
├── nb
│ └── test.ipynb
└── py
└── test.py
"""

nb_file = tmpdir.mkdir("nb").join("test.ipynb")
py_file = tmpdir.mkdir("py").join("test.py")

"""The notebook and Python file are paired with "jupytext": {"formats": "py//py,nb//ipynb"}.
(using jupytext --set-formats py//py,nb//ipynb nb/test.ipynb)"""
write(
new_notebook(
cells=[new_markdown_cell("A Markdown cell")],
metadata={"jupytext": {"formats": "py//py,nb//ipynb"}},
),
str(nb_file),
)

"""This works fine when syncing with jupytext --sync nb/test.ipynb
but when syncing with jupytext --sync --pre-commit I get the following exception: (...)"""
git = git_in_tmpdir(tmpdir)
hook = str(tmpdir.join(".git/hooks/pre-commit"))
with open(hook, "w") as fp:
fp.write("#!/bin/sh\n" "jupytext --sync --pre-commit\n")

st = os.stat(hook)
os.chmod(hook, st.st_mode | stat.S_IEXEC)

assert not os.path.isfile(str(py_file))

git("add", "nb/test.ipynb")
git("status")
git("commit", "-m", "notebook created")
git("status")

assert os.path.isfile(str(py_file))
assert "A Markdown cell" in py_file.read()

0 comments on commit da81638

Please sign in to comment.