-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #719 from fcollonval/auto-backport-of-pr-717-on-0.…
…11.x Backport of #717 Add unit tests for ignore feature
- Loading branch information
Showing
2 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import pytest | ||
|
||
from jupyterlab_git.git import Git | ||
|
||
from .testutils import FakeContentManager, maybe_future | ||
|
||
|
||
@pytest.mark.parametrize("ignore_content", [None, "dummy", "dummy\n"]) | ||
@pytest.mark.asyncio | ||
async def test_ensure_gitignore(tmp_path, ignore_content): | ||
# Given | ||
ignore_file = tmp_path / ".gitignore" | ||
if ignore_content is not None: | ||
ignore_file.write_text(ignore_content) | ||
|
||
# When | ||
actual_response = await Git(FakeContentManager("/bin")).ensure_gitignore( | ||
str(tmp_path) | ||
) | ||
|
||
# Then | ||
assert {"code": 0} == actual_response | ||
content = ignore_file.read_text() | ||
assert len(content) == 0 or content.endswith("\n") | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_ensure_gitignore_failure(tmp_path): | ||
# Given | ||
ignore_file = tmp_path / ".gitignore" | ||
ignore_file.write_text("dummy") | ||
ignore_file.chmod(200) # Set read only to generate an error | ||
|
||
# When | ||
response = await Git(FakeContentManager("/bin")).ensure_gitignore(str(tmp_path)) | ||
|
||
# Then | ||
assert response["code"] == -1 | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_ignore(tmp_path): | ||
# Given | ||
ignore_file = tmp_path / ".gitignore" | ||
ignore_file.write_text("dummy") | ||
file_ignore = "to_ignore.txt" | ||
|
||
# When | ||
response = await Git(FakeContentManager("/bin")).ignore(str(tmp_path), file_ignore) | ||
|
||
# Then | ||
assert {"code": 0} == response | ||
content = ignore_file.read_text() | ||
content.endswith("{}\n".format(file_ignore)) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_ignore_failure(tmp_path): | ||
# Given | ||
ignore_file = tmp_path / ".gitignore" | ||
ignore_file.write_text("dummy") | ||
ignore_file.chmod(200) # Set read only to generate an error | ||
|
||
# When | ||
response = await Git(FakeContentManager("/bin")).ignore( | ||
str(tmp_path), "to_ignore.txt" | ||
) | ||
|
||
# Then | ||
assert response["code"] == -1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters