Skip to content

Commit

Permalink
Merge pull request #719 from fcollonval/auto-backport-of-pr-717-on-0.…
Browse files Browse the repository at this point in the history
…11.x

Backport of #717  Add unit tests for ignore feature
  • Loading branch information
fcollonval authored Aug 8, 2020
2 parents 9a00d0b + 1bcd4f5 commit 27ac6a5
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
70 changes: 70 additions & 0 deletions jupyterlab_git/tests/test_ignore.py
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
3 changes: 2 additions & 1 deletion src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,8 @@ export class GitExtension implements IGitExtension {
/**
* Make request to ignore one file.
*
* @param filename Optional name of the files to add
* @param filePath File to ignore
* @param useExtension Whether to ignore the file or its extension
*/
async ignore(filePath: string, useExtension: boolean): Promise<Response> {
await this.ready;
Expand Down

0 comments on commit 27ac6a5

Please sign in to comment.